systrace.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Systrace Kernel Tracing Integration
  3. *
  4. * Copyright (C) 2019 Google, Inc.
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #undef TRACE_SYSTEM
  16. #define TRACE_SYSTEM systrace
  17. #if !defined(_TRACE_SYSTRACE_H) || defined(TRACE_HEADER_MULTI_READ)
  18. #define _TRACE_SYSTRACE_H
  19. #include <linux/tracepoint.h>
  20. /* make declarations singleton at recursive inclusion path */
  21. #if !defined(_SYSTRACE_RECURSIVE_DECLARATIONS)
  22. #define _SYSTRACE_RECURSIVE_DECLARATIONS
  23. enum {
  24. SYSTRACE_EVENT_BEGIN = (1UL << 0),
  25. SYSTRACE_EVENT_END = (1UL << 1),
  26. SYSTRACE_EVENT_INT64 = (1UL << 2),
  27. };
  28. #endif /* _SYSTRACE_RECURSIVE_DECLARATIONS */
  29. #define systrace_event_type(flag) \
  30. __print_flags(flag, "", \
  31. { SYSTRACE_EVENT_BEGIN, "B" }, \
  32. { SYSTRACE_EVENT_END, "E" }, \
  33. { SYSTRACE_EVENT_INT64, "C" })
  34. /*
  35. * To comply with systrace format: [BEC]|pid|name|value
  36. *
  37. * Note:
  38. * 0 can be recognized by catapult ftrace importer but should be deprecated.
  39. * once we get a new dedicated parsing tag like tracing_mark_write.
  40. */
  41. TRACE_EVENT(0,
  42. TP_PROTO(int flag, int pid, const char *name, int64_t value),
  43. TP_ARGS(flag, pid, name, value),
  44. TP_STRUCT__entry(
  45. __field(int, flag)
  46. __field(int, pid)
  47. __string(name, name)
  48. __field(int64_t, value)
  49. ),
  50. TP_fast_assign(
  51. __entry->flag = flag;
  52. __entry->pid = pid;
  53. __assign_str(name, name);
  54. __entry->value = value;
  55. ),
  56. TP_printk("%s|%d|%s|%lld",
  57. systrace_event_type(__entry->flag),
  58. __entry->pid,
  59. __get_str(name),
  60. __entry->value
  61. )
  62. );
  63. #if IS_ENABLED(CONFIG_SYSTRACE)
  64. #define ATRACE_INT(name, value) \
  65. trace_0(SYSTRACE_EVENT_INT64, \
  66. current->tgid, \
  67. name, \
  68. value)
  69. #define ATRACE_BEGIN(name) \
  70. trace_0(SYSTRACE_EVENT_BEGIN, \
  71. current->tgid, \
  72. name, \
  73. 0)
  74. #define ATRACE_END() \
  75. trace_0(SYSTRACE_EVENT_END, \
  76. current->tgid, \
  77. "", \
  78. 0)
  79. #define ATRACE_BLOCK(name, block) \
  80. do { \
  81. ATRACE_BEGIN(name); \
  82. (block); \
  83. ATRACE_END(); \
  84. } while (0)
  85. #else
  86. #define ATRACE_INT(name, value)
  87. #define ATRACE_BEGIN(name)
  88. #define ATRACE_END()
  89. #define ATRACE_BLOCK(name, block) (block)
  90. #endif /* CONFIG_SYSTRACE */
  91. #endif /* _TRACE_SYSTRACE_H */
  92. /* This part must be outside protection */
  93. #include <trace/define_trace.h>