blob: 34c6fcb82d927757058f249982e3215ca962e8d4 [file] [log] [blame]
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001#ifndef __PERF_RECORD_H
2#define __PERF_RECORD_H
John Kacur8b40f522009-09-24 18:02:18 +02003
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +02004#include "../perf.h"
Frederic Weisbecker66e274f2009-08-12 11:07:25 +02005#include "util.h"
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -03006#include <linux/list.h>
Arnaldo Carvalho de Melo1b46cdd2009-09-28 14:48:46 -03007#include <linux/rbtree.h>
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +02008
Peter Zijlstra18408dd2009-08-13 11:47:55 +02009/*
10 * PERF_SAMPLE_IP | PERF_SAMPLE_TID | *
11 */
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020012struct ip_event {
13 struct perf_event_header header;
14 u64 ip;
15 u32 pid, tid;
16 unsigned char __more_data[];
17};
18
19struct mmap_event {
20 struct perf_event_header header;
21 u32 pid, tid;
22 u64 start;
23 u64 len;
24 u64 pgoff;
25 char filename[PATH_MAX];
26};
27
28struct comm_event {
29 struct perf_event_header header;
30 u32 pid, tid;
31 char comm[16];
32};
33
34struct fork_event {
35 struct perf_event_header header;
36 u32 pid, ppid;
37 u32 tid, ptid;
Arjan van de Ven393b2ad2009-09-12 07:52:47 +020038 u64 time;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020039};
40
41struct lost_event {
42 struct perf_event_header header;
43 u64 id;
44 u64 lost;
45};
46
Peter Zijlstra18408dd2009-08-13 11:47:55 +020047/*
48 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
49 */
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020050struct read_event {
51 struct perf_event_header header;
Ingo Molnardc02bf72009-09-16 13:45:00 +020052 u32 pid, tid;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020053 u64 value;
54 u64 time_enabled;
55 u64 time_running;
56 u64 id;
57};
58
Arjan van de Venfd39e052009-09-12 07:53:00 +020059struct sample_event{
60 struct perf_event_header header;
61 u64 array[];
62};
63
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020064#define BUILD_ID_SIZE 20
65
66struct build_id_event {
67 struct perf_event_header header;
68 u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
69 char filename[];
70};
Arjan van de Venfd39e052009-09-12 07:53:00 +020071
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020072typedef union event_union {
73 struct perf_event_header header;
74 struct ip_event ip;
75 struct mmap_event mmap;
76 struct comm_event comm;
77 struct fork_event fork;
78 struct lost_event lost;
79 struct read_event read;
Arjan van de Venfd39e052009-09-12 07:53:00 +020080 struct sample_event sample;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020081} event_t;
Frederic Weisbecker66e274f2009-08-12 11:07:25 +020082
83struct map {
Arnaldo Carvalho de Melo439d4732009-10-02 03:29:58 -030084 union {
85 struct rb_node rb_node;
86 struct list_head node;
87 };
Frederic Weisbecker66e274f2009-08-12 11:07:25 +020088 u64 start;
89 u64 end;
90 u64 pgoff;
91 u64 (*map_ip)(struct map *, u64);
Arnaldo Carvalho de Meloed52ce22009-10-19 17:17:57 -020092 u64 (*unmap_ip)(struct map *, u64);
Frederic Weisbecker66e274f2009-08-12 11:07:25 +020093 struct dso *dso;
94};
95
96static inline u64 map__map_ip(struct map *map, u64 ip)
97{
98 return ip - map->start + map->pgoff;
99}
100
Arnaldo Carvalho de Meloed52ce22009-10-19 17:17:57 -0200101static inline u64 map__unmap_ip(struct map *map, u64 ip)
102{
103 return ip + map->start - map->pgoff;
104}
105
106static inline u64 identity__map_ip(struct map *map __used, u64 ip)
Frederic Weisbecker66e274f2009-08-12 11:07:25 +0200107{
108 return ip;
109}
110
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200111struct symbol;
112
113typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
114
Arnaldo Carvalho de Meloafb7b4f2009-10-30 16:28:23 -0200115void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
116 struct dso *dso);
Arnaldo Carvalho de Melo00a192b2009-10-30 16:28:24 -0200117struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen);
Frederic Weisbecker66e274f2009-08-12 11:07:25 +0200118struct map *map__clone(struct map *self);
119int map__overlap(struct map *l, struct map *r);
120size_t map__fprintf(struct map *self, FILE *fp);
Arnaldo Carvalho de Melo66bd8422009-10-28 21:51:21 -0200121struct symbol *map__find_symbol(struct map *self, u64 ip, symbol_filter_t filter);
Frederic Weisbecker66e274f2009-08-12 11:07:25 +0200122
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200123int event__synthesize_thread(pid_t pid, int (*process)(event_t *event));
124void event__synthesize_threads(int (*process)(event_t *event));
125
John Kacur8b40f522009-09-24 18:02:18 +0200126#endif /* __PERF_RECORD_H */