Skip to content

Commit 640c03c

Browse files
committed
perf session: Parse sample earlier
At perf_session__process_event, so that we reduce the number of lines in eache tool sample processing routine that now receives a sample_data pointer already parsed. This will also be useful in the next patch, where we'll allow sample the identity fields in MMAP, FORK, EXIT, etc, when it will be possible to see (cpu, timestamp) just after before every event. Also validate callchains in perf_session__process_event, i.e. as early as possible, and keep a counter of the number of events discarded due to invalid callchains, warning the user about it if it happens. There is an assumption that was kept that all events have the same sample_type, that will be dealt with in the future, when this preexisting limitation will be removed. Tested-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Ian Munsie <imunsie@au1.ibm.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Ian Munsie <imunsie@au1.ibm.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Stephane Eranian <eranian@google.com> LKML-Reference: <1291318772-30880-4-git-send-email-acme@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent c980d10 commit 640c03c

18 files changed

Lines changed: 236 additions & 192 deletions

‎tools/perf/builtin-annotate.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ static int hists__add_entry(struct hists *self, struct addr_location *al)
5858
return hist_entry__inc_addr_samples(he, al->addr);
5959
}
6060

61-
static int process_sample_event(event_t *event, struct perf_session *session)
61+
static int process_sample_event(event_t *event, struct sample_data *sample,
62+
struct perf_session *session)
6263
{
6364
struct addr_location al;
64-
struct sample_data data;
6565

66-
if (event__preprocess_sample(event, session, &al, &data, NULL) < 0) {
66+
if (event__preprocess_sample(event, session, &al, sample, NULL) < 0) {
6767
pr_warning("problem processing %d event, skipping it.\n",
6868
event->header.type);
6969
return -1;

‎tools/perf/builtin-diff.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ static int hists__add_entry(struct hists *self,
3030
return -ENOMEM;
3131
}
3232

33-
static int diff__process_sample_event(event_t *event, struct perf_session *session)
33+
static int diff__process_sample_event(event_t *event,
34+
struct sample_data *sample,
35+
struct perf_session *session)
3436
{
3537
struct addr_location al;
36-
struct sample_data data = { .period = 1, };
3738

38-
if (event__preprocess_sample(event, session, &al, &data, NULL) < 0) {
39+
if (event__preprocess_sample(event, session, &al, sample, NULL) < 0) {
3940
pr_warning("problem processing %d event, skipping it.\n",
4041
event->header.type);
4142
return -1;
@@ -44,12 +45,12 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi
4445
if (al.filtered || al.sym == NULL)
4546
return 0;
4647

47-
if (hists__add_entry(&session->hists, &al, data.period)) {
48+
if (hists__add_entry(&session->hists, &al, sample->period)) {
4849
pr_warning("problem incrementing symbol period, skipping event\n");
4950
return -1;
5051
}
5152

52-
session->hists.stats.total_period += data.period;
53+
session->hists.stats.total_period += sample->period;
5354
return 0;
5455
}
5556

‎tools/perf/builtin-inject.c‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
static char const *input_name = "-";
1717
static bool inject_build_ids;
1818

19-
static int event__repipe(event_t *event __used,
20-
struct perf_session *session __used)
19+
static int event__repipe_synth(event_t *event,
20+
struct perf_session *session __used)
2121
{
2222
uint32_t size;
2323
void *buf = event;
@@ -36,22 +36,30 @@ static int event__repipe(event_t *event __used,
3636
return 0;
3737
}
3838

39-
static int event__repipe_mmap(event_t *self, struct perf_session *session)
39+
static int event__repipe(event_t *event, struct sample_data *sample __used,
40+
struct perf_session *session)
41+
{
42+
return event__repipe_synth(event, session);
43+
}
44+
45+
static int event__repipe_mmap(event_t *self, struct sample_data *sample,
46+
struct perf_session *session)
4047
{
4148
int err;
4249

43-
err = event__process_mmap(self, session);
44-
event__repipe(self, session);
50+
err = event__process_mmap(self, sample, session);
51+
event__repipe(self, sample, session);
4552

4653
return err;
4754
}
4855

49-
static int event__repipe_task(event_t *self, struct perf_session *session)
56+
static int event__repipe_task(event_t *self, struct sample_data *sample,
57+
struct perf_session *session)
5058
{
5159
int err;
5260

53-
err = event__process_task(self, session);
54-
event__repipe(self, session);
61+
err = event__process_task(self, sample, session);
62+
event__repipe(self, sample, session);
5563

5664
return err;
5765
}
@@ -61,7 +69,7 @@ static int event__repipe_tracing_data(event_t *self,
6169
{
6270
int err;
6371

64-
event__repipe(self, session);
72+
event__repipe_synth(self, session);
6573
err = event__process_tracing_data(self, session);
6674

6775
return err;
@@ -111,7 +119,8 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
111119
return 0;
112120
}
113121

114-
static int event__inject_buildid(event_t *event, struct perf_session *session)
122+
static int event__inject_buildid(event_t *event, struct sample_data *sample,
123+
struct perf_session *session)
115124
{
116125
struct addr_location al;
117126
struct thread *thread;
@@ -146,7 +155,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
146155
}
147156

148157
repipe:
149-
event__repipe(event, session);
158+
event__repipe(event, sample, session);
150159
return 0;
151160
}
152161

@@ -160,10 +169,10 @@ struct perf_event_ops inject_ops = {
160169
.read = event__repipe,
161170
.throttle = event__repipe,
162171
.unthrottle = event__repipe,
163-
.attr = event__repipe,
164-
.event_type = event__repipe,
165-
.tracing_data = event__repipe,
166-
.build_id = event__repipe,
172+
.attr = event__repipe_synth,
173+
.event_type = event__repipe_synth,
174+
.tracing_data = event__repipe_synth,
175+
.build_id = event__repipe_synth,
167176
};
168177

169178
extern volatile int session_done;

‎tools/perf/builtin-kmem.c‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,22 +304,11 @@ process_raw_event(event_t *raw_event __used, void *data,
304304
}
305305
}
306306

307-
static int process_sample_event(event_t *event, struct perf_session *session)
307+
static int process_sample_event(event_t *event, struct sample_data *sample,
308+
struct perf_session *session)
308309
{
309-
struct sample_data data;
310-
struct thread *thread;
310+
struct thread *thread = perf_session__findnew(session, event->ip.pid);
311311

312-
memset(&data, 0, sizeof(data));
313-
data.time = -1;
314-
data.cpu = -1;
315-
data.period = 1;
316-
317-
event__parse_sample(event, session->sample_type, &data);
318-
319-
dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
320-
data.pid, data.tid, data.ip, data.period);
321-
322-
thread = perf_session__findnew(session, event->ip.pid);
323312
if (thread == NULL) {
324313
pr_debug("problem processing %d event, skipping it.\n",
325314
event->header.type);
@@ -328,8 +317,8 @@ static int process_sample_event(event_t *event, struct perf_session *session)
328317

329318
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
330319

331-
process_raw_event(event, data.raw_data, data.cpu,
332-
data.time, thread);
320+
process_raw_event(event, sample->raw_data, sample->cpu,
321+
sample->time, thread);
333322

334323
return 0;
335324
}

‎tools/perf/builtin-lock.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -834,22 +834,18 @@ static void dump_info(void)
834834
die("Unknown type of information\n");
835835
}
836836

837-
static int process_sample_event(event_t *self, struct perf_session *s)
837+
static int process_sample_event(event_t *self, struct sample_data *sample,
838+
struct perf_session *s)
838839
{
839-
struct sample_data data;
840-
struct thread *thread;
840+
struct thread *thread = perf_session__findnew(s, sample->tid);
841841

842-
bzero(&data, sizeof(data));
843-
event__parse_sample(self, s->sample_type, &data);
844-
845-
thread = perf_session__findnew(s, data.tid);
846842
if (thread == NULL) {
847843
pr_debug("problem processing %d event, skipping it.\n",
848844
self->header.type);
849845
return -1;
850846
}
851847

852-
process_raw_event(data.raw_data, data.cpu, data.time, thread);
848+
process_raw_event(sample->raw_data, sample->cpu, sample->time, thread);
853849

854850
return 0;
855851
}

‎tools/perf/builtin-record.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
3636

3737
static u64 user_interval = ULLONG_MAX;
3838
static u64 default_interval = 0;
39+
static u64 sample_type;
3940

4041
static int nr_cpus = 0;
4142
static unsigned int page_size;
@@ -129,6 +130,7 @@ static void write_output(void *buf, size_t size)
129130
}
130131

131132
static int process_synthesized_event(event_t *event,
133+
struct sample_data *sample __used,
132134
struct perf_session *self __used)
133135
{
134136
write_output(event, event->header.size);
@@ -287,6 +289,9 @@ static void create_counter(int counter, int cpu)
287289
attr->sample_type |= PERF_SAMPLE_CPU;
288290
}
289291

292+
if (!sample_type)
293+
sample_type = attr->sample_type;
294+
290295
attr->mmap = track;
291296
attr->comm = track;
292297
attr->inherit = !no_inherit;
@@ -642,6 +647,8 @@ static int __cmd_record(int argc, const char **argv)
642647
open_counters(cpumap[i]);
643648
}
644649

650+
perf_session__set_sample_type(session, sample_type);
651+
645652
if (pipe_output) {
646653
err = perf_header__write_pipe(output);
647654
if (err < 0)

‎tools/perf/builtin-report.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ static int add_event_total(struct perf_session *session,
150150
return 0;
151151
}
152152

153-
static int process_sample_event(event_t *event, struct perf_session *session)
153+
static int process_sample_event(event_t *event, struct sample_data *sample,
154+
struct perf_session *session)
154155
{
155-
struct sample_data data = { .period = 1, };
156156
struct addr_location al;
157157
struct perf_event_attr *attr;
158158

159-
if (event__preprocess_sample(event, session, &al, &data, NULL) < 0) {
159+
if (event__preprocess_sample(event, session, &al, sample, NULL) < 0) {
160160
fprintf(stderr, "problem processing %d event, skipping it.\n",
161161
event->header.type);
162162
return -1;
@@ -165,22 +165,23 @@ static int process_sample_event(event_t *event, struct perf_session *session)
165165
if (al.filtered || (hide_unresolved && al.sym == NULL))
166166
return 0;
167167

168-
if (perf_session__add_hist_entry(session, &al, &data)) {
168+
if (perf_session__add_hist_entry(session, &al, sample)) {
169169
pr_debug("problem incrementing symbol period, skipping event\n");
170170
return -1;
171171
}
172172

173-
attr = perf_header__find_attr(data.id, &session->header);
173+
attr = perf_header__find_attr(sample->id, &session->header);
174174

175-
if (add_event_total(session, &data, attr)) {
175+
if (add_event_total(session, sample, attr)) {
176176
pr_debug("problem adding event period\n");
177177
return -1;
178178
}
179179

180180
return 0;
181181
}
182182

183-
static int process_read_event(event_t *event, struct perf_session *session __used)
183+
static int process_read_event(event_t *event, struct sample_data *sample __used,
184+
struct perf_session *session __used)
184185
{
185186
struct perf_event_attr *attr;
186187

‎tools/perf/builtin-sched.c‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,25 +1606,15 @@ process_raw_event(event_t *raw_event __used, struct perf_session *session,
16061606
process_sched_migrate_task_event(data, session, event, cpu, timestamp, thread);
16071607
}
16081608

1609-
static int process_sample_event(event_t *event, struct perf_session *session)
1609+
static int process_sample_event(event_t *event, struct sample_data *sample,
1610+
struct perf_session *session)
16101611
{
1611-
struct sample_data data;
16121612
struct thread *thread;
16131613

16141614
if (!(session->sample_type & PERF_SAMPLE_RAW))
16151615
return 0;
16161616

1617-
memset(&data, 0, sizeof(data));
1618-
data.time = -1;
1619-
data.cpu = -1;
1620-
data.period = -1;
1621-
1622-
event__parse_sample(event, session->sample_type, &data);
1623-
1624-
dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
1625-
data.pid, data.tid, data.ip, data.period);
1626-
1627-
thread = perf_session__findnew(session, data.pid);
1617+
thread = perf_session__findnew(session, sample->pid);
16281618
if (thread == NULL) {
16291619
pr_debug("problem processing %d event, skipping it.\n",
16301620
event->header.type);
@@ -1633,10 +1623,11 @@ static int process_sample_event(event_t *event, struct perf_session *session)
16331623

16341624
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
16351625

1636-
if (profile_cpu != -1 && profile_cpu != (int)data.cpu)
1626+
if (profile_cpu != -1 && profile_cpu != (int)sample->cpu)
16371627
return 0;
16381628

1639-
process_raw_event(event, session, data.raw_data, data.cpu, data.time, thread);
1629+
process_raw_event(event, session, sample->raw_data, sample->cpu,
1630+
sample->time, thread);
16401631

16411632
return 0;
16421633
}

‎tools/perf/builtin-script.c‎

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,11 @@ static int cleanup_scripting(void)
6363

6464
static char const *input_name = "perf.data";
6565

66-
static int process_sample_event(event_t *event, struct perf_session *session)
66+
static int process_sample_event(event_t *event, struct sample_data *sample,
67+
struct perf_session *session)
6768
{
68-
struct sample_data data;
69-
struct thread *thread;
69+
struct thread *thread = perf_session__findnew(session, event->ip.pid);
7070

71-
memset(&data, 0, sizeof(data));
72-
data.time = -1;
73-
data.cpu = -1;
74-
data.period = 1;
75-
76-
event__parse_sample(event, session->sample_type, &data);
77-
78-
dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
79-
data.pid, data.tid, data.ip, data.period);
80-
81-
thread = perf_session__findnew(session, event->ip.pid);
8271
if (thread == NULL) {
8372
pr_debug("problem processing %d event, skipping it.\n",
8473
event->header.type);
@@ -87,32 +76,33 @@ static int process_sample_event(event_t *event, struct perf_session *session)
8776

8877
if (session->sample_type & PERF_SAMPLE_RAW) {
8978
if (debug_mode) {
90-
if (data.time < last_timestamp) {
79+
if (sample->time < last_timestamp) {
9180
pr_err("Samples misordered, previous: %llu "
9281
"this: %llu\n", last_timestamp,
93-
data.time);
82+
sample->time);
9483
nr_unordered++;
9584
}
96-
last_timestamp = data.time;
85+
last_timestamp = sample->time;
9786
return 0;
9887
}
9988
/*
10089
* FIXME: better resolve from pid from the struct trace_entry
10190
* field, although it should be the same than this perf
10291
* event pid
10392
*/
104-
scripting_ops->process_event(data.cpu, data.raw_data,
105-
data.raw_size,
106-
data.time, thread->comm);
93+
scripting_ops->process_event(sample->cpu, sample->raw_data,
94+
sample->raw_size,
95+
sample->time, thread->comm);
10796
}
10897

109-
session->hists.stats.total_period += data.period;
98+
session->hists.stats.total_period += sample->period;
11099
return 0;
111100
}
112101

113102
static u64 nr_lost;
114103

115-
static int process_lost_event(event_t *event, struct perf_session *session __used)
104+
static int process_lost_event(event_t *event, struct sample_data *sample __used,
105+
struct perf_session *session __used)
116106
{
117107
nr_lost += event->lost.lost;
118108

0 commit comments

Comments
 (0)