Skip to content

Commit efd5745

Browse files
committed
perf trace: Count number of events for each thread and globally
The nr_events in trace__run was local, but we will need it in other trace methods, move it to struct trace. We'll also need the number of events per thread, so introduce a nr_events method for that in struct thread_trace. Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ba361c9 commit efd5745

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tools/perf/builtin-trace.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct thread_trace {
6767
u64 entry_time;
6868
u64 exit_time;
6969
bool entry_pending;
70+
unsigned long nr_events;
7071
char *entry_str;
7172
};
7273

@@ -77,16 +78,21 @@ static struct thread_trace *thread_trace__new(void)
7778

7879
static struct thread_trace *thread__trace(struct thread *thread)
7980
{
81+
struct thread_trace *ttrace;
82+
8083
if (thread == NULL)
8184
goto fail;
8285

8386
if (thread->priv == NULL)
8487
thread->priv = thread_trace__new();
85-
88+
8689
if (thread->priv == NULL)
8790
goto fail;
8891

89-
return thread->priv;
92+
ttrace = thread->priv;
93+
++ttrace->nr_events;
94+
95+
return ttrace;
9096
fail:
9197
color_fprintf(stdout, PERF_COLOR_RED,
9298
"WARNING: not enough memory, dropping samples!\n");
@@ -102,6 +108,7 @@ struct trace {
102108
struct perf_record_opts opts;
103109
struct machine host;
104110
u64 base_time;
111+
unsigned long nr_events;
105112
bool multiple_threads;
106113
double duration_filter;
107114
};
@@ -386,7 +393,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
386393
{
387394
struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
388395
struct perf_evsel *evsel;
389-
int err = -1, i, nr_events = 0, before;
396+
int err = -1, i;
397+
unsigned long before;
390398
const bool forks = argc > 0;
391399

392400
if (evlist == NULL) {
@@ -444,7 +452,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
444452

445453
trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1;
446454
again:
447-
before = nr_events;
455+
before = trace->nr_events;
448456

449457
for (i = 0; i < evlist->nr_mmaps; i++) {
450458
union perf_event *event;
@@ -454,7 +462,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
454462
tracepoint_handler handler;
455463
struct perf_sample sample;
456464

457-
++nr_events;
465+
++trace->nr_events;
458466

459467
err = perf_evlist__parse_sample(evlist, event, &sample);
460468
if (err) {
@@ -495,7 +503,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
495503
}
496504
}
497505

498-
if (nr_events == before) {
506+
if (trace->nr_events == before) {
499507
if (done)
500508
goto out_delete_evlist;
501509

0 commit comments

Comments
 (0)