diff options
Diffstat (limited to 'tools/perf/builtin-diff.c')
-rw-r--r-- | tools/perf/builtin-diff.c | 127 |
1 files changed, 56 insertions, 71 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index bd71b8ceafb7..a6e2fdc7a04e 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -19,22 +19,15 @@ | |||
19 | static char const *input_old = "perf.data.old", | 19 | static char const *input_old = "perf.data.old", |
20 | *input_new = "perf.data"; | 20 | *input_new = "perf.data"; |
21 | static char diff__default_sort_order[] = "dso,symbol"; | 21 | static char diff__default_sort_order[] = "dso,symbol"; |
22 | static int force; | 22 | static bool force; |
23 | static bool show_displacement; | 23 | static bool show_displacement; |
24 | 24 | ||
25 | static int perf_session__add_hist_entry(struct perf_session *self, | 25 | static int hists__add_entry(struct hists *self, |
26 | struct addr_location *al, u64 count) | 26 | struct addr_location *al, u64 period) |
27 | { | 27 | { |
28 | bool hit; | 28 | if (__hists__add_entry(self, al, NULL, period) != NULL) |
29 | struct hist_entry *he = __perf_session__add_hist_entry(self, al, NULL, | 29 | return 0; |
30 | count, &hit); | 30 | return -ENOMEM; |
31 | if (he == NULL) | ||
32 | return -ENOMEM; | ||
33 | |||
34 | if (hit) | ||
35 | he->count += count; | ||
36 | |||
37 | return 0; | ||
38 | } | 31 | } |
39 | 32 | ||
40 | static int diff__process_sample_event(event_t *event, struct perf_session *session) | 33 | static int diff__process_sample_event(event_t *event, struct perf_session *session) |
@@ -42,8 +35,8 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi | |||
42 | struct addr_location al; | 35 | struct addr_location al; |
43 | struct sample_data data = { .period = 1, }; | 36 | struct sample_data data = { .period = 1, }; |
44 | 37 | ||
45 | dump_printf("(IP, %d): %d: %p\n", event->header.misc, | 38 | dump_printf("(IP, %d): %d: %#Lx\n", event->header.misc, |
46 | event->ip.pid, (void *)(long)event->ip.ip); | 39 | event->ip.pid, event->ip.ip); |
47 | 40 | ||
48 | if (event__preprocess_sample(event, session, &al, NULL) < 0) { | 41 | if (event__preprocess_sample(event, session, &al, NULL) < 0) { |
49 | pr_warning("problem processing %d event, skipping it.\n", | 42 | pr_warning("problem processing %d event, skipping it.\n", |
@@ -51,27 +44,27 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi | |||
51 | return -1; | 44 | return -1; |
52 | } | 45 | } |
53 | 46 | ||
54 | if (al.filtered) | 47 | if (al.filtered || al.sym == NULL) |
55 | return 0; | 48 | return 0; |
56 | 49 | ||
57 | event__parse_sample(event, session->sample_type, &data); | 50 | event__parse_sample(event, session->sample_type, &data); |
58 | 51 | ||
59 | if (al.sym && perf_session__add_hist_entry(session, &al, data.period)) { | 52 | if (hists__add_entry(&session->hists, &al, data.period)) { |
60 | pr_warning("problem incrementing symbol count, skipping event\n"); | 53 | pr_warning("problem incrementing symbol period, skipping event\n"); |
61 | return -1; | 54 | return -1; |
62 | } | 55 | } |
63 | 56 | ||
64 | session->events_stats.total += data.period; | 57 | session->hists.stats.total_period += data.period; |
65 | return 0; | 58 | return 0; |
66 | } | 59 | } |
67 | 60 | ||
68 | static struct perf_event_ops event_ops = { | 61 | static struct perf_event_ops event_ops = { |
69 | .process_sample_event = diff__process_sample_event, | 62 | .sample = diff__process_sample_event, |
70 | .process_mmap_event = event__process_mmap, | 63 | .mmap = event__process_mmap, |
71 | .process_comm_event = event__process_comm, | 64 | .comm = event__process_comm, |
72 | .process_exit_event = event__process_task, | 65 | .exit = event__process_task, |
73 | .process_fork_event = event__process_task, | 66 | .fork = event__process_task, |
74 | .process_lost_event = event__process_lost, | 67 | .lost = event__process_lost, |
75 | }; | 68 | }; |
76 | 69 | ||
77 | static void perf_session__insert_hist_entry_by_name(struct rb_root *root, | 70 | static void perf_session__insert_hist_entry_by_name(struct rb_root *root, |
@@ -82,84 +75,69 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, | |||
82 | struct hist_entry *iter; | 75 | struct hist_entry *iter; |
83 | 76 | ||
84 | while (*p != NULL) { | 77 | while (*p != NULL) { |
85 | int cmp; | ||
86 | parent = *p; | 78 | parent = *p; |
87 | iter = rb_entry(parent, struct hist_entry, rb_node); | 79 | iter = rb_entry(parent, struct hist_entry, rb_node); |
88 | 80 | if (hist_entry__cmp(he, iter) < 0) | |
89 | cmp = strcmp(he->map->dso->name, iter->map->dso->name); | ||
90 | if (cmp > 0) | ||
91 | p = &(*p)->rb_left; | 81 | p = &(*p)->rb_left; |
92 | else if (cmp < 0) | 82 | else |
93 | p = &(*p)->rb_right; | 83 | p = &(*p)->rb_right; |
94 | else { | ||
95 | cmp = strcmp(he->sym->name, iter->sym->name); | ||
96 | if (cmp > 0) | ||
97 | p = &(*p)->rb_left; | ||
98 | else | ||
99 | p = &(*p)->rb_right; | ||
100 | } | ||
101 | } | 84 | } |
102 | 85 | ||
103 | rb_link_node(&he->rb_node, parent, p); | 86 | rb_link_node(&he->rb_node, parent, p); |
104 | rb_insert_color(&he->rb_node, root); | 87 | rb_insert_color(&he->rb_node, root); |
105 | } | 88 | } |
106 | 89 | ||
107 | static void perf_session__resort_by_name(struct perf_session *self) | 90 | static void hists__resort_entries(struct hists *self) |
108 | { | 91 | { |
109 | unsigned long position = 1; | 92 | unsigned long position = 1; |
110 | struct rb_root tmp = RB_ROOT; | 93 | struct rb_root tmp = RB_ROOT; |
111 | struct rb_node *next = rb_first(&self->hists); | 94 | struct rb_node *next = rb_first(&self->entries); |
112 | 95 | ||
113 | while (next != NULL) { | 96 | while (next != NULL) { |
114 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); | 97 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); |
115 | 98 | ||
116 | next = rb_next(&n->rb_node); | 99 | next = rb_next(&n->rb_node); |
117 | rb_erase(&n->rb_node, &self->hists); | 100 | rb_erase(&n->rb_node, &self->entries); |
118 | n->position = position++; | 101 | n->position = position++; |
119 | perf_session__insert_hist_entry_by_name(&tmp, n); | 102 | perf_session__insert_hist_entry_by_name(&tmp, n); |
120 | } | 103 | } |
121 | 104 | ||
122 | self->hists = tmp; | 105 | self->entries = tmp; |
123 | } | 106 | } |
124 | 107 | ||
125 | static struct hist_entry * | 108 | static void hists__set_positions(struct hists *self) |
126 | perf_session__find_hist_entry_by_name(struct perf_session *self, | ||
127 | struct hist_entry *he) | ||
128 | { | 109 | { |
129 | struct rb_node *n = self->hists.rb_node; | 110 | hists__output_resort(self); |
111 | hists__resort_entries(self); | ||
112 | } | ||
113 | |||
114 | static struct hist_entry *hists__find_entry(struct hists *self, | ||
115 | struct hist_entry *he) | ||
116 | { | ||
117 | struct rb_node *n = self->entries.rb_node; | ||
130 | 118 | ||
131 | while (n) { | 119 | while (n) { |
132 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); | 120 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); |
133 | int cmp = strcmp(he->map->dso->name, iter->map->dso->name); | 121 | int64_t cmp = hist_entry__cmp(he, iter); |
134 | 122 | ||
135 | if (cmp > 0) | 123 | if (cmp < 0) |
136 | n = n->rb_left; | 124 | n = n->rb_left; |
137 | else if (cmp < 0) | 125 | else if (cmp > 0) |
138 | n = n->rb_right; | 126 | n = n->rb_right; |
139 | else { | 127 | else |
140 | cmp = strcmp(he->sym->name, iter->sym->name); | 128 | return iter; |
141 | if (cmp > 0) | ||
142 | n = n->rb_left; | ||
143 | else if (cmp < 0) | ||
144 | n = n->rb_right; | ||
145 | else | ||
146 | return iter; | ||
147 | } | ||
148 | } | 129 | } |
149 | 130 | ||
150 | return NULL; | 131 | return NULL; |
151 | } | 132 | } |
152 | 133 | ||
153 | static void perf_session__match_hists(struct perf_session *old_session, | 134 | static void hists__match(struct hists *older, struct hists *newer) |
154 | struct perf_session *new_session) | ||
155 | { | 135 | { |
156 | struct rb_node *nd; | 136 | struct rb_node *nd; |
157 | 137 | ||
158 | perf_session__resort_by_name(old_session); | 138 | for (nd = rb_first(&newer->entries); nd; nd = rb_next(nd)) { |
159 | |||
160 | for (nd = rb_first(&new_session->hists); nd; nd = rb_next(nd)) { | ||
161 | struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node); | 139 | struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node); |
162 | pos->pair = perf_session__find_hist_entry_by_name(old_session, pos); | 140 | pos->pair = hists__find_entry(older, pos); |
163 | } | 141 | } |
164 | } | 142 | } |
165 | 143 | ||
@@ -168,8 +146,8 @@ static int __cmd_diff(void) | |||
168 | int ret, i; | 146 | int ret, i; |
169 | struct perf_session *session[2]; | 147 | struct perf_session *session[2]; |
170 | 148 | ||
171 | session[0] = perf_session__new(input_old, O_RDONLY, force); | 149 | session[0] = perf_session__new(input_old, O_RDONLY, force, false); |
172 | session[1] = perf_session__new(input_new, O_RDONLY, force); | 150 | session[1] = perf_session__new(input_new, O_RDONLY, force, false); |
173 | if (session[0] == NULL || session[1] == NULL) | 151 | if (session[0] == NULL || session[1] == NULL) |
174 | return -ENOMEM; | 152 | return -ENOMEM; |
175 | 153 | ||
@@ -177,12 +155,15 @@ static int __cmd_diff(void) | |||
177 | ret = perf_session__process_events(session[i], &event_ops); | 155 | ret = perf_session__process_events(session[i], &event_ops); |
178 | if (ret) | 156 | if (ret) |
179 | goto out_delete; | 157 | goto out_delete; |
180 | perf_session__output_resort(session[i], session[i]->events_stats.total); | ||
181 | } | 158 | } |
182 | 159 | ||
183 | perf_session__match_hists(session[0], session[1]); | 160 | hists__output_resort(&session[1]->hists); |
184 | perf_session__fprintf_hists(session[1], session[0], | 161 | if (show_displacement) |
185 | show_displacement, stdout); | 162 | hists__set_positions(&session[0]->hists); |
163 | |||
164 | hists__match(&session[0]->hists, &session[1]->hists); | ||
165 | hists__fprintf(&session[1]->hists, &session[0]->hists, | ||
166 | show_displacement, stdout); | ||
186 | out_delete: | 167 | out_delete: |
187 | for (i = 0; i < 2; ++i) | 168 | for (i = 0; i < 2; ++i) |
188 | perf_session__delete(session[i]); | 169 | perf_session__delete(session[i]); |
@@ -195,7 +176,7 @@ static const char * const diff_usage[] = { | |||
195 | }; | 176 | }; |
196 | 177 | ||
197 | static const struct option options[] = { | 178 | static const struct option options[] = { |
198 | OPT_BOOLEAN('v', "verbose", &verbose, | 179 | OPT_INCR('v', "verbose", &verbose, |
199 | "be more verbose (show symbol address, etc)"), | 180 | "be more verbose (show symbol address, etc)"), |
200 | OPT_BOOLEAN('m', "displacement", &show_displacement, | 181 | OPT_BOOLEAN('m', "displacement", &show_displacement, |
201 | "Show position displacement relative to baseline"), | 182 | "Show position displacement relative to baseline"), |
@@ -204,7 +185,7 @@ static const struct option options[] = { | |||
204 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 185 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
205 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, | 186 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
206 | "load module symbols - WARNING: use only with -k and LIVE kernel"), | 187 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
207 | OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths, | 188 | OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths, |
208 | "Don't shorten the pathnames taking into account the cwd"), | 189 | "Don't shorten the pathnames taking into account the cwd"), |
209 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | 190 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
210 | "only consider symbols in these dsos"), | 191 | "only consider symbols in these dsos"), |
@@ -232,6 +213,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix __used) | |||
232 | input_new = argv[1]; | 213 | input_new = argv[1]; |
233 | } else | 214 | } else |
234 | input_new = argv[0]; | 215 | input_new = argv[0]; |
216 | } else if (symbol_conf.default_guest_vmlinux_name || | ||
217 | symbol_conf.default_guest_kallsyms) { | ||
218 | input_old = "perf.data.host"; | ||
219 | input_new = "perf.data.guest"; | ||
235 | } | 220 | } |
236 | 221 | ||
237 | symbol_conf.exclude_other = false; | 222 | symbol_conf.exclude_other = false; |