diff options
author | Roberto Agostino Vitillo <ravitillo@lbl.gov> | 2012-02-09 17:21:01 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2012-03-09 02:26:04 -0500 |
commit | b5387528f31d98acedf06e930554b563d87e2383 (patch) | |
tree | 0a8fff59cc7d1392d7adfbbc0f9beacc9ca6d20b /tools | |
parent | d010b3326cf06b3406cdd88af16dcf4e4b6fec2e (diff) |
perf tools: Add code to support PERF_SAMPLE_BRANCH_STACK
This patch adds:
- ability to parse samples with PERF_SAMPLE_BRANCH_STACK
- sort on branches (dso_from, symbol_from, dso_to, symbol_to, mispredict)
- build histograms on branches
Signed-off-by: Roberto Agostino Vitillo <ravitillo@lbl.gov>
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: peterz@infradead.org
Cc: acme@redhat.com
Cc: robert.richter@amd.com
Cc: ming.m.lin@intel.com
Cc: andi@firstfloor.org
Cc: asharma@fb.com
Cc: vweaver1@eecs.utk.edu
Cc: khandual@linux.vnet.ibm.com
Cc: dsahern@gmail.com
Link: http://lkml.kernel.org/r/1328826068-11713-12-git-send-email-eranian@google.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/perf.h | 17 | ||||
-rw-r--r-- | tools/perf/util/event.h | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 10 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 122 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 11 | ||||
-rw-r--r-- | tools/perf/util/session.c | 72 | ||||
-rw-r--r-- | tools/perf/util/session.h | 4 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 287 | ||||
-rw-r--r-- | tools/perf/util/sort.h | 9 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 13 |
10 files changed, 468 insertions, 78 deletions
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index f0227e93665d..358f40135c4d 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -179,6 +179,23 @@ struct ip_callchain { | |||
179 | u64 ips[0]; | 179 | u64 ips[0]; |
180 | }; | 180 | }; |
181 | 181 | ||
182 | struct branch_flags { | ||
183 | u64 mispred:1; | ||
184 | u64 predicted:1; | ||
185 | u64 reserved:62; | ||
186 | }; | ||
187 | |||
188 | struct branch_entry { | ||
189 | u64 from; | ||
190 | u64 to; | ||
191 | struct branch_flags flags; | ||
192 | }; | ||
193 | |||
194 | struct branch_stack { | ||
195 | u64 nr; | ||
196 | struct branch_entry entries[0]; | ||
197 | }; | ||
198 | |||
182 | extern bool perf_host, perf_guest; | 199 | extern bool perf_host, perf_guest; |
183 | extern const char perf_version_string[]; | 200 | extern const char perf_version_string[]; |
184 | 201 | ||
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index cbdeaad9c5e5..1b197280c621 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -81,6 +81,7 @@ struct perf_sample { | |||
81 | u32 raw_size; | 81 | u32 raw_size; |
82 | void *raw_data; | 82 | void *raw_data; |
83 | struct ip_callchain *callchain; | 83 | struct ip_callchain *callchain; |
84 | struct branch_stack *branch_stack; | ||
84 | }; | 85 | }; |
85 | 86 | ||
86 | #define BUILD_ID_SIZE 20 | 87 | #define BUILD_ID_SIZE 20 |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 302d49a9f985..a1fd1cd2a5af 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -576,6 +576,16 @@ int perf_event__parse_sample(const union perf_event *event, u64 type, | |||
576 | data->raw_data = (void *) pdata; | 576 | data->raw_data = (void *) pdata; |
577 | } | 577 | } |
578 | 578 | ||
579 | if (type & PERF_SAMPLE_BRANCH_STACK) { | ||
580 | u64 sz; | ||
581 | |||
582 | data->branch_stack = (struct branch_stack *)array; | ||
583 | array++; /* nr */ | ||
584 | |||
585 | sz = data->branch_stack->nr * sizeof(struct branch_entry); | ||
586 | sz /= sizeof(u64); | ||
587 | array += sz; | ||
588 | } | ||
579 | return 0; | 589 | return 0; |
580 | } | 590 | } |
581 | 591 | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 6f505d1abac7..8380c3db1c92 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -50,21 +50,25 @@ static void hists__reset_col_len(struct hists *hists) | |||
50 | hists__set_col_len(hists, col, 0); | 50 | hists__set_col_len(hists, col, 0); |
51 | } | 51 | } |
52 | 52 | ||
53 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) | ||
54 | { | ||
55 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; | ||
56 | |||
57 | if (hists__col_len(hists, dso) < unresolved_col_width && | ||
58 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && | ||
59 | !symbol_conf.dso_list) | ||
60 | hists__set_col_len(hists, dso, unresolved_col_width); | ||
61 | } | ||
62 | |||
53 | static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) | 63 | static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
54 | { | 64 | { |
65 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; | ||
55 | u16 len; | 66 | u16 len; |
56 | 67 | ||
57 | if (h->ms.sym) | 68 | if (h->ms.sym) |
58 | hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen); | 69 | hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4); |
59 | else { | 70 | else |
60 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; | 71 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
61 | |||
62 | if (hists__col_len(hists, HISTC_DSO) < unresolved_col_width && | ||
63 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && | ||
64 | !symbol_conf.dso_list) | ||
65 | hists__set_col_len(hists, HISTC_DSO, | ||
66 | unresolved_col_width); | ||
67 | } | ||
68 | 72 | ||
69 | len = thread__comm_len(h->thread); | 73 | len = thread__comm_len(h->thread); |
70 | if (hists__new_col_len(hists, HISTC_COMM, len)) | 74 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
@@ -74,6 +78,37 @@ static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) | |||
74 | len = dso__name_len(h->ms.map->dso); | 78 | len = dso__name_len(h->ms.map->dso); |
75 | hists__new_col_len(hists, HISTC_DSO, len); | 79 | hists__new_col_len(hists, HISTC_DSO, len); |
76 | } | 80 | } |
81 | |||
82 | if (h->branch_info) { | ||
83 | int symlen; | ||
84 | /* | ||
85 | * +4 accounts for '[x] ' priv level info | ||
86 | * +2 account of 0x prefix on raw addresses | ||
87 | */ | ||
88 | if (h->branch_info->from.sym) { | ||
89 | symlen = (int)h->branch_info->from.sym->namelen + 4; | ||
90 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); | ||
91 | |||
92 | symlen = dso__name_len(h->branch_info->from.map->dso); | ||
93 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); | ||
94 | } else { | ||
95 | symlen = unresolved_col_width + 4 + 2; | ||
96 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); | ||
97 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); | ||
98 | } | ||
99 | |||
100 | if (h->branch_info->to.sym) { | ||
101 | symlen = (int)h->branch_info->to.sym->namelen + 4; | ||
102 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); | ||
103 | |||
104 | symlen = dso__name_len(h->branch_info->to.map->dso); | ||
105 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); | ||
106 | } else { | ||
107 | symlen = unresolved_col_width + 4 + 2; | ||
108 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); | ||
109 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); | ||
110 | } | ||
111 | } | ||
77 | } | 112 | } |
78 | 113 | ||
79 | static void hist_entry__add_cpumode_period(struct hist_entry *he, | 114 | static void hist_entry__add_cpumode_period(struct hist_entry *he, |
@@ -195,26 +230,14 @@ static u8 symbol__parent_filter(const struct symbol *parent) | |||
195 | return 0; | 230 | return 0; |
196 | } | 231 | } |
197 | 232 | ||
198 | struct hist_entry *__hists__add_entry(struct hists *hists, | 233 | static struct hist_entry *add_hist_entry(struct hists *hists, |
234 | struct hist_entry *entry, | ||
199 | struct addr_location *al, | 235 | struct addr_location *al, |
200 | struct symbol *sym_parent, u64 period) | 236 | u64 period) |
201 | { | 237 | { |
202 | struct rb_node **p; | 238 | struct rb_node **p; |
203 | struct rb_node *parent = NULL; | 239 | struct rb_node *parent = NULL; |
204 | struct hist_entry *he; | 240 | struct hist_entry *he; |
205 | struct hist_entry entry = { | ||
206 | .thread = al->thread, | ||
207 | .ms = { | ||
208 | .map = al->map, | ||
209 | .sym = al->sym, | ||
210 | }, | ||
211 | .cpu = al->cpu, | ||
212 | .ip = al->addr, | ||
213 | .level = al->level, | ||
214 | .period = period, | ||
215 | .parent = sym_parent, | ||
216 | .filtered = symbol__parent_filter(sym_parent), | ||
217 | }; | ||
218 | int cmp; | 241 | int cmp; |
219 | 242 | ||
220 | pthread_mutex_lock(&hists->lock); | 243 | pthread_mutex_lock(&hists->lock); |
@@ -225,7 +248,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
225 | parent = *p; | 248 | parent = *p; |
226 | he = rb_entry(parent, struct hist_entry, rb_node_in); | 249 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
227 | 250 | ||
228 | cmp = hist_entry__cmp(&entry, he); | 251 | cmp = hist_entry__cmp(entry, he); |
229 | 252 | ||
230 | if (!cmp) { | 253 | if (!cmp) { |
231 | he->period += period; | 254 | he->period += period; |
@@ -239,7 +262,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
239 | p = &(*p)->rb_right; | 262 | p = &(*p)->rb_right; |
240 | } | 263 | } |
241 | 264 | ||
242 | he = hist_entry__new(&entry); | 265 | he = hist_entry__new(entry); |
243 | if (!he) | 266 | if (!he) |
244 | goto out_unlock; | 267 | goto out_unlock; |
245 | 268 | ||
@@ -252,6 +275,51 @@ out_unlock: | |||
252 | return he; | 275 | return he; |
253 | } | 276 | } |
254 | 277 | ||
278 | struct hist_entry *__hists__add_branch_entry(struct hists *self, | ||
279 | struct addr_location *al, | ||
280 | struct symbol *sym_parent, | ||
281 | struct branch_info *bi, | ||
282 | u64 period) | ||
283 | { | ||
284 | struct hist_entry entry = { | ||
285 | .thread = al->thread, | ||
286 | .ms = { | ||
287 | .map = bi->to.map, | ||
288 | .sym = bi->to.sym, | ||
289 | }, | ||
290 | .cpu = al->cpu, | ||
291 | .ip = bi->to.addr, | ||
292 | .level = al->level, | ||
293 | .period = period, | ||
294 | .parent = sym_parent, | ||
295 | .filtered = symbol__parent_filter(sym_parent), | ||
296 | .branch_info = bi, | ||
297 | }; | ||
298 | |||
299 | return add_hist_entry(self, &entry, al, period); | ||
300 | } | ||
301 | |||
302 | struct hist_entry *__hists__add_entry(struct hists *self, | ||
303 | struct addr_location *al, | ||
304 | struct symbol *sym_parent, u64 period) | ||
305 | { | ||
306 | struct hist_entry entry = { | ||
307 | .thread = al->thread, | ||
308 | .ms = { | ||
309 | .map = al->map, | ||
310 | .sym = al->sym, | ||
311 | }, | ||
312 | .cpu = al->cpu, | ||
313 | .ip = al->addr, | ||
314 | .level = al->level, | ||
315 | .period = period, | ||
316 | .parent = sym_parent, | ||
317 | .filtered = symbol__parent_filter(sym_parent), | ||
318 | }; | ||
319 | |||
320 | return add_hist_entry(self, &entry, al, period); | ||
321 | } | ||
322 | |||
255 | int64_t | 323 | int64_t |
256 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | 324 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
257 | { | 325 | { |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 48e5acd1e862..9413f3e31fea 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -42,6 +42,11 @@ enum hist_column { | |||
42 | HISTC_COMM, | 42 | HISTC_COMM, |
43 | HISTC_PARENT, | 43 | HISTC_PARENT, |
44 | HISTC_CPU, | 44 | HISTC_CPU, |
45 | HISTC_MISPREDICT, | ||
46 | HISTC_SYMBOL_FROM, | ||
47 | HISTC_SYMBOL_TO, | ||
48 | HISTC_DSO_FROM, | ||
49 | HISTC_DSO_TO, | ||
45 | HISTC_NR_COLS, /* Last entry */ | 50 | HISTC_NR_COLS, /* Last entry */ |
46 | }; | 51 | }; |
47 | 52 | ||
@@ -74,6 +79,12 @@ int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size, | |||
74 | struct hists *hists); | 79 | struct hists *hists); |
75 | void hist_entry__free(struct hist_entry *); | 80 | void hist_entry__free(struct hist_entry *); |
76 | 81 | ||
82 | struct hist_entry *__hists__add_branch_entry(struct hists *self, | ||
83 | struct addr_location *al, | ||
84 | struct symbol *sym_parent, | ||
85 | struct branch_info *bi, | ||
86 | u64 period); | ||
87 | |||
77 | void hists__output_resort(struct hists *self); | 88 | void hists__output_resort(struct hists *self); |
78 | void hists__output_resort_threaded(struct hists *hists); | 89 | void hists__output_resort_threaded(struct hists *hists); |
79 | void hists__collapse_resort(struct hists *self); | 90 | void hists__collapse_resort(struct hists *self); |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 9f833cf9c6a9..bec8a328b1b8 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -229,6 +229,63 @@ static bool symbol__match_parent_regex(struct symbol *sym) | |||
229 | return 0; | 229 | return 0; |
230 | } | 230 | } |
231 | 231 | ||
232 | static const u8 cpumodes[] = { | ||
233 | PERF_RECORD_MISC_USER, | ||
234 | PERF_RECORD_MISC_KERNEL, | ||
235 | PERF_RECORD_MISC_GUEST_USER, | ||
236 | PERF_RECORD_MISC_GUEST_KERNEL | ||
237 | }; | ||
238 | #define NCPUMODES (sizeof(cpumodes)/sizeof(u8)) | ||
239 | |||
240 | static void ip__resolve_ams(struct machine *self, struct thread *thread, | ||
241 | struct addr_map_symbol *ams, | ||
242 | u64 ip) | ||
243 | { | ||
244 | struct addr_location al; | ||
245 | size_t i; | ||
246 | u8 m; | ||
247 | |||
248 | memset(&al, 0, sizeof(al)); | ||
249 | |||
250 | for (i = 0; i < NCPUMODES; i++) { | ||
251 | m = cpumodes[i]; | ||
252 | /* | ||
253 | * We cannot use the header.misc hint to determine whether a | ||
254 | * branch stack address is user, kernel, guest, hypervisor. | ||
255 | * Branches may straddle the kernel/user/hypervisor boundaries. | ||
256 | * Thus, we have to try consecutively until we find a match | ||
257 | * or else, the symbol is unknown | ||
258 | */ | ||
259 | thread__find_addr_location(thread, self, m, MAP__FUNCTION, | ||
260 | ip, &al, NULL); | ||
261 | if (al.sym) | ||
262 | goto found; | ||
263 | } | ||
264 | found: | ||
265 | ams->addr = ip; | ||
266 | ams->sym = al.sym; | ||
267 | ams->map = al.map; | ||
268 | } | ||
269 | |||
270 | struct branch_info *machine__resolve_bstack(struct machine *self, | ||
271 | struct thread *thr, | ||
272 | struct branch_stack *bs) | ||
273 | { | ||
274 | struct branch_info *bi; | ||
275 | unsigned int i; | ||
276 | |||
277 | bi = calloc(bs->nr, sizeof(struct branch_info)); | ||
278 | if (!bi) | ||
279 | return NULL; | ||
280 | |||
281 | for (i = 0; i < bs->nr; i++) { | ||
282 | ip__resolve_ams(self, thr, &bi[i].to, bs->entries[i].to); | ||
283 | ip__resolve_ams(self, thr, &bi[i].from, bs->entries[i].from); | ||
284 | bi[i].flags = bs->entries[i].flags; | ||
285 | } | ||
286 | return bi; | ||
287 | } | ||
288 | |||
232 | int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, | 289 | int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel, |
233 | struct thread *thread, | 290 | struct thread *thread, |
234 | struct ip_callchain *chain, | 291 | struct ip_callchain *chain, |
@@ -697,6 +754,18 @@ static void callchain__printf(struct perf_sample *sample) | |||
697 | i, sample->callchain->ips[i]); | 754 | i, sample->callchain->ips[i]); |
698 | } | 755 | } |
699 | 756 | ||
757 | static void branch_stack__printf(struct perf_sample *sample) | ||
758 | { | ||
759 | uint64_t i; | ||
760 | |||
761 | printf("... branch stack: nr:%" PRIu64 "\n", sample->branch_stack->nr); | ||
762 | |||
763 | for (i = 0; i < sample->branch_stack->nr; i++) | ||
764 | printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 "\n", | ||
765 | i, sample->branch_stack->entries[i].from, | ||
766 | sample->branch_stack->entries[i].to); | ||
767 | } | ||
768 | |||
700 | static void perf_session__print_tstamp(struct perf_session *session, | 769 | static void perf_session__print_tstamp(struct perf_session *session, |
701 | union perf_event *event, | 770 | union perf_event *event, |
702 | struct perf_sample *sample) | 771 | struct perf_sample *sample) |
@@ -744,6 +813,9 @@ static void dump_sample(struct perf_session *session, union perf_event *event, | |||
744 | 813 | ||
745 | if (session->sample_type & PERF_SAMPLE_CALLCHAIN) | 814 | if (session->sample_type & PERF_SAMPLE_CALLCHAIN) |
746 | callchain__printf(sample); | 815 | callchain__printf(sample); |
816 | |||
817 | if (session->sample_type & PERF_SAMPLE_BRANCH_STACK) | ||
818 | branch_stack__printf(sample); | ||
747 | } | 819 | } |
748 | 820 | ||
749 | static struct machine * | 821 | static struct machine * |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index c8d90178e7de..7a5434c00565 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -73,6 +73,10 @@ int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel | |||
73 | struct ip_callchain *chain, | 73 | struct ip_callchain *chain, |
74 | struct symbol **parent); | 74 | struct symbol **parent); |
75 | 75 | ||
76 | struct branch_info *machine__resolve_bstack(struct machine *self, | ||
77 | struct thread *thread, | ||
78 | struct branch_stack *bs); | ||
79 | |||
76 | bool perf_session__has_traces(struct perf_session *self, const char *msg); | 80 | bool perf_session__has_traces(struct perf_session *self, const char *msg); |
77 | 81 | ||
78 | void mem_bswap_64(void *src, int byte_size); | 82 | void mem_bswap_64(void *src, int byte_size); |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 16da30d8d765..2739ed10d5e6 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -8,6 +8,7 @@ const char default_sort_order[] = "comm,dso,symbol"; | |||
8 | const char *sort_order = default_sort_order; | 8 | const char *sort_order = default_sort_order; |
9 | int sort__need_collapse = 0; | 9 | int sort__need_collapse = 0; |
10 | int sort__has_parent = 0; | 10 | int sort__has_parent = 0; |
11 | bool sort__branch_mode; | ||
11 | 12 | ||
12 | enum sort_type sort__first_dimension; | 13 | enum sort_type sort__first_dimension; |
13 | 14 | ||
@@ -94,6 +95,26 @@ static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, | |||
94 | return repsep_snprintf(bf, size, "%*s", width, self->thread->comm); | 95 | return repsep_snprintf(bf, size, "%*s", width, self->thread->comm); |
95 | } | 96 | } |
96 | 97 | ||
98 | static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r) | ||
99 | { | ||
100 | struct dso *dso_l = map_l ? map_l->dso : NULL; | ||
101 | struct dso *dso_r = map_r ? map_r->dso : NULL; | ||
102 | const char *dso_name_l, *dso_name_r; | ||
103 | |||
104 | if (!dso_l || !dso_r) | ||
105 | return cmp_null(dso_l, dso_r); | ||
106 | |||
107 | if (verbose) { | ||
108 | dso_name_l = dso_l->long_name; | ||
109 | dso_name_r = dso_r->long_name; | ||
110 | } else { | ||
111 | dso_name_l = dso_l->short_name; | ||
112 | dso_name_r = dso_r->short_name; | ||
113 | } | ||
114 | |||
115 | return strcmp(dso_name_l, dso_name_r); | ||
116 | } | ||
117 | |||
97 | struct sort_entry sort_comm = { | 118 | struct sort_entry sort_comm = { |
98 | .se_header = "Command", | 119 | .se_header = "Command", |
99 | .se_cmp = sort__comm_cmp, | 120 | .se_cmp = sort__comm_cmp, |
@@ -107,36 +128,74 @@ struct sort_entry sort_comm = { | |||
107 | static int64_t | 128 | static int64_t |
108 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | 129 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
109 | { | 130 | { |
110 | struct dso *dso_l = left->ms.map ? left->ms.map->dso : NULL; | 131 | return _sort__dso_cmp(left->ms.map, right->ms.map); |
111 | struct dso *dso_r = right->ms.map ? right->ms.map->dso : NULL; | 132 | } |
112 | const char *dso_name_l, *dso_name_r; | ||
113 | 133 | ||
114 | if (!dso_l || !dso_r) | ||
115 | return cmp_null(dso_l, dso_r); | ||
116 | 134 | ||
117 | if (verbose) { | 135 | static int64_t _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r, |
118 | dso_name_l = dso_l->long_name; | 136 | u64 ip_l, u64 ip_r) |
119 | dso_name_r = dso_r->long_name; | 137 | { |
120 | } else { | 138 | if (!sym_l || !sym_r) |
121 | dso_name_l = dso_l->short_name; | 139 | return cmp_null(sym_l, sym_r); |
122 | dso_name_r = dso_r->short_name; | 140 | |
141 | if (sym_l == sym_r) | ||
142 | return 0; | ||
143 | |||
144 | if (sym_l) | ||
145 | ip_l = sym_l->start; | ||
146 | if (sym_r) | ||
147 | ip_r = sym_r->start; | ||
148 | |||
149 | return (int64_t)(ip_r - ip_l); | ||
150 | } | ||
151 | |||
152 | static int _hist_entry__dso_snprintf(struct map *map, char *bf, | ||
153 | size_t size, unsigned int width) | ||
154 | { | ||
155 | if (map && map->dso) { | ||
156 | const char *dso_name = !verbose ? map->dso->short_name : | ||
157 | map->dso->long_name; | ||
158 | return repsep_snprintf(bf, size, "%-*s", width, dso_name); | ||
123 | } | 159 | } |
124 | 160 | ||
125 | return strcmp(dso_name_l, dso_name_r); | 161 | return repsep_snprintf(bf, size, "%-*s", width, "[unknown]"); |
126 | } | 162 | } |
127 | 163 | ||
128 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, | 164 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, |
129 | size_t size, unsigned int width) | 165 | size_t size, unsigned int width) |
130 | { | 166 | { |
131 | if (self->ms.map && self->ms.map->dso) { | 167 | return _hist_entry__dso_snprintf(self->ms.map, bf, size, width); |
132 | const char *dso_name = !verbose ? self->ms.map->dso->short_name : | 168 | } |
133 | self->ms.map->dso->long_name; | 169 | |
134 | return repsep_snprintf(bf, size, "%-*s", width, dso_name); | 170 | static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, |
171 | u64 ip, char level, char *bf, size_t size, | ||
172 | unsigned int width __used) | ||
173 | { | ||
174 | size_t ret = 0; | ||
175 | |||
176 | if (verbose) { | ||
177 | char o = map ? dso__symtab_origin(map->dso) : '!'; | ||
178 | ret += repsep_snprintf(bf, size, "%-#*llx %c ", | ||
179 | BITS_PER_LONG / 4, ip, o); | ||
135 | } | 180 | } |
136 | 181 | ||
137 | return repsep_snprintf(bf, size, "%-*s", width, "[unknown]"); | 182 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level); |
183 | if (sym) | ||
184 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", | ||
185 | width - ret, | ||
186 | sym->name); | ||
187 | else { | ||
188 | size_t len = BITS_PER_LONG / 4; | ||
189 | ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", | ||
190 | len, ip); | ||
191 | ret += repsep_snprintf(bf + ret, size - ret, "%-*s", | ||
192 | width - ret, ""); | ||
193 | } | ||
194 | |||
195 | return ret; | ||
138 | } | 196 | } |
139 | 197 | ||
198 | |||
140 | struct sort_entry sort_dso = { | 199 | struct sort_entry sort_dso = { |
141 | .se_header = "Shared Object", | 200 | .se_header = "Shared Object", |
142 | .se_cmp = sort__dso_cmp, | 201 | .se_cmp = sort__dso_cmp, |
@@ -144,8 +203,14 @@ struct sort_entry sort_dso = { | |||
144 | .se_width_idx = HISTC_DSO, | 203 | .se_width_idx = HISTC_DSO, |
145 | }; | 204 | }; |
146 | 205 | ||
147 | /* --sort symbol */ | 206 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, |
207 | size_t size, unsigned int width __used) | ||
208 | { | ||
209 | return _hist_entry__sym_snprintf(self->ms.map, self->ms.sym, self->ip, | ||
210 | self->level, bf, size, width); | ||
211 | } | ||
148 | 212 | ||
213 | /* --sort symbol */ | ||
149 | static int64_t | 214 | static int64_t |
150 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | 215 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) |
151 | { | 216 | { |
@@ -163,31 +228,7 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | |||
163 | ip_l = left->ms.sym->start; | 228 | ip_l = left->ms.sym->start; |
164 | ip_r = right->ms.sym->start; | 229 | ip_r = right->ms.sym->start; |
165 | 230 | ||
166 | return (int64_t)(ip_r - ip_l); | 231 | return _sort__sym_cmp(left->ms.sym, right->ms.sym, ip_l, ip_r); |
167 | } | ||
168 | |||
169 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | ||
170 | size_t size, unsigned int width __used) | ||
171 | { | ||
172 | size_t ret = 0; | ||
173 | |||
174 | if (verbose) { | ||
175 | char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!'; | ||
176 | ret += repsep_snprintf(bf, size, "%-#*llx %c ", | ||
177 | BITS_PER_LONG / 4, self->ip, o); | ||
178 | } | ||
179 | |||
180 | if (!sort_dso.elide) | ||
181 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level); | ||
182 | |||
183 | if (self->ms.sym) | ||
184 | ret += repsep_snprintf(bf + ret, size - ret, "%s", | ||
185 | self->ms.sym->name); | ||
186 | else | ||
187 | ret += repsep_snprintf(bf + ret, size - ret, "%-#*llx", | ||
188 | BITS_PER_LONG / 4, self->ip); | ||
189 | |||
190 | return ret; | ||
191 | } | 232 | } |
192 | 233 | ||
193 | struct sort_entry sort_sym = { | 234 | struct sort_entry sort_sym = { |
@@ -246,19 +287,155 @@ struct sort_entry sort_cpu = { | |||
246 | .se_width_idx = HISTC_CPU, | 287 | .se_width_idx = HISTC_CPU, |
247 | }; | 288 | }; |
248 | 289 | ||
290 | static int64_t | ||
291 | sort__dso_from_cmp(struct hist_entry *left, struct hist_entry *right) | ||
292 | { | ||
293 | return _sort__dso_cmp(left->branch_info->from.map, | ||
294 | right->branch_info->from.map); | ||
295 | } | ||
296 | |||
297 | static int hist_entry__dso_from_snprintf(struct hist_entry *self, char *bf, | ||
298 | size_t size, unsigned int width) | ||
299 | { | ||
300 | return _hist_entry__dso_snprintf(self->branch_info->from.map, | ||
301 | bf, size, width); | ||
302 | } | ||
303 | |||
304 | struct sort_entry sort_dso_from = { | ||
305 | .se_header = "Source Shared Object", | ||
306 | .se_cmp = sort__dso_from_cmp, | ||
307 | .se_snprintf = hist_entry__dso_from_snprintf, | ||
308 | .se_width_idx = HISTC_DSO_FROM, | ||
309 | }; | ||
310 | |||
311 | static int64_t | ||
312 | sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right) | ||
313 | { | ||
314 | return _sort__dso_cmp(left->branch_info->to.map, | ||
315 | right->branch_info->to.map); | ||
316 | } | ||
317 | |||
318 | static int hist_entry__dso_to_snprintf(struct hist_entry *self, char *bf, | ||
319 | size_t size, unsigned int width) | ||
320 | { | ||
321 | return _hist_entry__dso_snprintf(self->branch_info->to.map, | ||
322 | bf, size, width); | ||
323 | } | ||
324 | |||
325 | static int64_t | ||
326 | sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right) | ||
327 | { | ||
328 | struct addr_map_symbol *from_l = &left->branch_info->from; | ||
329 | struct addr_map_symbol *from_r = &right->branch_info->from; | ||
330 | |||
331 | if (!from_l->sym && !from_r->sym) | ||
332 | return right->level - left->level; | ||
333 | |||
334 | return _sort__sym_cmp(from_l->sym, from_r->sym, from_l->addr, | ||
335 | from_r->addr); | ||
336 | } | ||
337 | |||
338 | static int64_t | ||
339 | sort__sym_to_cmp(struct hist_entry *left, struct hist_entry *right) | ||
340 | { | ||
341 | struct addr_map_symbol *to_l = &left->branch_info->to; | ||
342 | struct addr_map_symbol *to_r = &right->branch_info->to; | ||
343 | |||
344 | if (!to_l->sym && !to_r->sym) | ||
345 | return right->level - left->level; | ||
346 | |||
347 | return _sort__sym_cmp(to_l->sym, to_r->sym, to_l->addr, to_r->addr); | ||
348 | } | ||
349 | |||
350 | static int hist_entry__sym_from_snprintf(struct hist_entry *self, char *bf, | ||
351 | size_t size, unsigned int width __used) | ||
352 | { | ||
353 | struct addr_map_symbol *from = &self->branch_info->from; | ||
354 | return _hist_entry__sym_snprintf(from->map, from->sym, from->addr, | ||
355 | self->level, bf, size, width); | ||
356 | |||
357 | } | ||
358 | |||
359 | static int hist_entry__sym_to_snprintf(struct hist_entry *self, char *bf, | ||
360 | size_t size, unsigned int width __used) | ||
361 | { | ||
362 | struct addr_map_symbol *to = &self->branch_info->to; | ||
363 | return _hist_entry__sym_snprintf(to->map, to->sym, to->addr, | ||
364 | self->level, bf, size, width); | ||
365 | |||
366 | } | ||
367 | |||
368 | struct sort_entry sort_dso_to = { | ||
369 | .se_header = "Target Shared Object", | ||
370 | .se_cmp = sort__dso_to_cmp, | ||
371 | .se_snprintf = hist_entry__dso_to_snprintf, | ||
372 | .se_width_idx = HISTC_DSO_TO, | ||
373 | }; | ||
374 | |||
375 | struct sort_entry sort_sym_from = { | ||
376 | .se_header = "Source Symbol", | ||
377 | .se_cmp = sort__sym_from_cmp, | ||
378 | .se_snprintf = hist_entry__sym_from_snprintf, | ||
379 | .se_width_idx = HISTC_SYMBOL_FROM, | ||
380 | }; | ||
381 | |||
382 | struct sort_entry sort_sym_to = { | ||
383 | .se_header = "Target Symbol", | ||
384 | .se_cmp = sort__sym_to_cmp, | ||
385 | .se_snprintf = hist_entry__sym_to_snprintf, | ||
386 | .se_width_idx = HISTC_SYMBOL_TO, | ||
387 | }; | ||
388 | |||
389 | static int64_t | ||
390 | sort__mispredict_cmp(struct hist_entry *left, struct hist_entry *right) | ||
391 | { | ||
392 | const unsigned char mp = left->branch_info->flags.mispred != | ||
393 | right->branch_info->flags.mispred; | ||
394 | const unsigned char p = left->branch_info->flags.predicted != | ||
395 | right->branch_info->flags.predicted; | ||
396 | |||
397 | return mp || p; | ||
398 | } | ||
399 | |||
400 | static int hist_entry__mispredict_snprintf(struct hist_entry *self, char *bf, | ||
401 | size_t size, unsigned int width){ | ||
402 | static const char *out = "N/A"; | ||
403 | |||
404 | if (self->branch_info->flags.predicted) | ||
405 | out = "N"; | ||
406 | else if (self->branch_info->flags.mispred) | ||
407 | out = "Y"; | ||
408 | |||
409 | return repsep_snprintf(bf, size, "%-*s", width, out); | ||
410 | } | ||
411 | |||
412 | struct sort_entry sort_mispredict = { | ||
413 | .se_header = "Branch Mispredicted", | ||
414 | .se_cmp = sort__mispredict_cmp, | ||
415 | .se_snprintf = hist_entry__mispredict_snprintf, | ||
416 | .se_width_idx = HISTC_MISPREDICT, | ||
417 | }; | ||
418 | |||
249 | struct sort_dimension { | 419 | struct sort_dimension { |
250 | const char *name; | 420 | const char *name; |
251 | struct sort_entry *entry; | 421 | struct sort_entry *entry; |
252 | int taken; | 422 | int taken; |
253 | }; | 423 | }; |
254 | 424 | ||
425 | #define DIM(d, n, func) [d] = { .name = n, .entry = &(func) } | ||
426 | |||
255 | static struct sort_dimension sort_dimensions[] = { | 427 | static struct sort_dimension sort_dimensions[] = { |
256 | { .name = "pid", .entry = &sort_thread, }, | 428 | DIM(SORT_PID, "pid", sort_thread), |
257 | { .name = "comm", .entry = &sort_comm, }, | 429 | DIM(SORT_COMM, "comm", sort_comm), |
258 | { .name = "dso", .entry = &sort_dso, }, | 430 | DIM(SORT_DSO, "dso", sort_dso), |
259 | { .name = "symbol", .entry = &sort_sym, }, | 431 | DIM(SORT_DSO_FROM, "dso_from", sort_dso_from), |
260 | { .name = "parent", .entry = &sort_parent, }, | 432 | DIM(SORT_DSO_TO, "dso_to", sort_dso_to), |
261 | { .name = "cpu", .entry = &sort_cpu, }, | 433 | DIM(SORT_SYM, "symbol", sort_sym), |
434 | DIM(SORT_SYM_TO, "symbol_from", sort_sym_from), | ||
435 | DIM(SORT_SYM_FROM, "symbol_to", sort_sym_to), | ||
436 | DIM(SORT_PARENT, "parent", sort_parent), | ||
437 | DIM(SORT_CPU, "cpu", sort_cpu), | ||
438 | DIM(SORT_MISPREDICT, "mispredict", sort_mispredict), | ||
262 | }; | 439 | }; |
263 | 440 | ||
264 | int sort_dimension__add(const char *tok) | 441 | int sort_dimension__add(const char *tok) |
@@ -270,7 +447,6 @@ int sort_dimension__add(const char *tok) | |||
270 | 447 | ||
271 | if (strncasecmp(tok, sd->name, strlen(tok))) | 448 | if (strncasecmp(tok, sd->name, strlen(tok))) |
272 | continue; | 449 | continue; |
273 | |||
274 | if (sd->entry == &sort_parent) { | 450 | if (sd->entry == &sort_parent) { |
275 | int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED); | 451 | int ret = regcomp(&parent_regex, parent_pattern, REG_EXTENDED); |
276 | if (ret) { | 452 | if (ret) { |
@@ -302,6 +478,16 @@ int sort_dimension__add(const char *tok) | |||
302 | sort__first_dimension = SORT_PARENT; | 478 | sort__first_dimension = SORT_PARENT; |
303 | else if (!strcmp(sd->name, "cpu")) | 479 | else if (!strcmp(sd->name, "cpu")) |
304 | sort__first_dimension = SORT_CPU; | 480 | sort__first_dimension = SORT_CPU; |
481 | else if (!strcmp(sd->name, "symbol_from")) | ||
482 | sort__first_dimension = SORT_SYM_FROM; | ||
483 | else if (!strcmp(sd->name, "symbol_to")) | ||
484 | sort__first_dimension = SORT_SYM_TO; | ||
485 | else if (!strcmp(sd->name, "dso_from")) | ||
486 | sort__first_dimension = SORT_DSO_FROM; | ||
487 | else if (!strcmp(sd->name, "dso_to")) | ||
488 | sort__first_dimension = SORT_DSO_TO; | ||
489 | else if (!strcmp(sd->name, "mispredict")) | ||
490 | sort__first_dimension = SORT_MISPREDICT; | ||
305 | } | 491 | } |
306 | 492 | ||
307 | list_add_tail(&sd->entry->list, &hist_entry__sort_list); | 493 | list_add_tail(&sd->entry->list, &hist_entry__sort_list); |
@@ -309,7 +495,6 @@ int sort_dimension__add(const char *tok) | |||
309 | 495 | ||
310 | return 0; | 496 | return 0; |
311 | } | 497 | } |
312 | |||
313 | return -ESRCH; | 498 | return -ESRCH; |
314 | } | 499 | } |
315 | 500 | ||
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 3f67ae395752..7aa72a00bc8e 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -31,11 +31,14 @@ extern const char *parent_pattern; | |||
31 | extern const char default_sort_order[]; | 31 | extern const char default_sort_order[]; |
32 | extern int sort__need_collapse; | 32 | extern int sort__need_collapse; |
33 | extern int sort__has_parent; | 33 | extern int sort__has_parent; |
34 | extern bool sort__branch_mode; | ||
34 | extern char *field_sep; | 35 | extern char *field_sep; |
35 | extern struct sort_entry sort_comm; | 36 | extern struct sort_entry sort_comm; |
36 | extern struct sort_entry sort_dso; | 37 | extern struct sort_entry sort_dso; |
37 | extern struct sort_entry sort_sym; | 38 | extern struct sort_entry sort_sym; |
38 | extern struct sort_entry sort_parent; | 39 | extern struct sort_entry sort_parent; |
40 | extern struct sort_entry sort_lbr_dso; | ||
41 | extern struct sort_entry sort_lbr_sym; | ||
39 | extern enum sort_type sort__first_dimension; | 42 | extern enum sort_type sort__first_dimension; |
40 | 43 | ||
41 | /** | 44 | /** |
@@ -72,6 +75,7 @@ struct hist_entry { | |||
72 | struct hist_entry *pair; | 75 | struct hist_entry *pair; |
73 | struct rb_root sorted_chain; | 76 | struct rb_root sorted_chain; |
74 | }; | 77 | }; |
78 | struct branch_info *branch_info; | ||
75 | struct callchain_root callchain[0]; | 79 | struct callchain_root callchain[0]; |
76 | }; | 80 | }; |
77 | 81 | ||
@@ -82,6 +86,11 @@ enum sort_type { | |||
82 | SORT_SYM, | 86 | SORT_SYM, |
83 | SORT_PARENT, | 87 | SORT_PARENT, |
84 | SORT_CPU, | 88 | SORT_CPU, |
89 | SORT_DSO_FROM, | ||
90 | SORT_DSO_TO, | ||
91 | SORT_SYM_FROM, | ||
92 | SORT_SYM_TO, | ||
93 | SORT_MISPREDICT, | ||
85 | }; | 94 | }; |
86 | 95 | ||
87 | /* | 96 | /* |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 2a683d4fc918..5866ce6b9c02 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <stdint.h> | 6 | #include <stdint.h> |
7 | #include "map.h" | 7 | #include "map.h" |
8 | #include "../perf.h" | ||
8 | #include <linux/list.h> | 9 | #include <linux/list.h> |
9 | #include <linux/rbtree.h> | 10 | #include <linux/rbtree.h> |
10 | #include <stdio.h> | 11 | #include <stdio.h> |
@@ -120,6 +121,18 @@ struct map_symbol { | |||
120 | bool has_children; | 121 | bool has_children; |
121 | }; | 122 | }; |
122 | 123 | ||
124 | struct addr_map_symbol { | ||
125 | struct map *map; | ||
126 | struct symbol *sym; | ||
127 | u64 addr; | ||
128 | }; | ||
129 | |||
130 | struct branch_info { | ||
131 | struct addr_map_symbol from; | ||
132 | struct addr_map_symbol to; | ||
133 | struct branch_flags flags; | ||
134 | }; | ||
135 | |||
123 | struct addr_location { | 136 | struct addr_location { |
124 | struct thread *thread; | 137 | struct thread *thread; |
125 | struct map *map; | 138 | struct map *map; |