xref: /linux/include/linux/trace.h (revision 06d07429858317ded2db7986113a9e0129cd599b)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2478409ddSChunyan Zhang #ifndef _LINUX_TRACE_H
3478409ddSChunyan Zhang #define _LINUX_TRACE_H
4478409ddSChunyan Zhang 
58438f521STingwei Zhang #define TRACE_EXPORT_FUNCTION	BIT(0)
68ab7a2b7STingwei Zhang #define TRACE_EXPORT_EVENT	BIT(1)
7458999c6STingwei Zhang #define TRACE_EXPORT_MARKER	BIT(2)
88438f521STingwei Zhang 
9478409ddSChunyan Zhang /*
10478409ddSChunyan Zhang  * The trace export - an export of Ftrace output. The trace_export
11478409ddSChunyan Zhang  * can process traces and export them to a registered destination as
12478409ddSChunyan Zhang  * an addition to the current only output of Ftrace - i.e. ring buffer.
13478409ddSChunyan Zhang  *
14478409ddSChunyan Zhang  * If you want traces to be sent to some other place rather than ring
15478409ddSChunyan Zhang  * buffer only, just need to register a new trace_export and implement
16478409ddSChunyan Zhang  * its own .write() function for writing traces to the storage.
17478409ddSChunyan Zhang  *
18478409ddSChunyan Zhang  * next		- pointer to the next trace_export
19478409ddSChunyan Zhang  * write	- copy traces which have been delt with ->commit() to
20478409ddSChunyan Zhang  *		  the destination
218438f521STingwei Zhang  * flags	- which ftrace to be exported
22478409ddSChunyan Zhang  */
23478409ddSChunyan Zhang struct trace_export {
24478409ddSChunyan Zhang 	struct trace_export __rcu	*next;
25a773d419SFelipe Balbi 	void (*write)(struct trace_export *, const void *, unsigned int);
268438f521STingwei Zhang 	int flags;
27478409ddSChunyan Zhang };
28478409ddSChunyan Zhang 
29bedf0683SAashish Sharma struct trace_array;
30bedf0683SAashish Sharma 
311a77dd1cSArun Easi #ifdef CONFIG_TRACING
321a77dd1cSArun Easi 
33478409ddSChunyan Zhang int register_ftrace_export(struct trace_export *export);
34478409ddSChunyan Zhang int unregister_ftrace_export(struct trace_export *export);
35478409ddSChunyan Zhang 
36d503b8f7SSteven Rostedt (Google) /**
37d503b8f7SSteven Rostedt (Google)  * trace_array_puts - write a constant string into the trace buffer.
38d503b8f7SSteven Rostedt (Google)  * @tr:    The trace array to write to
39d503b8f7SSteven Rostedt (Google)  * @str:   The constant string to write
40d503b8f7SSteven Rostedt (Google)  */
41d503b8f7SSteven Rostedt (Google) #define trace_array_puts(tr, str)					\
42d503b8f7SSteven Rostedt (Google) 	({								\
43d503b8f7SSteven Rostedt (Google) 		str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1;	\
44d503b8f7SSteven Rostedt (Google) 	})
45d503b8f7SSteven Rostedt (Google) int __trace_array_puts(struct trace_array *tr, unsigned long ip,
46d503b8f7SSteven Rostedt (Google) 		       const char *str, int size);
47d503b8f7SSteven Rostedt (Google) 
482d6425afSDivya Indi void trace_printk_init_buffers(void);
49bd0c9706STom Rix __printf(3, 4)
502d6425afSDivya Indi int trace_array_printk(struct trace_array *tr, unsigned long ip,
512d6425afSDivya Indi 		       const char *fmt, ...);
5238ce2a9eSSteven Rostedt (VMware) int trace_array_init_printk(struct trace_array *tr);
5328879787SDivya Indi void trace_array_put(struct trace_array *tr);
54*d2356997SSteven Rostedt (Google) struct trace_array *trace_array_get_by_name(const char *name, const char *systems);
552d6425afSDivya Indi int trace_array_destroy(struct trace_array *tr);
56bce29ac9SDaniel Bristot de Oliveira 
57bce29ac9SDaniel Bristot de Oliveira /* For osnoise tracer */
58bce29ac9SDaniel Bristot de Oliveira int osnoise_arch_register(void);
59bce29ac9SDaniel Bristot de Oliveira void osnoise_arch_unregister(void);
60f7d9f637SDaniel Bristot de Oliveira void osnoise_trace_irq_entry(int id);
61f7d9f637SDaniel Bristot de Oliveira void osnoise_trace_irq_exit(int id, const char *desc);
62bce29ac9SDaniel Bristot de Oliveira 
631a77dd1cSArun Easi #else /* CONFIG_TRACING */
register_ftrace_export(struct trace_export * export)641a77dd1cSArun Easi static inline int register_ftrace_export(struct trace_export *export)
651a77dd1cSArun Easi {
661a77dd1cSArun Easi 	return -EINVAL;
671a77dd1cSArun Easi }
unregister_ftrace_export(struct trace_export * export)681a77dd1cSArun Easi static inline int unregister_ftrace_export(struct trace_export *export)
691a77dd1cSArun Easi {
701a77dd1cSArun Easi 	return 0;
711a77dd1cSArun Easi }
trace_printk_init_buffers(void)721a77dd1cSArun Easi static inline void trace_printk_init_buffers(void)
731a77dd1cSArun Easi {
741a77dd1cSArun Easi }
trace_array_printk(struct trace_array * tr,unsigned long ip,const char * fmt,...)751a77dd1cSArun Easi static inline int trace_array_printk(struct trace_array *tr, unsigned long ip,
761a77dd1cSArun Easi 				     const char *fmt, ...)
771a77dd1cSArun Easi {
781a77dd1cSArun Easi 	return 0;
791a77dd1cSArun Easi }
trace_array_init_printk(struct trace_array * tr)801a77dd1cSArun Easi static inline int trace_array_init_printk(struct trace_array *tr)
811a77dd1cSArun Easi {
821a77dd1cSArun Easi 	return -EINVAL;
831a77dd1cSArun Easi }
trace_array_put(struct trace_array * tr)841a77dd1cSArun Easi static inline void trace_array_put(struct trace_array *tr)
851a77dd1cSArun Easi {
861a77dd1cSArun Easi }
trace_array_get_by_name(const char * name,const char * systems)87*d2356997SSteven Rostedt (Google) static inline struct trace_array *trace_array_get_by_name(const char *name, const char *systems)
881a77dd1cSArun Easi {
891a77dd1cSArun Easi 	return NULL;
901a77dd1cSArun Easi }
trace_array_destroy(struct trace_array * tr)911a77dd1cSArun Easi static inline int trace_array_destroy(struct trace_array *tr)
921a77dd1cSArun Easi {
931a77dd1cSArun Easi 	return 0;
941a77dd1cSArun Easi }
95478409ddSChunyan Zhang #endif	/* CONFIG_TRACING */
96478409ddSChunyan Zhang 
97478409ddSChunyan Zhang #endif	/* _LINUX_TRACE_H */
98