1
0

trace-event.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _PERF_UTIL_TRACE_EVENT_H
  3. #define _PERF_UTIL_TRACE_EVENT_H
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <linux/types.h>
  8. struct evlist;
  9. struct machine;
  10. struct perf_sample;
  11. union perf_event;
  12. struct perf_tool;
  13. struct thread;
  14. struct tep_plugin_list;
  15. struct evsel;
  16. struct tep_format_field;
  17. struct trace_event {
  18. struct tep_handle *pevent;
  19. struct tep_plugin_list *plugin_list;
  20. };
  21. /* Computes a version number comparable with LIBTRACEEVENT_VERSION from Makefile.config. */
  22. #define MAKE_LIBTRACEEVENT_VERSION(a, b, c) ((a)*255*255+(b)*255+(c))
  23. typedef char *(tep_func_resolver_t)(void *priv,
  24. unsigned long long *addrp, char **modp);
  25. bool have_tracepoints(struct list_head *evlist);
  26. int trace_event__init(struct trace_event *t);
  27. void trace_event__cleanup(struct trace_event *t);
  28. int trace_event__register_resolver(struct machine *machine,
  29. tep_func_resolver_t *func);
  30. struct tep_event*
  31. trace_event__tp_format(const char *sys, const char *name);
  32. struct tep_event *trace_event__tp_format_id(int id);
  33. void event_format__fprintf(const struct tep_event *event,
  34. int cpu, void *data, int size, FILE *fp);
  35. int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
  36. int parse_event_file(struct tep_handle *pevent,
  37. char *buf, unsigned long size, char *sys);
  38. unsigned long long
  39. raw_field_value(struct tep_event *event, const char *name, void *data);
  40. const char *parse_task_states(struct tep_format_field *state_field);
  41. void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
  42. void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
  43. void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int size);
  44. ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
  45. unsigned long long read_size(struct tep_event *event, void *ptr, int size);
  46. unsigned long long eval_flag(const char *flag);
  47. int read_tracing_data(int fd, struct list_head *pattrs);
  48. /*
  49. * Return the tracepoint name in the format "subsystem:event_name",
  50. * callers should free the returned string.
  51. */
  52. char *tracepoint_id_to_name(u64 config);
  53. struct tracing_data {
  54. /* size is only valid if temp is 'true' */
  55. ssize_t size;
  56. bool temp;
  57. char temp_file[50];
  58. };
  59. struct tracing_data *tracing_data_get(struct list_head *pattrs,
  60. int fd, bool temp);
  61. int tracing_data_put(struct tracing_data *tdata);
  62. struct addr_location;
  63. struct perf_session;
  64. struct perf_stat_config;
  65. struct scripting_ops {
  66. const char *name;
  67. const char *dirname; /* For script path .../scripts/<dirname>/... */
  68. int (*start_script)(const char *script, int argc, const char **argv,
  69. struct perf_session *session);
  70. int (*flush_script) (void);
  71. int (*stop_script) (void);
  72. void (*process_event) (union perf_event *event,
  73. struct perf_sample *sample,
  74. struct evsel *evsel,
  75. struct addr_location *al,
  76. struct addr_location *addr_al);
  77. void (*process_switch)(union perf_event *event,
  78. struct perf_sample *sample,
  79. struct machine *machine);
  80. void (*process_auxtrace_error)(struct perf_session *session,
  81. union perf_event *event);
  82. void (*process_stat)(struct perf_stat_config *config,
  83. struct evsel *evsel, u64 tstamp);
  84. void (*process_stat_interval)(u64 tstamp);
  85. void (*process_throttle)(union perf_event *event,
  86. struct perf_sample *sample,
  87. struct machine *machine);
  88. int (*generate_script) (struct tep_handle *pevent, const char *outfile);
  89. };
  90. extern unsigned int scripting_max_stack;
  91. struct scripting_ops *script_spec__lookup(const char *spec);
  92. int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec));
  93. void setup_perl_scripting(void);
  94. void setup_python_scripting(void);
  95. struct scripting_context {
  96. struct tep_handle *pevent;
  97. void *event_data;
  98. union perf_event *event;
  99. struct perf_sample *sample;
  100. struct evsel *evsel;
  101. struct addr_location *al;
  102. struct addr_location *addr_al;
  103. struct perf_session *session;
  104. };
  105. void scripting_context__update(struct scripting_context *scripting_context,
  106. union perf_event *event,
  107. struct perf_sample *sample,
  108. struct evsel *evsel,
  109. struct addr_location *al,
  110. struct addr_location *addr_al);
  111. int common_pc(struct scripting_context *context);
  112. int common_flags(struct scripting_context *context);
  113. int common_lock_depth(struct scripting_context *context);
  114. #define SAMPLE_FLAGS_BUF_SIZE 64
  115. #define SAMPLE_FLAGS_STR_ALIGNED_SIZE 21
  116. int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
  117. #if defined(LIBTRACEEVENT_VERSION) && LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
  118. #include <event-parse.h>
  119. static inline bool tep_field_is_relative(unsigned long flags)
  120. {
  121. return (flags & TEP_FIELD_IS_RELATIVE) != 0;
  122. }
  123. #else
  124. #include <linux/compiler.h>
  125. static inline bool tep_field_is_relative(unsigned long flags __maybe_unused)
  126. {
  127. return false;
  128. }
  129. #endif
  130. #endif /* _PERF_UTIL_TRACE_EVENT_H */