trace.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_TRACE_H
  3. #define _LINUX_TRACE_H
  4. #define TRACE_EXPORT_FUNCTION BIT(0)
  5. #define TRACE_EXPORT_EVENT BIT(1)
  6. #define TRACE_EXPORT_MARKER BIT(2)
  7. /*
  8. * The trace export - an export of Ftrace output. The trace_export
  9. * can process traces and export them to a registered destination as
  10. * an addition to the current only output of Ftrace - i.e. ring buffer.
  11. *
  12. * If you want traces to be sent to some other place rather than ring
  13. * buffer only, just need to register a new trace_export and implement
  14. * its own .write() function for writing traces to the storage.
  15. *
  16. * next - pointer to the next trace_export
  17. * write - copy traces which have been delt with ->commit() to
  18. * the destination
  19. * flags - which ftrace to be exported
  20. */
  21. struct trace_export {
  22. struct trace_export __rcu *next;
  23. void (*write)(struct trace_export *, const void *, unsigned int);
  24. int flags;
  25. };
  26. struct trace_array;
  27. #ifdef CONFIG_TRACING
  28. int register_ftrace_export(struct trace_export *export);
  29. int unregister_ftrace_export(struct trace_export *export);
  30. /**
  31. * trace_array_puts - write a constant string into the trace buffer.
  32. * @tr: The trace array to write to
  33. * @str: The constant string to write
  34. */
  35. #define trace_array_puts(tr, str) \
  36. ({ \
  37. str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1; \
  38. })
  39. int __trace_array_puts(struct trace_array *tr, unsigned long ip,
  40. const char *str, int size);
  41. void trace_printk_init_buffers(void);
  42. __printf(3, 4)
  43. int trace_array_printk(struct trace_array *tr, unsigned long ip,
  44. const char *fmt, ...);
  45. int trace_array_init_printk(struct trace_array *tr);
  46. void trace_array_put(struct trace_array *tr);
  47. struct trace_array *trace_array_get_by_name(const char *name);
  48. int trace_array_destroy(struct trace_array *tr);
  49. /* For osnoise tracer */
  50. int osnoise_arch_register(void);
  51. void osnoise_arch_unregister(void);
  52. void osnoise_trace_irq_entry(int id);
  53. void osnoise_trace_irq_exit(int id, const char *desc);
  54. #else /* CONFIG_TRACING */
  55. static inline int register_ftrace_export(struct trace_export *export)
  56. {
  57. return -EINVAL;
  58. }
  59. static inline int unregister_ftrace_export(struct trace_export *export)
  60. {
  61. return 0;
  62. }
  63. static inline void trace_printk_init_buffers(void)
  64. {
  65. }
  66. static inline int trace_array_printk(struct trace_array *tr, unsigned long ip,
  67. const char *fmt, ...)
  68. {
  69. return 0;
  70. }
  71. static inline int trace_array_init_printk(struct trace_array *tr)
  72. {
  73. return -EINVAL;
  74. }
  75. static inline void trace_array_put(struct trace_array *tr)
  76. {
  77. }
  78. static inline struct trace_array *trace_array_get_by_name(const char *name)
  79. {
  80. return NULL;
  81. }
  82. static inline int trace_array_destroy(struct trace_array *tr)
  83. {
  84. return 0;
  85. }
  86. #endif /* CONFIG_TRACING */
  87. #endif /* _LINUX_TRACE_H */