event.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #ifndef __PERF_RECORD_H
  2. #define __PERF_RECORD_H
  3. #include <limits.h>
  4. #include <stdio.h>
  5. #include "../perf.h"
  6. #include "map.h"
  7. #include "build-id.h"
  8. #include "perf_regs.h"
  9. struct mmap_event {
  10. struct perf_event_header header;
  11. u32 pid, tid;
  12. u64 start;
  13. u64 len;
  14. u64 pgoff;
  15. char filename[PATH_MAX];
  16. };
  17. struct mmap2_event {
  18. struct perf_event_header header;
  19. u32 pid, tid;
  20. u64 start;
  21. u64 len;
  22. u64 pgoff;
  23. u32 maj;
  24. u32 min;
  25. u64 ino;
  26. u64 ino_generation;
  27. u32 prot;
  28. u32 flags;
  29. char filename[PATH_MAX];
  30. };
  31. struct comm_event {
  32. struct perf_event_header header;
  33. u32 pid, tid;
  34. char comm[16];
  35. };
  36. struct fork_event {
  37. struct perf_event_header header;
  38. u32 pid, ppid;
  39. u32 tid, ptid;
  40. u64 time;
  41. };
  42. struct lost_event {
  43. struct perf_event_header header;
  44. u64 id;
  45. u64 lost;
  46. };
  47. struct lost_samples_event {
  48. struct perf_event_header header;
  49. u64 lost;
  50. };
  51. /*
  52. * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
  53. */
  54. struct read_event {
  55. struct perf_event_header header;
  56. u32 pid, tid;
  57. u64 value;
  58. u64 time_enabled;
  59. u64 time_running;
  60. u64 id;
  61. };
  62. struct throttle_event {
  63. struct perf_event_header header;
  64. u64 time;
  65. u64 id;
  66. u64 stream_id;
  67. };
  68. #define PERF_SAMPLE_MASK \
  69. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
  70. PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
  71. PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
  72. PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
  73. PERF_SAMPLE_IDENTIFIER)
  74. /* perf sample has 16 bits size limit */
  75. #define PERF_SAMPLE_MAX_SIZE (1 << 16)
  76. struct sample_event {
  77. struct perf_event_header header;
  78. u64 array[];
  79. };
  80. struct regs_dump {
  81. u64 abi;
  82. u64 mask;
  83. u64 *regs;
  84. /* Cached values/mask filled by first register access. */
  85. u64 cache_regs[PERF_REGS_MAX];
  86. u64 cache_mask;
  87. };
  88. struct stack_dump {
  89. u16 offset;
  90. u64 size;
  91. char *data;
  92. };
  93. struct sample_read_value {
  94. u64 value;
  95. u64 id;
  96. };
  97. struct sample_read {
  98. u64 time_enabled;
  99. u64 time_running;
  100. union {
  101. struct {
  102. u64 nr;
  103. struct sample_read_value *values;
  104. } group;
  105. struct sample_read_value one;
  106. };
  107. };
  108. struct ip_callchain {
  109. u64 nr;
  110. u64 ips[0];
  111. };
  112. struct branch_flags {
  113. u64 mispred:1;
  114. u64 predicted:1;
  115. u64 in_tx:1;
  116. u64 abort:1;
  117. u64 reserved:60;
  118. };
  119. struct branch_entry {
  120. u64 from;
  121. u64 to;
  122. struct branch_flags flags;
  123. };
  124. struct branch_stack {
  125. u64 nr;
  126. struct branch_entry entries[0];
  127. };
  128. enum {
  129. PERF_IP_FLAG_BRANCH = 1ULL << 0,
  130. PERF_IP_FLAG_CALL = 1ULL << 1,
  131. PERF_IP_FLAG_RETURN = 1ULL << 2,
  132. PERF_IP_FLAG_CONDITIONAL = 1ULL << 3,
  133. PERF_IP_FLAG_SYSCALLRET = 1ULL << 4,
  134. PERF_IP_FLAG_ASYNC = 1ULL << 5,
  135. PERF_IP_FLAG_INTERRUPT = 1ULL << 6,
  136. PERF_IP_FLAG_TX_ABORT = 1ULL << 7,
  137. PERF_IP_FLAG_TRACE_BEGIN = 1ULL << 8,
  138. PERF_IP_FLAG_TRACE_END = 1ULL << 9,
  139. PERF_IP_FLAG_IN_TX = 1ULL << 10,
  140. };
  141. #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
  142. #define PERF_BRANCH_MASK (\
  143. PERF_IP_FLAG_BRANCH |\
  144. PERF_IP_FLAG_CALL |\
  145. PERF_IP_FLAG_RETURN |\
  146. PERF_IP_FLAG_CONDITIONAL |\
  147. PERF_IP_FLAG_SYSCALLRET |\
  148. PERF_IP_FLAG_ASYNC |\
  149. PERF_IP_FLAG_INTERRUPT |\
  150. PERF_IP_FLAG_TX_ABORT |\
  151. PERF_IP_FLAG_TRACE_BEGIN |\
  152. PERF_IP_FLAG_TRACE_END)
  153. struct perf_sample {
  154. u64 ip;
  155. u32 pid, tid;
  156. u64 time;
  157. u64 addr;
  158. u64 id;
  159. u64 stream_id;
  160. u64 period;
  161. u64 weight;
  162. u64 transaction;
  163. u32 cpu;
  164. u32 raw_size;
  165. u64 data_src;
  166. u32 flags;
  167. u16 insn_len;
  168. void *raw_data;
  169. struct ip_callchain *callchain;
  170. struct branch_stack *branch_stack;
  171. struct regs_dump user_regs;
  172. struct regs_dump intr_regs;
  173. struct stack_dump user_stack;
  174. struct sample_read read;
  175. };
  176. #define PERF_MEM_DATA_SRC_NONE \
  177. (PERF_MEM_S(OP, NA) |\
  178. PERF_MEM_S(LVL, NA) |\
  179. PERF_MEM_S(SNOOP, NA) |\
  180. PERF_MEM_S(LOCK, NA) |\
  181. PERF_MEM_S(TLB, NA))
  182. struct build_id_event {
  183. struct perf_event_header header;
  184. pid_t pid;
  185. u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
  186. char filename[];
  187. };
  188. enum perf_user_event_type { /* above any possible kernel type */
  189. PERF_RECORD_USER_TYPE_START = 64,
  190. PERF_RECORD_HEADER_ATTR = 64,
  191. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
  192. PERF_RECORD_HEADER_TRACING_DATA = 66,
  193. PERF_RECORD_HEADER_BUILD_ID = 67,
  194. PERF_RECORD_FINISHED_ROUND = 68,
  195. PERF_RECORD_ID_INDEX = 69,
  196. PERF_RECORD_AUXTRACE_INFO = 70,
  197. PERF_RECORD_AUXTRACE = 71,
  198. PERF_RECORD_AUXTRACE_ERROR = 72,
  199. PERF_RECORD_HEADER_MAX
  200. };
  201. enum auxtrace_error_type {
  202. PERF_AUXTRACE_ERROR_ITRACE = 1,
  203. PERF_AUXTRACE_ERROR_MAX
  204. };
  205. /*
  206. * The kernel collects the number of events it couldn't send in a stretch and
  207. * when possible sends this number in a PERF_RECORD_LOST event. The number of
  208. * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
  209. * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
  210. * the sum of all struct lost_event.lost fields reported.
  211. *
  212. * The kernel discards mixed up samples and sends the number in a
  213. * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored
  214. * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells
  215. * exactly how many samples the kernel in fact dropped, i.e. it is the sum of
  216. * all struct lost_samples_event.lost fields reported.
  217. *
  218. * The total_period is needed because by default auto-freq is used, so
  219. * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
  220. * the total number of low level events, it is necessary to to sum all struct
  221. * sample_event.period and stash the result in total_period.
  222. */
  223. struct events_stats {
  224. u64 total_period;
  225. u64 total_non_filtered_period;
  226. u64 total_lost;
  227. u64 total_lost_samples;
  228. u64 total_invalid_chains;
  229. u32 nr_events[PERF_RECORD_HEADER_MAX];
  230. u32 nr_non_filtered_samples;
  231. u32 nr_lost_warned;
  232. u32 nr_unknown_events;
  233. u32 nr_invalid_chains;
  234. u32 nr_unknown_id;
  235. u32 nr_unprocessable_samples;
  236. u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
  237. u32 nr_proc_map_timeout;
  238. };
  239. struct attr_event {
  240. struct perf_event_header header;
  241. struct perf_event_attr attr;
  242. u64 id[];
  243. };
  244. #define MAX_EVENT_NAME 64
  245. struct perf_trace_event_type {
  246. u64 event_id;
  247. char name[MAX_EVENT_NAME];
  248. };
  249. struct event_type_event {
  250. struct perf_event_header header;
  251. struct perf_trace_event_type event_type;
  252. };
  253. struct tracing_data_event {
  254. struct perf_event_header header;
  255. u32 size;
  256. };
  257. struct id_index_entry {
  258. u64 id;
  259. u64 idx;
  260. u64 cpu;
  261. u64 tid;
  262. };
  263. struct id_index_event {
  264. struct perf_event_header header;
  265. u64 nr;
  266. struct id_index_entry entries[0];
  267. };
  268. struct auxtrace_info_event {
  269. struct perf_event_header header;
  270. u32 type;
  271. u32 reserved__; /* For alignment */
  272. u64 priv[];
  273. };
  274. struct auxtrace_event {
  275. struct perf_event_header header;
  276. u64 size;
  277. u64 offset;
  278. u64 reference;
  279. u32 idx;
  280. u32 tid;
  281. u32 cpu;
  282. u32 reserved__; /* For alignment */
  283. };
  284. #define MAX_AUXTRACE_ERROR_MSG 64
  285. struct auxtrace_error_event {
  286. struct perf_event_header header;
  287. u32 type;
  288. u32 code;
  289. u32 cpu;
  290. u32 pid;
  291. u32 tid;
  292. u32 reserved__; /* For alignment */
  293. u64 ip;
  294. char msg[MAX_AUXTRACE_ERROR_MSG];
  295. };
  296. struct aux_event {
  297. struct perf_event_header header;
  298. u64 aux_offset;
  299. u64 aux_size;
  300. u64 flags;
  301. };
  302. struct itrace_start_event {
  303. struct perf_event_header header;
  304. u32 pid, tid;
  305. };
  306. union perf_event {
  307. struct perf_event_header header;
  308. struct mmap_event mmap;
  309. struct mmap2_event mmap2;
  310. struct comm_event comm;
  311. struct fork_event fork;
  312. struct lost_event lost;
  313. struct lost_samples_event lost_samples;
  314. struct read_event read;
  315. struct throttle_event throttle;
  316. struct sample_event sample;
  317. struct attr_event attr;
  318. struct event_type_event event_type;
  319. struct tracing_data_event tracing_data;
  320. struct build_id_event build_id;
  321. struct id_index_event id_index;
  322. struct auxtrace_info_event auxtrace_info;
  323. struct auxtrace_event auxtrace;
  324. struct auxtrace_error_event auxtrace_error;
  325. struct aux_event aux;
  326. struct itrace_start_event itrace_start;
  327. };
  328. void perf_event__print_totals(void);
  329. struct perf_tool;
  330. struct thread_map;
  331. typedef int (*perf_event__handler_t)(struct perf_tool *tool,
  332. union perf_event *event,
  333. struct perf_sample *sample,
  334. struct machine *machine);
  335. int perf_event__synthesize_thread_map(struct perf_tool *tool,
  336. struct thread_map *threads,
  337. perf_event__handler_t process,
  338. struct machine *machine, bool mmap_data,
  339. unsigned int proc_map_timeout);
  340. int perf_event__synthesize_threads(struct perf_tool *tool,
  341. perf_event__handler_t process,
  342. struct machine *machine, bool mmap_data,
  343. unsigned int proc_map_timeout);
  344. int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
  345. perf_event__handler_t process,
  346. struct machine *machine);
  347. int perf_event__synthesize_modules(struct perf_tool *tool,
  348. perf_event__handler_t process,
  349. struct machine *machine);
  350. int perf_event__process_comm(struct perf_tool *tool,
  351. union perf_event *event,
  352. struct perf_sample *sample,
  353. struct machine *machine);
  354. int perf_event__process_lost(struct perf_tool *tool,
  355. union perf_event *event,
  356. struct perf_sample *sample,
  357. struct machine *machine);
  358. int perf_event__process_lost_samples(struct perf_tool *tool,
  359. union perf_event *event,
  360. struct perf_sample *sample,
  361. struct machine *machine);
  362. int perf_event__process_aux(struct perf_tool *tool,
  363. union perf_event *event,
  364. struct perf_sample *sample,
  365. struct machine *machine);
  366. int perf_event__process_itrace_start(struct perf_tool *tool,
  367. union perf_event *event,
  368. struct perf_sample *sample,
  369. struct machine *machine);
  370. int perf_event__process_mmap(struct perf_tool *tool,
  371. union perf_event *event,
  372. struct perf_sample *sample,
  373. struct machine *machine);
  374. int perf_event__process_mmap2(struct perf_tool *tool,
  375. union perf_event *event,
  376. struct perf_sample *sample,
  377. struct machine *machine);
  378. int perf_event__process_fork(struct perf_tool *tool,
  379. union perf_event *event,
  380. struct perf_sample *sample,
  381. struct machine *machine);
  382. int perf_event__process_exit(struct perf_tool *tool,
  383. union perf_event *event,
  384. struct perf_sample *sample,
  385. struct machine *machine);
  386. int perf_event__process(struct perf_tool *tool,
  387. union perf_event *event,
  388. struct perf_sample *sample,
  389. struct machine *machine);
  390. struct addr_location;
  391. int perf_event__preprocess_sample(const union perf_event *event,
  392. struct machine *machine,
  393. struct addr_location *al,
  394. struct perf_sample *sample);
  395. void addr_location__put(struct addr_location *al);
  396. struct thread;
  397. bool is_bts_event(struct perf_event_attr *attr);
  398. bool sample_addr_correlates_sym(struct perf_event_attr *attr);
  399. void perf_event__preprocess_sample_addr(union perf_event *event,
  400. struct perf_sample *sample,
  401. struct thread *thread,
  402. struct addr_location *al);
  403. const char *perf_event__name(unsigned int id);
  404. size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
  405. u64 read_format);
  406. int perf_event__synthesize_sample(union perf_event *event, u64 type,
  407. u64 read_format,
  408. const struct perf_sample *sample,
  409. bool swapped);
  410. int perf_event__synthesize_mmap_events(struct perf_tool *tool,
  411. union perf_event *event,
  412. pid_t pid, pid_t tgid,
  413. perf_event__handler_t process,
  414. struct machine *machine,
  415. bool mmap_data,
  416. unsigned int proc_map_timeout);
  417. size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
  418. size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
  419. size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
  420. size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
  421. size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
  422. size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
  423. size_t perf_event__fprintf(union perf_event *event, FILE *fp);
  424. u64 kallsyms__get_function_start(const char *kallsyms_filename,
  425. const char *symbol_name);
  426. #endif /* __PERF_RECORD_H */