Skip to content

Commit e248de3

Browse files
committed
perf tools: Improve support for sessions with multiple events
By creating an perf_evlist out of the attributes in the perf.data file header, so that we can use evlists and evsels when reading recorded sessions in addition to when we record sessions. More work is needed to allow tools to allow the user to select which events are wanted when browsing sessions, be it just one or a subset of them, aggregated or showed at the same time but with different indications on the UI to allow seeing workloads thru different views at the same time. But the overall goal/trend is to more uniformly use evsels and evlists. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3d3b5e9 commit e248de3

10 files changed

Lines changed: 208 additions & 196 deletions

File tree

‎tools/perf/builtin-annotate.c‎

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "perf.h"
2020
#include "util/debug.h"
2121

22+
#include "util/evlist.h"
23+
#include "util/evsel.h"
2224
#include "util/annotate.h"
2325
#include "util/event.h"
2426
#include "util/parse-options.h"
@@ -38,9 +40,13 @@ static bool print_line;
3840

3941
static const char *sym_hist_filter;
4042

41-
static int hists__add_entry(struct hists *self, struct addr_location *al)
43+
static int perf_evlist__add_sample(struct perf_evlist *evlist,
44+
struct perf_sample *sample,
45+
struct addr_location *al)
4246
{
47+
struct perf_evsel *evsel;
4348
struct hist_entry *he;
49+
int ret;
4450

4551
if (sym_hist_filter != NULL &&
4652
(al->sym == NULL || strcmp(sym_hist_filter, al->sym->name) != 0)) {
@@ -53,23 +59,35 @@ static int hists__add_entry(struct hists *self, struct addr_location *al)
5359
return 0;
5460
}
5561

56-
he = __hists__add_entry(self, al, NULL, 1);
62+
evsel = perf_evlist__id2evsel(evlist, sample->id);
63+
if (evsel == NULL) {
64+
/*
65+
* FIXME: Propagate this back, but at least we're in a builtin,
66+
* where exit() is allowed. ;-)
67+
*/
68+
ui__warning("Invalid %s file, contains samples with id not in "
69+
"its header!\n", input_name);
70+
exit_browser(0);
71+
exit(1);
72+
}
73+
74+
he = __hists__add_entry(&evsel->hists, al, NULL, 1);
5775
if (he == NULL)
5876
return -ENOMEM;
5977

78+
ret = 0;
6079
if (he->ms.sym != NULL) {
61-
/*
62-
* All aggregated on the first sym_hist.
63-
*/
6480
struct annotation *notes = symbol__annotation(he->ms.sym);
6581
if (notes->src == NULL &&
66-
symbol__alloc_hist(he->ms.sym, 1) < 0)
82+
symbol__alloc_hist(he->ms.sym, evlist->nr_entries) < 0)
6783
return -ENOMEM;
6884

69-
return hist_entry__inc_addr_samples(he, 0, al->addr);
85+
ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
7086
}
7187

72-
return 0;
88+
evsel->hists.stats.total_period += sample->period;
89+
hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
90+
return ret;
7391
}
7492

7593
static int process_sample_event(union perf_event *event,
@@ -85,7 +103,7 @@ static int process_sample_event(union perf_event *event,
85103
return -1;
86104
}
87105

88-
if (!al.filtered && hists__add_entry(&session->hists, &al)) {
106+
if (!al.filtered && perf_evlist__add_sample(session->evlist, sample, &al)) {
89107
pr_warning("problem incrementing symbol count, "
90108
"skipping event\n");
91109
return -1;
@@ -100,7 +118,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he, int evidx)
100118
print_line, full_paths, 0, 0);
101119
}
102120

103-
static void hists__find_annotations(struct hists *self)
121+
static void hists__find_annotations(struct hists *self, int evidx)
104122
{
105123
struct rb_node *nd = rb_first(&self->entries), *next;
106124
int key = KEY_RIGHT;
@@ -123,8 +141,7 @@ static void hists__find_annotations(struct hists *self)
123141
}
124142

125143
if (use_browser > 0) {
126-
/* For now all is aggregated on the first */
127-
key = hist_entry__tui_annotate(he, 0);
144+
key = hist_entry__tui_annotate(he, evidx);
128145
switch (key) {
129146
case KEY_RIGHT:
130147
next = rb_next(nd);
@@ -139,8 +156,7 @@ static void hists__find_annotations(struct hists *self)
139156
if (next != NULL)
140157
nd = next;
141158
} else {
142-
/* For now all is aggregated on the first */
143-
hist_entry__tty_annotate(he, 0);
159+
hist_entry__tty_annotate(he, evidx);
144160
nd = rb_next(nd);
145161
/*
146162
* Since we have a hist_entry per IP for the same
@@ -166,6 +182,8 @@ static int __cmd_annotate(void)
166182
{
167183
int ret;
168184
struct perf_session *session;
185+
struct perf_evsel *pos;
186+
u64 total_nr_samples;
169187

170188
session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
171189
if (session == NULL)
@@ -186,12 +204,36 @@ static int __cmd_annotate(void)
186204
if (verbose > 2)
187205
perf_session__fprintf_dsos(session, stdout);
188206

189-
hists__collapse_resort(&session->hists);
190-
hists__output_resort(&session->hists);
191-
hists__find_annotations(&session->hists);
192-
out_delete:
193-
perf_session__delete(session);
207+
total_nr_samples = 0;
208+
list_for_each_entry(pos, &session->evlist->entries, node) {
209+
struct hists *hists = &pos->hists;
210+
u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
211+
212+
if (nr_samples > 0) {
213+
total_nr_samples += nr_samples;
214+
hists__collapse_resort(hists);
215+
hists__output_resort(hists);
216+
hists__find_annotations(hists, pos->idx);
217+
}
218+
}
194219

220+
if (total_nr_samples == 0) {
221+
ui__warning("The %s file has no samples!\n", input_name);
222+
goto out_delete;
223+
}
224+
out_delete:
225+
/*
226+
* Speed up the exit process, for large files this can
227+
* take quite a while.
228+
*
229+
* XXX Enable this when using valgrind or if we ever
230+
* librarize this command.
231+
*
232+
* Also experiment with obstacks to see how much speed
233+
* up we'll get here.
234+
*
235+
* perf_session__delete(session);
236+
*/
195237
return ret;
196238
}
197239

0 commit comments

Comments
 (0)