diff options
author | Ingo Molnar <mingo@elte.hu> | 2010-05-15 02:39:09 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-05-15 02:39:09 -0400 |
commit | 7ebaa2838a751125c113072486334d7b4e63f9ad (patch) | |
tree | b0081ab2236cc11f21e27e32d0fc221a467292f0 | |
parent | 1ff3d7d79204612ebe2e611d2592f8898908ca00 (diff) | |
parent | 3e1bbdc3a721f4b1ed44f4554402a8dbc60fa97f (diff) |
Merge branch 'perf' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 into perf/core
-rw-r--r-- | tools/perf/Makefile | 2 | ||||
-rw-r--r-- | tools/perf/builtin-annotate.c | 2 | ||||
-rw-r--r-- | tools/perf/builtin-diff.c | 8 | ||||
-rw-r--r-- | tools/perf/builtin-report.c | 44 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 17 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 2 | ||||
-rw-r--r-- | tools/perf/util/event.c | 19 | ||||
-rw-r--r-- | tools/perf/util/event.h | 2 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 121 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 24 | ||||
-rw-r--r-- | tools/perf/util/newt.c | 46 | ||||
-rw-r--r-- | tools/perf/util/pstack.c | 75 | ||||
-rw-r--r-- | tools/perf/util/pstack.h | 12 | ||||
-rw-r--r-- | tools/perf/util/session.c | 36 | ||||
-rw-r--r-- | tools/perf/util/session.h | 8 | ||||
-rw-r--r-- | tools/perf/util/sort.h | 11 | ||||
-rw-r--r-- | tools/perf/util/util.c | 22 | ||||
-rw-r--r-- | tools/perf/util/util.h | 1 |
18 files changed, 322 insertions, 130 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 9c4dc30cdc13..a9281cca4114 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -416,6 +416,7 @@ LIB_H += util/thread.h | |||
416 | LIB_H += util/trace-event.h | 416 | LIB_H += util/trace-event.h |
417 | LIB_H += util/probe-finder.h | 417 | LIB_H += util/probe-finder.h |
418 | LIB_H += util/probe-event.h | 418 | LIB_H += util/probe-event.h |
419 | LIB_H += util/pstack.h | ||
419 | LIB_H += util/cpumap.h | 420 | LIB_H += util/cpumap.h |
420 | 421 | ||
421 | LIB_OBJS += $(OUTPUT)util/abspath.o | 422 | LIB_OBJS += $(OUTPUT)util/abspath.o |
@@ -451,6 +452,7 @@ LIB_OBJS += $(OUTPUT)util/callchain.o | |||
451 | LIB_OBJS += $(OUTPUT)util/values.o | 452 | LIB_OBJS += $(OUTPUT)util/values.o |
452 | LIB_OBJS += $(OUTPUT)util/debug.o | 453 | LIB_OBJS += $(OUTPUT)util/debug.o |
453 | LIB_OBJS += $(OUTPUT)util/map.o | 454 | LIB_OBJS += $(OUTPUT)util/map.o |
455 | LIB_OBJS += $(OUTPUT)util/pstack.o | ||
454 | LIB_OBJS += $(OUTPUT)util/session.o | 456 | LIB_OBJS += $(OUTPUT)util/session.o |
455 | LIB_OBJS += $(OUTPUT)util/thread.o | 457 | LIB_OBJS += $(OUTPUT)util/thread.o |
456 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o | 458 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index fd1b786c8f35..77bcc9b130f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -365,7 +365,7 @@ static int __cmd_annotate(void) | |||
365 | goto out_delete; | 365 | goto out_delete; |
366 | 366 | ||
367 | if (dump_trace) { | 367 | if (dump_trace) { |
368 | event__print_totals(); | 368 | perf_session__fprintf_nr_events(session, stdout); |
369 | goto out_delete; | 369 | goto out_delete; |
370 | } | 370 | } |
371 | 371 | ||
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 3a95a0260a5b..a6e2fdc7a04e 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -23,9 +23,9 @@ static bool force; | |||
23 | static bool show_displacement; | 23 | static bool show_displacement; |
24 | 24 | ||
25 | static int hists__add_entry(struct hists *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 | if (__hists__add_entry(self, al, NULL, count) != NULL) | 28 | if (__hists__add_entry(self, al, NULL, period) != NULL) |
29 | return 0; | 29 | return 0; |
30 | return -ENOMEM; | 30 | return -ENOMEM; |
31 | } | 31 | } |
@@ -50,11 +50,11 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi | |||
50 | event__parse_sample(event, session->sample_type, &data); | 50 | event__parse_sample(event, session->sample_type, &data); |
51 | 51 | ||
52 | if (hists__add_entry(&session->hists, &al, data.period)) { | 52 | if (hists__add_entry(&session->hists, &al, data.period)) { |
53 | pr_warning("problem incrementing symbol count, skipping event\n"); | 53 | pr_warning("problem incrementing symbol period, skipping event\n"); |
54 | return -1; | 54 | return -1; |
55 | } | 55 | } |
56 | 56 | ||
57 | session->hists.stats.total += data.period; | 57 | session->hists.stats.total_period += data.period; |
58 | return 0; | 58 | return 0; |
59 | } | 59 | } |
60 | 60 | ||
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 04de3387de3f..68265120ee07 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -138,8 +138,14 @@ static int add_event_total(struct perf_session *session, | |||
138 | if (!hists) | 138 | if (!hists) |
139 | return -ENOMEM; | 139 | return -ENOMEM; |
140 | 140 | ||
141 | hists->stats.total += data->period; | 141 | hists->stats.total_period += data->period; |
142 | session->hists.stats.total += data->period; | 142 | /* |
143 | * FIXME: add_event_total should be moved from here to | ||
144 | * perf_session__process_event so that the proper hist is passed to | ||
145 | * the event_op methods. | ||
146 | */ | ||
147 | hists__inc_nr_events(hists, PERF_RECORD_SAMPLE); | ||
148 | session->hists.stats.total_period += data->period; | ||
143 | return 0; | 149 | return 0; |
144 | } | 150 | } |
145 | 151 | ||
@@ -182,14 +188,14 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
182 | return 0; | 188 | return 0; |
183 | 189 | ||
184 | if (perf_session__add_hist_entry(session, &al, &data)) { | 190 | if (perf_session__add_hist_entry(session, &al, &data)) { |
185 | pr_debug("problem incrementing symbol count, skipping event\n"); | 191 | pr_debug("problem incrementing symbol period, skipping event\n"); |
186 | return -1; | 192 | return -1; |
187 | } | 193 | } |
188 | 194 | ||
189 | attr = perf_header__find_attr(data.id, &session->header); | 195 | attr = perf_header__find_attr(data.id, &session->header); |
190 | 196 | ||
191 | if (add_event_total(session, &data, attr)) { | 197 | if (add_event_total(session, &data, attr)) { |
192 | pr_debug("problem adding event count\n"); | 198 | pr_debug("problem adding event period\n"); |
193 | return -1; | 199 | return -1; |
194 | } | 200 | } |
195 | 201 | ||
@@ -263,11 +269,25 @@ static struct perf_event_ops event_ops = { | |||
263 | 269 | ||
264 | extern volatile int session_done; | 270 | extern volatile int session_done; |
265 | 271 | ||
266 | static void sig_handler(int sig __attribute__((__unused__))) | 272 | static void sig_handler(int sig __used) |
267 | { | 273 | { |
268 | session_done = 1; | 274 | session_done = 1; |
269 | } | 275 | } |
270 | 276 | ||
277 | static size_t hists__fprintf_nr_sample_events(struct hists *self, | ||
278 | const char *evname, FILE *fp) | ||
279 | { | ||
280 | size_t ret; | ||
281 | char unit; | ||
282 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; | ||
283 | |||
284 | nr_events = convert_unit(nr_events, &unit); | ||
285 | ret = fprintf(fp, "# Events: %lu%c", nr_events, unit); | ||
286 | if (evname != NULL) | ||
287 | ret += fprintf(fp, " %s", evname); | ||
288 | return ret + fprintf(fp, "\n#\n"); | ||
289 | } | ||
290 | |||
271 | static int __cmd_report(void) | 291 | static int __cmd_report(void) |
272 | { | 292 | { |
273 | int ret = -EINVAL; | 293 | int ret = -EINVAL; |
@@ -293,7 +313,7 @@ static int __cmd_report(void) | |||
293 | goto out_delete; | 313 | goto out_delete; |
294 | 314 | ||
295 | if (dump_trace) { | 315 | if (dump_trace) { |
296 | event__print_totals(); | 316 | perf_session__fprintf_nr_events(session, stdout); |
297 | goto out_delete; | 317 | goto out_delete; |
298 | } | 318 | } |
299 | 319 | ||
@@ -313,14 +333,12 @@ static int __cmd_report(void) | |||
313 | if (use_browser) | 333 | if (use_browser) |
314 | hists__browse(hists, help, input_name); | 334 | hists__browse(hists, help, input_name); |
315 | else { | 335 | else { |
316 | if (rb_first(&session->hists.entries) == | 336 | const char *evname = NULL; |
337 | if (rb_first(&session->hists.entries) != | ||
317 | rb_last(&session->hists.entries)) | 338 | rb_last(&session->hists.entries)) |
318 | fprintf(stdout, "# Samples: %Ld\n#\n", | 339 | evname = __event_name(hists->type, hists->config); |
319 | hists->stats.total); | 340 | |
320 | else | 341 | hists__fprintf_nr_sample_events(hists, evname, stdout); |
321 | fprintf(stdout, "# Samples: %Ld %s\n#\n", | ||
322 | hists->stats.total, | ||
323 | __event_name(hists->type, hists->config)); | ||
324 | 342 | ||
325 | hists__fprintf(hists, NULL, false, stdout); | 343 | hists__fprintf(hists, NULL, false, stdout); |
326 | fprintf(stdout, "\n\n"); | 344 | fprintf(stdout, "\n\n"); |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index aef6ed0e119c..be7bc9264710 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -1641,19 +1641,10 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
1641 | return 0; | 1641 | return 0; |
1642 | } | 1642 | } |
1643 | 1643 | ||
1644 | static int process_lost_event(event_t *event __used, | ||
1645 | struct perf_session *session __used) | ||
1646 | { | ||
1647 | nr_lost_chunks++; | ||
1648 | nr_lost_events += event->lost.lost; | ||
1649 | |||
1650 | return 0; | ||
1651 | } | ||
1652 | |||
1653 | static struct perf_event_ops event_ops = { | 1644 | static struct perf_event_ops event_ops = { |
1654 | .sample = process_sample_event, | 1645 | .sample = process_sample_event, |
1655 | .comm = event__process_comm, | 1646 | .comm = event__process_comm, |
1656 | .lost = process_lost_event, | 1647 | .lost = event__process_lost, |
1657 | .ordered_samples = true, | 1648 | .ordered_samples = true, |
1658 | }; | 1649 | }; |
1659 | 1650 | ||
@@ -1664,8 +1655,12 @@ static int read_events(void) | |||
1664 | if (session == NULL) | 1655 | if (session == NULL) |
1665 | return -ENOMEM; | 1656 | return -ENOMEM; |
1666 | 1657 | ||
1667 | if (perf_session__has_traces(session, "record -R")) | 1658 | if (perf_session__has_traces(session, "record -R")) { |
1668 | err = perf_session__process_events(session, &event_ops); | 1659 | err = perf_session__process_events(session, &event_ops); |
1660 | nr_events = session->hists.stats.nr_events[0]; | ||
1661 | nr_lost_events = session->hists.stats.total_lost; | ||
1662 | nr_lost_chunks = session->hists.stats.nr_events[PERF_RECORD_LOST]; | ||
1663 | } | ||
1669 | 1664 | ||
1670 | perf_session__delete(session); | 1665 | perf_session__delete(session); |
1671 | return err; | 1666 | return err; |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 95fcb0517a9d..dddf3f01b5ab 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -109,7 +109,7 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
109 | data.time, thread->comm); | 109 | data.time, thread->comm); |
110 | } | 110 | } |
111 | 111 | ||
112 | session->hists.stats.total += data.period; | 112 | session->hists.stats.total_period += data.period; |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | 115 | ||
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index cce006ec8f05..50771b5813ee 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -7,6 +7,23 @@ | |||
7 | #include "strlist.h" | 7 | #include "strlist.h" |
8 | #include "thread.h" | 8 | #include "thread.h" |
9 | 9 | ||
10 | const char *event__name[] = { | ||
11 | [0] = "TOTAL", | ||
12 | [PERF_RECORD_MMAP] = "MMAP", | ||
13 | [PERF_RECORD_LOST] = "LOST", | ||
14 | [PERF_RECORD_COMM] = "COMM", | ||
15 | [PERF_RECORD_EXIT] = "EXIT", | ||
16 | [PERF_RECORD_THROTTLE] = "THROTTLE", | ||
17 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", | ||
18 | [PERF_RECORD_FORK] = "FORK", | ||
19 | [PERF_RECORD_READ] = "READ", | ||
20 | [PERF_RECORD_SAMPLE] = "SAMPLE", | ||
21 | [PERF_RECORD_HEADER_ATTR] = "ATTR", | ||
22 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", | ||
23 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", | ||
24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", | ||
25 | }; | ||
26 | |||
10 | static pid_t event__synthesize_comm(pid_t pid, int full, | 27 | static pid_t event__synthesize_comm(pid_t pid, int full, |
11 | event__handler_t process, | 28 | event__handler_t process, |
12 | struct perf_session *session) | 29 | struct perf_session *session) |
@@ -368,7 +385,7 @@ int event__process_comm(event_t *self, struct perf_session *session) | |||
368 | int event__process_lost(event_t *self, struct perf_session *session) | 385 | int event__process_lost(event_t *self, struct perf_session *session) |
369 | { | 386 | { |
370 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); | 387 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); |
371 | session->hists.stats.lost += self->lost.lost; | 388 | session->hists.stats.total_lost += self->lost.lost; |
372 | return 0; | 389 | return 0; |
373 | } | 390 | } |
374 | 391 | ||
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 48c2cc9dae4f..8577085db067 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -160,4 +160,6 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
160 | struct addr_location *al, symbol_filter_t filter); | 160 | struct addr_location *al, symbol_filter_t filter); |
161 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data); | 161 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data); |
162 | 162 | ||
163 | extern const char *event__name[]; | ||
164 | |||
163 | #endif /* __PERF_RECORD_H */ | 165 | #endif /* __PERF_RECORD_H */ |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 5dc4f8429eda..f75c5f62401c 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -9,21 +9,21 @@ struct callchain_param callchain_param = { | |||
9 | .min_percent = 0.5 | 9 | .min_percent = 0.5 |
10 | }; | 10 | }; |
11 | 11 | ||
12 | static void hist_entry__add_cpumode_count(struct hist_entry *self, | 12 | static void hist_entry__add_cpumode_period(struct hist_entry *self, |
13 | unsigned int cpumode, u64 count) | 13 | unsigned int cpumode, u64 period) |
14 | { | 14 | { |
15 | switch (cpumode) { | 15 | switch (cpumode) { |
16 | case PERF_RECORD_MISC_KERNEL: | 16 | case PERF_RECORD_MISC_KERNEL: |
17 | self->count_sys += count; | 17 | self->period_sys += period; |
18 | break; | 18 | break; |
19 | case PERF_RECORD_MISC_USER: | 19 | case PERF_RECORD_MISC_USER: |
20 | self->count_us += count; | 20 | self->period_us += period; |
21 | break; | 21 | break; |
22 | case PERF_RECORD_MISC_GUEST_KERNEL: | 22 | case PERF_RECORD_MISC_GUEST_KERNEL: |
23 | self->count_guest_sys += count; | 23 | self->period_guest_sys += period; |
24 | break; | 24 | break; |
25 | case PERF_RECORD_MISC_GUEST_USER: | 25 | case PERF_RECORD_MISC_GUEST_USER: |
26 | self->count_guest_us += count; | 26 | self->period_guest_us += period; |
27 | break; | 27 | break; |
28 | default: | 28 | default: |
29 | break; | 29 | break; |
@@ -31,7 +31,7 @@ static void hist_entry__add_cpumode_count(struct hist_entry *self, | |||
31 | } | 31 | } |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * histogram, sorted on item, collects counts | 34 | * histogram, sorted on item, collects periods |
35 | */ | 35 | */ |
36 | 36 | ||
37 | static struct hist_entry *hist_entry__new(struct hist_entry *template) | 37 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
@@ -41,6 +41,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) | |||
41 | 41 | ||
42 | if (self != NULL) { | 42 | if (self != NULL) { |
43 | *self = *template; | 43 | *self = *template; |
44 | self->nr_events = 1; | ||
44 | if (symbol_conf.use_callchain) | 45 | if (symbol_conf.use_callchain) |
45 | callchain_init(self->callchain); | 46 | callchain_init(self->callchain); |
46 | } | 47 | } |
@@ -57,7 +58,7 @@ static void hists__inc_nr_entries(struct hists *self, struct hist_entry *entry) | |||
57 | 58 | ||
58 | struct hist_entry *__hists__add_entry(struct hists *self, | 59 | struct hist_entry *__hists__add_entry(struct hists *self, |
59 | struct addr_location *al, | 60 | struct addr_location *al, |
60 | struct symbol *sym_parent, u64 count) | 61 | struct symbol *sym_parent, u64 period) |
61 | { | 62 | { |
62 | struct rb_node **p = &self->entries.rb_node; | 63 | struct rb_node **p = &self->entries.rb_node; |
63 | struct rb_node *parent = NULL; | 64 | struct rb_node *parent = NULL; |
@@ -70,7 +71,7 @@ struct hist_entry *__hists__add_entry(struct hists *self, | |||
70 | }, | 71 | }, |
71 | .ip = al->addr, | 72 | .ip = al->addr, |
72 | .level = al->level, | 73 | .level = al->level, |
73 | .count = count, | 74 | .period = period, |
74 | .parent = sym_parent, | 75 | .parent = sym_parent, |
75 | }; | 76 | }; |
76 | int cmp; | 77 | int cmp; |
@@ -82,7 +83,8 @@ struct hist_entry *__hists__add_entry(struct hists *self, | |||
82 | cmp = hist_entry__cmp(&entry, he); | 83 | cmp = hist_entry__cmp(&entry, he); |
83 | 84 | ||
84 | if (!cmp) { | 85 | if (!cmp) { |
85 | he->count += count; | 86 | he->period += period; |
87 | ++he->nr_events; | ||
86 | goto out; | 88 | goto out; |
87 | } | 89 | } |
88 | 90 | ||
@@ -99,7 +101,7 @@ struct hist_entry *__hists__add_entry(struct hists *self, | |||
99 | rb_insert_color(&he->rb_node, &self->entries); | 101 | rb_insert_color(&he->rb_node, &self->entries); |
100 | hists__inc_nr_entries(self, he); | 102 | hists__inc_nr_entries(self, he); |
101 | out: | 103 | out: |
102 | hist_entry__add_cpumode_count(he, al->cpumode, count); | 104 | hist_entry__add_cpumode_period(he, al->cpumode, period); |
103 | return he; | 105 | return he; |
104 | } | 106 | } |
105 | 107 | ||
@@ -160,7 +162,7 @@ static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
160 | cmp = hist_entry__collapse(iter, he); | 162 | cmp = hist_entry__collapse(iter, he); |
161 | 163 | ||
162 | if (!cmp) { | 164 | if (!cmp) { |
163 | iter->count += he->count; | 165 | iter->period += he->period; |
164 | hist_entry__free(he); | 166 | hist_entry__free(he); |
165 | return false; | 167 | return false; |
166 | } | 168 | } |
@@ -203,7 +205,7 @@ void hists__collapse_resort(struct hists *self) | |||
203 | } | 205 | } |
204 | 206 | ||
205 | /* | 207 | /* |
206 | * reverse the map, sort on count. | 208 | * reverse the map, sort on period. |
207 | */ | 209 | */ |
208 | 210 | ||
209 | static void __hists__insert_output_entry(struct rb_root *entries, | 211 | static void __hists__insert_output_entry(struct rb_root *entries, |
@@ -222,7 +224,7 @@ static void __hists__insert_output_entry(struct rb_root *entries, | |||
222 | parent = *p; | 224 | parent = *p; |
223 | iter = rb_entry(parent, struct hist_entry, rb_node); | 225 | iter = rb_entry(parent, struct hist_entry, rb_node); |
224 | 226 | ||
225 | if (he->count > iter->count) | 227 | if (he->period > iter->period) |
226 | p = &(*p)->rb_left; | 228 | p = &(*p)->rb_left; |
227 | else | 229 | else |
228 | p = &(*p)->rb_right; | 230 | p = &(*p)->rb_right; |
@@ -239,7 +241,7 @@ void hists__output_resort(struct hists *self) | |||
239 | struct hist_entry *n; | 241 | struct hist_entry *n; |
240 | u64 min_callchain_hits; | 242 | u64 min_callchain_hits; |
241 | 243 | ||
242 | min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100); | 244 | min_callchain_hits = self->stats.total_period * (callchain_param.min_percent / 100); |
243 | 245 | ||
244 | tmp = RB_ROOT; | 246 | tmp = RB_ROOT; |
245 | next = rb_first(&self->entries); | 247 | next = rb_first(&self->entries); |
@@ -288,7 +290,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, | |||
288 | } | 290 | } |
289 | 291 | ||
290 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | 292 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
291 | int depth, int depth_mask, int count, | 293 | int depth, int depth_mask, int period, |
292 | u64 total_samples, int hits, | 294 | u64 total_samples, int hits, |
293 | int left_margin) | 295 | int left_margin) |
294 | { | 296 | { |
@@ -301,7 +303,7 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | |||
301 | ret += fprintf(fp, "|"); | 303 | ret += fprintf(fp, "|"); |
302 | else | 304 | else |
303 | ret += fprintf(fp, " "); | 305 | ret += fprintf(fp, " "); |
304 | if (!count && i == depth - 1) { | 306 | if (!period && i == depth - 1) { |
305 | double percent; | 307 | double percent; |
306 | 308 | ||
307 | percent = hits * 100.0 / total_samples; | 309 | percent = hits * 100.0 / total_samples; |
@@ -516,7 +518,7 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size, | |||
516 | long displacement, bool color, u64 session_total) | 518 | long displacement, bool color, u64 session_total) |
517 | { | 519 | { |
518 | struct sort_entry *se; | 520 | struct sort_entry *se; |
519 | u64 count, total, count_sys, count_us, count_guest_sys, count_guest_us; | 521 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; |
520 | const char *sep = symbol_conf.field_sep; | 522 | const char *sep = symbol_conf.field_sep; |
521 | int ret; | 523 | int ret; |
522 | 524 | ||
@@ -524,57 +526,57 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size, | |||
524 | return 0; | 526 | return 0; |
525 | 527 | ||
526 | if (pair_hists) { | 528 | if (pair_hists) { |
527 | count = self->pair ? self->pair->count : 0; | 529 | period = self->pair ? self->pair->period : 0; |
528 | total = pair_hists->stats.total; | 530 | total = pair_hists->stats.total_period; |
529 | count_sys = self->pair ? self->pair->count_sys : 0; | 531 | period_sys = self->pair ? self->pair->period_sys : 0; |
530 | count_us = self->pair ? self->pair->count_us : 0; | 532 | period_us = self->pair ? self->pair->period_us : 0; |
531 | count_guest_sys = self->pair ? self->pair->count_guest_sys : 0; | 533 | period_guest_sys = self->pair ? self->pair->period_guest_sys : 0; |
532 | count_guest_us = self->pair ? self->pair->count_guest_us : 0; | 534 | period_guest_us = self->pair ? self->pair->period_guest_us : 0; |
533 | } else { | 535 | } else { |
534 | count = self->count; | 536 | period = self->period; |
535 | total = session_total; | 537 | total = session_total; |
536 | count_sys = self->count_sys; | 538 | period_sys = self->period_sys; |
537 | count_us = self->count_us; | 539 | period_us = self->period_us; |
538 | count_guest_sys = self->count_guest_sys; | 540 | period_guest_sys = self->period_guest_sys; |
539 | count_guest_us = self->count_guest_us; | 541 | period_guest_us = self->period_guest_us; |
540 | } | 542 | } |
541 | 543 | ||
542 | if (total) { | 544 | if (total) { |
543 | if (color) | 545 | if (color) |
544 | ret = percent_color_snprintf(s, size, | 546 | ret = percent_color_snprintf(s, size, |
545 | sep ? "%.2f" : " %6.2f%%", | 547 | sep ? "%.2f" : " %6.2f%%", |
546 | (count * 100.0) / total); | 548 | (period * 100.0) / total); |
547 | else | 549 | else |
548 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", | 550 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", |
549 | (count * 100.0) / total); | 551 | (period * 100.0) / total); |
550 | if (symbol_conf.show_cpu_utilization) { | 552 | if (symbol_conf.show_cpu_utilization) { |
551 | ret += percent_color_snprintf(s + ret, size - ret, | 553 | ret += percent_color_snprintf(s + ret, size - ret, |
552 | sep ? "%.2f" : " %6.2f%%", | 554 | sep ? "%.2f" : " %6.2f%%", |
553 | (count_sys * 100.0) / total); | 555 | (period_sys * 100.0) / total); |
554 | ret += percent_color_snprintf(s + ret, size - ret, | 556 | ret += percent_color_snprintf(s + ret, size - ret, |
555 | sep ? "%.2f" : " %6.2f%%", | 557 | sep ? "%.2f" : " %6.2f%%", |
556 | (count_us * 100.0) / total); | 558 | (period_us * 100.0) / total); |
557 | if (perf_guest) { | 559 | if (perf_guest) { |
558 | ret += percent_color_snprintf(s + ret, | 560 | ret += percent_color_snprintf(s + ret, |
559 | size - ret, | 561 | size - ret, |
560 | sep ? "%.2f" : " %6.2f%%", | 562 | sep ? "%.2f" : " %6.2f%%", |
561 | (count_guest_sys * 100.0) / | 563 | (period_guest_sys * 100.0) / |
562 | total); | 564 | total); |
563 | ret += percent_color_snprintf(s + ret, | 565 | ret += percent_color_snprintf(s + ret, |
564 | size - ret, | 566 | size - ret, |
565 | sep ? "%.2f" : " %6.2f%%", | 567 | sep ? "%.2f" : " %6.2f%%", |
566 | (count_guest_us * 100.0) / | 568 | (period_guest_us * 100.0) / |
567 | total); | 569 | total); |
568 | } | 570 | } |
569 | } | 571 | } |
570 | } else | 572 | } else |
571 | ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count); | 573 | ret = snprintf(s, size, sep ? "%lld" : "%12lld ", period); |
572 | 574 | ||
573 | if (symbol_conf.show_nr_samples) { | 575 | if (symbol_conf.show_nr_samples) { |
574 | if (sep) | 576 | if (sep) |
575 | ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count); | 577 | ret += snprintf(s + ret, size - ret, "%c%lld", *sep, period); |
576 | else | 578 | else |
577 | ret += snprintf(s + ret, size - ret, "%11lld", count); | 579 | ret += snprintf(s + ret, size - ret, "%11lld", period); |
578 | } | 580 | } |
579 | 581 | ||
580 | if (pair_hists) { | 582 | if (pair_hists) { |
@@ -582,9 +584,9 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size, | |||
582 | double old_percent = 0, new_percent = 0, diff; | 584 | double old_percent = 0, new_percent = 0, diff; |
583 | 585 | ||
584 | if (total > 0) | 586 | if (total > 0) |
585 | old_percent = (count * 100.0) / total; | 587 | old_percent = (period * 100.0) / total; |
586 | if (session_total > 0) | 588 | if (session_total > 0) |
587 | new_percent = (self->count * 100.0) / session_total; | 589 | new_percent = (self->period * 100.0) / session_total; |
588 | 590 | ||
589 | diff = new_percent - old_percent; | 591 | diff = new_percent - old_percent; |
590 | 592 | ||
@@ -769,10 +771,10 @@ print_entries: | |||
769 | ++position; | 771 | ++position; |
770 | } | 772 | } |
771 | ret += hist_entry__fprintf(h, pair, show_displacement, | 773 | ret += hist_entry__fprintf(h, pair, show_displacement, |
772 | displacement, fp, self->stats.total); | 774 | displacement, fp, self->stats.total_period); |
773 | 775 | ||
774 | if (symbol_conf.use_callchain) | 776 | if (symbol_conf.use_callchain) |
775 | ret += hist_entry__fprintf_callchain(h, fp, self->stats.total); | 777 | ret += hist_entry__fprintf_callchain(h, fp, self->stats.total_period); |
776 | 778 | ||
777 | if (h->ms.map == NULL && verbose > 1) { | 779 | if (h->ms.map == NULL && verbose > 1) { |
778 | __map_groups__fprintf_maps(&h->thread->mg, | 780 | __map_groups__fprintf_maps(&h->thread->mg, |
@@ -795,7 +797,8 @@ void hists__filter_by_dso(struct hists *self, const struct dso *dso) | |||
795 | { | 797 | { |
796 | struct rb_node *nd; | 798 | struct rb_node *nd; |
797 | 799 | ||
798 | self->nr_entries = self->stats.total = 0; | 800 | self->nr_entries = self->stats.total_period = 0; |
801 | self->stats.nr_events[PERF_RECORD_SAMPLE] = 0; | ||
799 | self->max_sym_namelen = 0; | 802 | self->max_sym_namelen = 0; |
800 | 803 | ||
801 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | 804 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
@@ -812,7 +815,8 @@ void hists__filter_by_dso(struct hists *self, const struct dso *dso) | |||
812 | h->filtered &= ~(1 << HIST_FILTER__DSO); | 815 | h->filtered &= ~(1 << HIST_FILTER__DSO); |
813 | if (!h->filtered) { | 816 | if (!h->filtered) { |
814 | ++self->nr_entries; | 817 | ++self->nr_entries; |
815 | self->stats.total += h->count; | 818 | self->stats.total_period += h->period; |
819 | self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; | ||
816 | if (h->ms.sym && | 820 | if (h->ms.sym && |
817 | self->max_sym_namelen < h->ms.sym->namelen) | 821 | self->max_sym_namelen < h->ms.sym->namelen) |
818 | self->max_sym_namelen = h->ms.sym->namelen; | 822 | self->max_sym_namelen = h->ms.sym->namelen; |
@@ -824,7 +828,8 @@ void hists__filter_by_thread(struct hists *self, const struct thread *thread) | |||
824 | { | 828 | { |
825 | struct rb_node *nd; | 829 | struct rb_node *nd; |
826 | 830 | ||
827 | self->nr_entries = self->stats.total = 0; | 831 | self->nr_entries = self->stats.total_period = 0; |
832 | self->stats.nr_events[PERF_RECORD_SAMPLE] = 0; | ||
828 | self->max_sym_namelen = 0; | 833 | self->max_sym_namelen = 0; |
829 | 834 | ||
830 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | 835 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
@@ -837,7 +842,8 @@ void hists__filter_by_thread(struct hists *self, const struct thread *thread) | |||
837 | h->filtered &= ~(1 << HIST_FILTER__THREAD); | 842 | h->filtered &= ~(1 << HIST_FILTER__THREAD); |
838 | if (!h->filtered) { | 843 | if (!h->filtered) { |
839 | ++self->nr_entries; | 844 | ++self->nr_entries; |
840 | self->stats.total += h->count; | 845 | self->stats.total_period += h->period; |
846 | self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; | ||
841 | if (h->ms.sym && | 847 | if (h->ms.sym && |
842 | self->max_sym_namelen < h->ms.sym->namelen) | 848 | self->max_sym_namelen < h->ms.sym->namelen) |
843 | self->max_sym_namelen = h->ms.sym->namelen; | 849 | self->max_sym_namelen = h->ms.sym->namelen; |
@@ -881,7 +887,7 @@ int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip) | |||
881 | h->sum++; | 887 | h->sum++; |
882 | h->ip[offset]++; | 888 | h->ip[offset]++; |
883 | 889 | ||
884 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", self->ms.sym->start, | 890 | pr_debug3("%#Lx %s: period++ [ip: %#Lx, %#Lx] => %Ld\n", self->ms.sym->start, |
885 | self->ms.sym->name, ip, ip - self->ms.sym->start, h->ip[offset]); | 891 | self->ms.sym->name, ip, ip - self->ms.sym->start, h->ip[offset]); |
886 | return 0; | 892 | return 0; |
887 | } | 893 | } |
@@ -1028,3 +1034,24 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | |||
1028 | pclose(file); | 1034 | pclose(file); |
1029 | return 0; | 1035 | return 0; |
1030 | } | 1036 | } |
1037 | |||
1038 | void hists__inc_nr_events(struct hists *self, u32 type) | ||
1039 | { | ||
1040 | ++self->stats.nr_events[0]; | ||
1041 | ++self->stats.nr_events[type]; | ||
1042 | } | ||
1043 | |||
1044 | size_t hists__fprintf_nr_events(struct hists *self, FILE *fp) | ||
1045 | { | ||
1046 | int i; | ||
1047 | size_t ret = 0; | ||
1048 | |||
1049 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { | ||
1050 | if (!event__name[i]) | ||
1051 | continue; | ||
1052 | ret += fprintf(fp, "%10s events: %10d\n", | ||
1053 | event__name[i], self->stats.nr_events[i]); | ||
1054 | } | ||
1055 | |||
1056 | return ret; | ||
1057 | } | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 0b4c8df914bd..6f17dcd8412c 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -37,9 +37,23 @@ struct sym_priv { | |||
37 | struct sym_ext *ext; | 37 | struct sym_ext *ext; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | /* | ||
41 | * The kernel collects the number of events it couldn't send in a stretch and | ||
42 | * when possible sends this number in a PERF_RECORD_LOST event. The number of | ||
43 | * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while | ||
44 | * total_lost tells exactly how many events the kernel in fact lost, i.e. it is | ||
45 | * the sum of all struct lost_event.lost fields reported. | ||
46 | * | ||
47 | * The total_period is needed because by default auto-freq is used, so | ||
48 | * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get | ||
49 | * the total number of low level events, it is necessary to to sum all struct | ||
50 | * sample_event.period and stash the result in total_period. | ||
51 | */ | ||
40 | struct events_stats { | 52 | struct events_stats { |
41 | u64 total; | 53 | u64 total_period; |
42 | u64 lost; | 54 | u64 total_lost; |
55 | u32 nr_events[PERF_RECORD_HEADER_MAX]; | ||
56 | u32 nr_unknown_events; | ||
43 | }; | 57 | }; |
44 | 58 | ||
45 | struct hists { | 59 | struct hists { |
@@ -55,7 +69,7 @@ struct hists { | |||
55 | 69 | ||
56 | struct hist_entry *__hists__add_entry(struct hists *self, | 70 | struct hist_entry *__hists__add_entry(struct hists *self, |
57 | struct addr_location *al, | 71 | struct addr_location *al, |
58 | struct symbol *parent, u64 count); | 72 | struct symbol *parent, u64 period); |
59 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 73 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); |
60 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 74 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); |
61 | int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists, | 75 | int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists, |
@@ -68,6 +82,10 @@ void hist_entry__free(struct hist_entry *); | |||
68 | 82 | ||
69 | void hists__output_resort(struct hists *self); | 83 | void hists__output_resort(struct hists *self); |
70 | void hists__collapse_resort(struct hists *self); | 84 | void hists__collapse_resort(struct hists *self); |
85 | |||
86 | void hists__inc_nr_events(struct hists *self, u32 type); | ||
87 | size_t hists__fprintf_nr_events(struct hists *self, FILE *fp); | ||
88 | |||
71 | size_t hists__fprintf(struct hists *self, struct hists *pair, | 89 | size_t hists__fprintf(struct hists *self, struct hists *pair, |
72 | bool show_displacement, FILE *fp); | 90 | bool show_displacement, FILE *fp); |
73 | 91 | ||
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index ba6acd04c082..e74df1240ef6 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
@@ -9,6 +9,7 @@ | |||
9 | 9 | ||
10 | #include "cache.h" | 10 | #include "cache.h" |
11 | #include "hist.h" | 11 | #include "hist.h" |
12 | #include "pstack.h" | ||
12 | #include "session.h" | 13 | #include "session.h" |
13 | #include "sort.h" | 14 | #include "sort.h" |
14 | #include "symbol.h" | 15 | #include "symbol.h" |
@@ -680,16 +681,18 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *hists | |||
680 | struct ui_progress *progress; | 681 | struct ui_progress *progress; |
681 | struct rb_node *nd; | 682 | struct rb_node *nd; |
682 | u64 curr_hist = 0; | 683 | u64 curr_hist = 0; |
683 | char seq[] = "."; | 684 | char seq[] = ".", unit; |
684 | char str[256]; | 685 | char str[256]; |
686 | unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE]; | ||
685 | 687 | ||
686 | if (self->form) { | 688 | if (self->form) { |
687 | newtFormDestroy(self->form); | 689 | newtFormDestroy(self->form); |
688 | newtPopWindow(); | 690 | newtPopWindow(); |
689 | } | 691 | } |
690 | 692 | ||
691 | snprintf(str, sizeof(str), "Samples: %Ld ", | 693 | nr_events = convert_unit(nr_events, &unit); |
692 | hists->stats.total); | 694 | snprintf(str, sizeof(str), "Events: %lu%c ", |
695 | nr_events, unit); | ||
693 | newtDrawRootText(0, 0, str); | 696 | newtDrawRootText(0, 0, str); |
694 | 697 | ||
695 | newtGetScreenSize(NULL, &rows); | 698 | newtGetScreenSize(NULL, &rows); |
@@ -718,12 +721,12 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *hists | |||
718 | if (h->filtered) | 721 | if (h->filtered) |
719 | continue; | 722 | continue; |
720 | 723 | ||
721 | len = hist_entry__append_browser(h, self->tree, hists->stats.total); | 724 | len = hist_entry__append_browser(h, self->tree, hists->stats.total_period); |
722 | if (len > max_len) | 725 | if (len > max_len) |
723 | max_len = len; | 726 | max_len = len; |
724 | if (symbol_conf.use_callchain) | 727 | if (symbol_conf.use_callchain) |
725 | hist_entry__append_callchain_browser(h, self->tree, | 728 | hist_entry__append_callchain_browser(h, self->tree, |
726 | hists->stats.total, idx++); | 729 | hists->stats.total_period, idx++); |
727 | ++curr_hist; | 730 | ++curr_hist; |
728 | if (curr_hist % 5) | 731 | if (curr_hist % 5) |
729 | ui_progress__update(progress, curr_hist); | 732 | ui_progress__update(progress, curr_hist); |
@@ -748,6 +751,7 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *hists | |||
748 | newtFormAddHotKey(self->form, 'A'); | 751 | newtFormAddHotKey(self->form, 'A'); |
749 | newtFormAddHotKey(self->form, 'a'); | 752 | newtFormAddHotKey(self->form, 'a'); |
750 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | 753 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); |
754 | newtFormAddHotKey(self->form, NEWT_KEY_LEFT); | ||
751 | newtFormAddComponents(self->form, self->tree, NULL); | 755 | newtFormAddComponents(self->form, self->tree, NULL); |
752 | self->selection = newt__symbol_tree_get_current(self->tree); | 756 | self->selection = newt__symbol_tree_get_current(self->tree); |
753 | 757 | ||
@@ -799,6 +803,7 @@ static int hist_browser__title(char *bf, size_t size, const char *input_name, | |||
799 | int hists__browse(struct hists *self, const char *helpline, const char *input_name) | 803 | int hists__browse(struct hists *self, const char *helpline, const char *input_name) |
800 | { | 804 | { |
801 | struct hist_browser *browser = hist_browser__new(); | 805 | struct hist_browser *browser = hist_browser__new(); |
806 | struct pstack *fstack = pstack__new(2); | ||
802 | const struct thread *thread_filter = NULL; | 807 | const struct thread *thread_filter = NULL; |
803 | const struct dso *dso_filter = NULL; | 808 | const struct dso *dso_filter = NULL; |
804 | struct newtExitStruct es; | 809 | struct newtExitStruct es; |
@@ -808,12 +813,16 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
808 | if (browser == NULL) | 813 | if (browser == NULL) |
809 | return -1; | 814 | return -1; |
810 | 815 | ||
816 | fstack = pstack__new(2); | ||
817 | if (fstack == NULL) | ||
818 | goto out; | ||
819 | |||
811 | ui_helpline__push(helpline); | 820 | ui_helpline__push(helpline); |
812 | 821 | ||
813 | hist_browser__title(msg, sizeof(msg), input_name, | 822 | hist_browser__title(msg, sizeof(msg), input_name, |
814 | dso_filter, thread_filter); | 823 | dso_filter, thread_filter); |
815 | if (hist_browser__populate(browser, self, msg) < 0) | 824 | if (hist_browser__populate(browser, self, msg) < 0) |
816 | goto out; | 825 | goto out_free_stack; |
817 | 826 | ||
818 | while (1) { | 827 | while (1) { |
819 | const struct thread *thread; | 828 | const struct thread *thread; |
@@ -834,6 +843,19 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
834 | else | 843 | else |
835 | continue; | 844 | continue; |
836 | } | 845 | } |
846 | |||
847 | if (es.u.key == NEWT_KEY_LEFT) { | ||
848 | const void *top; | ||
849 | |||
850 | if (pstack__empty(fstack)) | ||
851 | continue; | ||
852 | top = pstack__pop(fstack); | ||
853 | if (top == &dso_filter) | ||
854 | goto zoom_out_dso; | ||
855 | if (top == &thread_filter) | ||
856 | goto zoom_out_thread; | ||
857 | continue; | ||
858 | } | ||
837 | } | 859 | } |
838 | 860 | ||
839 | if (browser->selection->sym != NULL && | 861 | if (browser->selection->sym != NULL && |
@@ -886,12 +908,15 @@ do_annotate: | |||
886 | hist_entry__annotate_browser(he); | 908 | hist_entry__annotate_browser(he); |
887 | } else if (choice == zoom_dso) { | 909 | } else if (choice == zoom_dso) { |
888 | if (dso_filter) { | 910 | if (dso_filter) { |
911 | pstack__remove(fstack, &dso_filter); | ||
912 | zoom_out_dso: | ||
889 | ui_helpline__pop(); | 913 | ui_helpline__pop(); |
890 | dso_filter = NULL; | 914 | dso_filter = NULL; |
891 | } else { | 915 | } else { |
892 | ui_helpline__fpush("To zoom out press -> + \"Zoom out of %s DSO\"", | 916 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", |
893 | dso->kernel ? "the Kernel" : dso->short_name); | 917 | dso->kernel ? "the Kernel" : dso->short_name); |
894 | dso_filter = dso; | 918 | dso_filter = dso; |
919 | pstack__push(fstack, &dso_filter); | ||
895 | } | 920 | } |
896 | hists__filter_by_dso(self, dso_filter); | 921 | hists__filter_by_dso(self, dso_filter); |
897 | hist_browser__title(msg, sizeof(msg), input_name, | 922 | hist_browser__title(msg, sizeof(msg), input_name, |
@@ -900,13 +925,16 @@ do_annotate: | |||
900 | goto out; | 925 | goto out; |
901 | } else if (choice == zoom_thread) { | 926 | } else if (choice == zoom_thread) { |
902 | if (thread_filter) { | 927 | if (thread_filter) { |
928 | pstack__remove(fstack, &thread_filter); | ||
929 | zoom_out_thread: | ||
903 | ui_helpline__pop(); | 930 | ui_helpline__pop(); |
904 | thread_filter = NULL; | 931 | thread_filter = NULL; |
905 | } else { | 932 | } else { |
906 | ui_helpline__fpush("To zoom out press -> + \"Zoom out of %s(%d) thread\"", | 933 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", |
907 | thread->comm_set ? thread->comm : "", | 934 | thread->comm_set ? thread->comm : "", |
908 | thread->pid); | 935 | thread->pid); |
909 | thread_filter = thread; | 936 | thread_filter = thread; |
937 | pstack__push(fstack, &thread_filter); | ||
910 | } | 938 | } |
911 | hists__filter_by_thread(self, thread_filter); | 939 | hists__filter_by_thread(self, thread_filter); |
912 | hist_browser__title(msg, sizeof(msg), input_name, | 940 | hist_browser__title(msg, sizeof(msg), input_name, |
@@ -916,6 +944,8 @@ do_annotate: | |||
916 | } | 944 | } |
917 | } | 945 | } |
918 | err = 0; | 946 | err = 0; |
947 | out_free_stack: | ||
948 | pstack__delete(fstack); | ||
919 | out: | 949 | out: |
920 | hist_browser__delete(browser); | 950 | hist_browser__delete(browser); |
921 | return err; | 951 | return err; |
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c new file mode 100644 index 000000000000..13d36faf64eb --- /dev/null +++ b/tools/perf/util/pstack.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * Simple pointer stack | ||
3 | * | ||
4 | * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com> | ||
5 | */ | ||
6 | |||
7 | #include "util.h" | ||
8 | #include "pstack.h" | ||
9 | #include <linux/kernel.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | struct pstack { | ||
13 | unsigned short top; | ||
14 | unsigned short max_nr_entries; | ||
15 | void *entries[0]; | ||
16 | }; | ||
17 | |||
18 | struct pstack *pstack__new(unsigned short max_nr_entries) | ||
19 | { | ||
20 | struct pstack *self = zalloc((sizeof(*self) + | ||
21 | max_nr_entries * sizeof(void *))); | ||
22 | if (self != NULL) | ||
23 | self->max_nr_entries = max_nr_entries; | ||
24 | return self; | ||
25 | } | ||
26 | |||
27 | void pstack__delete(struct pstack *self) | ||
28 | { | ||
29 | free(self); | ||
30 | } | ||
31 | |||
32 | bool pstack__empty(const struct pstack *self) | ||
33 | { | ||
34 | return self->top == 0; | ||
35 | } | ||
36 | |||
37 | void pstack__remove(struct pstack *self, void *key) | ||
38 | { | ||
39 | unsigned short i = self->top, last_index = self->top - 1; | ||
40 | |||
41 | while (i-- != 0) { | ||
42 | if (self->entries[i] == key) { | ||
43 | if (i < last_index) | ||
44 | memmove(self->entries + i, | ||
45 | self->entries + i + 1, | ||
46 | (last_index - i) * sizeof(void *)); | ||
47 | --self->top; | ||
48 | return; | ||
49 | } | ||
50 | } | ||
51 | pr_err("%s: %p not on the pstack!\n", __func__, key); | ||
52 | } | ||
53 | |||
54 | void pstack__push(struct pstack *self, void *key) | ||
55 | { | ||
56 | if (self->top == self->max_nr_entries) { | ||
57 | pr_err("%s: top=%d, overflow!\n", __func__, self->top); | ||
58 | return; | ||
59 | } | ||
60 | self->entries[self->top++] = key; | ||
61 | } | ||
62 | |||
63 | void *pstack__pop(struct pstack *self) | ||
64 | { | ||
65 | void *ret; | ||
66 | |||
67 | if (self->top == 0) { | ||
68 | pr_err("%s: underflow!\n", __func__); | ||
69 | return NULL; | ||
70 | } | ||
71 | |||
72 | ret = self->entries[--self->top]; | ||
73 | self->entries[self->top] = NULL; | ||
74 | return ret; | ||
75 | } | ||
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h new file mode 100644 index 000000000000..5ad07023504b --- /dev/null +++ b/tools/perf/util/pstack.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #ifndef _PERF_PSTACK_ | ||
2 | #define _PERF_PSTACK_ | ||
3 | |||
4 | struct pstack; | ||
5 | struct pstack *pstack__new(unsigned short max_nr_entries); | ||
6 | void pstack__delete(struct pstack *self); | ||
7 | bool pstack__empty(const struct pstack *self); | ||
8 | void pstack__remove(struct pstack *self, void *key); | ||
9 | void pstack__push(struct pstack *self, void *key); | ||
10 | void *pstack__pop(struct pstack *self); | ||
11 | |||
12 | #endif /* _PERF_PSTACK_ */ | ||
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 72a7f6ae0293..25bfca4f10f0 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -94,7 +94,6 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc | |||
94 | self->mmap_window = 32; | 94 | self->mmap_window = 32; |
95 | self->cwd = NULL; | 95 | self->cwd = NULL; |
96 | self->cwdlen = 0; | 96 | self->cwdlen = 0; |
97 | self->unknown_events = 0; | ||
98 | self->machines = RB_ROOT; | 97 | self->machines = RB_ROOT; |
99 | self->repipe = repipe; | 98 | self->repipe = repipe; |
100 | INIT_LIST_HEAD(&self->ordered_samples.samples_head); | 99 | INIT_LIST_HEAD(&self->ordered_samples.samples_head); |
@@ -241,36 +240,6 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | |||
241 | } | 240 | } |
242 | } | 241 | } |
243 | 242 | ||
244 | static const char *event__name[] = { | ||
245 | [0] = "TOTAL", | ||
246 | [PERF_RECORD_MMAP] = "MMAP", | ||
247 | [PERF_RECORD_LOST] = "LOST", | ||
248 | [PERF_RECORD_COMM] = "COMM", | ||
249 | [PERF_RECORD_EXIT] = "EXIT", | ||
250 | [PERF_RECORD_THROTTLE] = "THROTTLE", | ||
251 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", | ||
252 | [PERF_RECORD_FORK] = "FORK", | ||
253 | [PERF_RECORD_READ] = "READ", | ||
254 | [PERF_RECORD_SAMPLE] = "SAMPLE", | ||
255 | [PERF_RECORD_HEADER_ATTR] = "ATTR", | ||
256 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", | ||
257 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", | ||
258 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", | ||
259 | }; | ||
260 | |||
261 | unsigned long event__total[PERF_RECORD_HEADER_MAX]; | ||
262 | |||
263 | void event__print_totals(void) | ||
264 | { | ||
265 | int i; | ||
266 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { | ||
267 | if (!event__name[i]) | ||
268 | continue; | ||
269 | pr_info("%10s events: %10ld\n", | ||
270 | event__name[i], event__total[i]); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | void mem_bswap_64(void *src, int byte_size) | 243 | void mem_bswap_64(void *src, int byte_size) |
275 | { | 244 | { |
276 | u64 *m = src; | 245 | u64 *m = src; |
@@ -580,8 +549,7 @@ static int perf_session__process_event(struct perf_session *self, | |||
580 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 549 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
581 | offset + head, event->header.size, | 550 | offset + head, event->header.size, |
582 | event__name[event->header.type]); | 551 | event__name[event->header.type]); |
583 | ++event__total[0]; | 552 | hists__inc_nr_events(&self->hists, event->header.type); |
584 | ++event__total[event->header.type]; | ||
585 | } | 553 | } |
586 | 554 | ||
587 | if (self->header.needs_swap && event__swap_ops[event->header.type]) | 555 | if (self->header.needs_swap && event__swap_ops[event->header.type]) |
@@ -619,7 +587,7 @@ static int perf_session__process_event(struct perf_session *self, | |||
619 | case PERF_RECORD_FINISHED_ROUND: | 587 | case PERF_RECORD_FINISHED_ROUND: |
620 | return ops->finished_round(event, self, ops); | 588 | return ops->finished_round(event, self, ops); |
621 | default: | 589 | default: |
622 | self->unknown_events++; | 590 | ++self->hists.stats.nr_unknown_events; |
623 | return -1; | 591 | return -1; |
624 | } | 592 | } |
625 | } | 593 | } |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index ce00fa6cdeda..e7fce486ebe2 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -30,8 +30,6 @@ struct perf_session { | |||
30 | struct machine host_machine; | 30 | struct machine host_machine; |
31 | struct rb_root machines; | 31 | struct rb_root machines; |
32 | struct rb_root hists_tree; | 32 | struct rb_root hists_tree; |
33 | unsigned long event_total[PERF_RECORD_MAX]; | ||
34 | unsigned long unknown_events; | ||
35 | /* | 33 | /* |
36 | * FIXME: should point to the first entry in hists_tree and | 34 | * FIXME: should point to the first entry in hists_tree and |
37 | * be a hists instance. Right now its only 'report' | 35 | * be a hists instance. Right now its only 'report' |
@@ -140,4 +138,10 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | |||
140 | { | 138 | { |
141 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); | 139 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
142 | } | 140 | } |
141 | |||
142 | static inline | ||
143 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) | ||
144 | { | ||
145 | return hists__fprintf_nr_events(&self->hists, fp); | ||
146 | } | ||
143 | #endif /* __PERF_SESSION_H */ | 147 | #endif /* __PERF_SESSION_H */ |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index af301acc461c..eab2e0b3b74e 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -43,14 +43,15 @@ extern enum sort_type sort__first_dimension; | |||
43 | 43 | ||
44 | struct hist_entry { | 44 | struct hist_entry { |
45 | struct rb_node rb_node; | 45 | struct rb_node rb_node; |
46 | u64 count; | 46 | u64 period; |
47 | u64 count_sys; | 47 | u64 period_sys; |
48 | u64 count_us; | 48 | u64 period_us; |
49 | u64 count_guest_sys; | 49 | u64 period_guest_sys; |
50 | u64 count_guest_us; | 50 | u64 period_guest_us; |
51 | struct map_symbol ms; | 51 | struct map_symbol ms; |
52 | struct thread *thread; | 52 | struct thread *thread; |
53 | u64 ip; | 53 | u64 ip; |
54 | u32 nr_events; | ||
54 | char level; | 55 | char level; |
55 | u8 filtered; | 56 | u8 filtered; |
56 | struct symbol *parent; | 57 | struct symbol *parent; |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index f9b890fde681..214265674ddd 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -92,3 +92,25 @@ out_close_from: | |||
92 | out: | 92 | out: |
93 | return err; | 93 | return err; |
94 | } | 94 | } |
95 | |||
96 | unsigned long convert_unit(unsigned long value, char *unit) | ||
97 | { | ||
98 | *unit = ' '; | ||
99 | |||
100 | if (value > 1000) { | ||
101 | value /= 1000; | ||
102 | *unit = 'K'; | ||
103 | } | ||
104 | |||
105 | if (value > 1000) { | ||
106 | value /= 1000; | ||
107 | *unit = 'M'; | ||
108 | } | ||
109 | |||
110 | if (value > 1000) { | ||
111 | value /= 1000; | ||
112 | *unit = 'G'; | ||
113 | } | ||
114 | |||
115 | return value; | ||
116 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index fbf45d1b26f7..0795bf304b19 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -423,6 +423,7 @@ char **argv_split(const char *str, int *argcp); | |||
423 | void argv_free(char **argv); | 423 | void argv_free(char **argv); |
424 | bool strglobmatch(const char *str, const char *pat); | 424 | bool strglobmatch(const char *str, const char *pat); |
425 | bool strlazymatch(const char *str, const char *pat); | 425 | bool strlazymatch(const char *str, const char *pat); |
426 | unsigned long convert_unit(unsigned long value, char *unit); | ||
426 | 427 | ||
427 | #define _STR(x) #x | 428 | #define _STR(x) #x |
428 | #define STR(x) _STR(x) | 429 | #define STR(x) _STR(x) |