Skip to content

Commit

Permalink
perf session: Parse sample earlier
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnaldo Carvalho de Melo committed Dec 5, 2010
1 parent c980d10 commit 640c03c
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 192 deletions.
6 changes: 3 additions & 3 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ static int hists__add_entry(struct hists *self, struct addr_location *al)
return hist_entry__inc_addr_samples(he, al->addr);
}

static int process_sample_event(event_t *event, struct perf_session *session)
static int process_sample_event(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct addr_location al;
struct sample_data data;

if (event__preprocess_sample(event, session, &al, &data, NULL) < 0) {
if (event__preprocess_sample(event, session, &al, sample, NULL) < 0) {
pr_warning("problem processing %d event, skipping it.\n",
event->header.type);
return -1;
Expand Down
11 changes: 6 additions & 5 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ static int hists__add_entry(struct hists *self,
return -ENOMEM;
}

static int diff__process_sample_event(event_t *event, struct perf_session *session)
static int diff__process_sample_event(event_t *event,
struct sample_data *sample,
struct perf_session *session)
{
struct addr_location al;
struct sample_data data = { .period = 1, };

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

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

session->hists.stats.total_period += data.period;
session->hists.stats.total_period += sample->period;
return 0;
}

Expand Down
39 changes: 24 additions & 15 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
static char const *input_name = "-";
static bool inject_build_ids;

static int event__repipe(event_t *event __used,
struct perf_session *session __used)
static int event__repipe_synth(event_t *event,
struct perf_session *session __used)
{
uint32_t size;
void *buf = event;
Expand All @@ -36,22 +36,30 @@ static int event__repipe(event_t *event __used,
return 0;
}

static int event__repipe_mmap(event_t *self, struct perf_session *session)
static int event__repipe(event_t *event, struct sample_data *sample __used,
struct perf_session *session)
{
return event__repipe_synth(event, session);
}

static int event__repipe_mmap(event_t *self, struct sample_data *sample,
struct perf_session *session)
{
int err;

err = event__process_mmap(self, session);
event__repipe(self, session);
err = event__process_mmap(self, sample, session);
event__repipe(self, sample, session);

return err;
}

static int event__repipe_task(event_t *self, struct perf_session *session)
static int event__repipe_task(event_t *self, struct sample_data *sample,
struct perf_session *session)
{
int err;

err = event__process_task(self, session);
event__repipe(self, session);
err = event__process_task(self, sample, session);
event__repipe(self, sample, session);

return err;
}
Expand All @@ -61,7 +69,7 @@ static int event__repipe_tracing_data(event_t *self,
{
int err;

event__repipe(self, session);
event__repipe_synth(self, session);
err = event__process_tracing_data(self, session);

return err;
Expand Down Expand Up @@ -111,7 +119,8 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
return 0;
}

static int event__inject_buildid(event_t *event, struct perf_session *session)
static int event__inject_buildid(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct addr_location al;
struct thread *thread;
Expand Down Expand Up @@ -146,7 +155,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
}

repipe:
event__repipe(event, session);
event__repipe(event, sample, session);
return 0;
}

Expand All @@ -160,10 +169,10 @@ struct perf_event_ops inject_ops = {
.read = event__repipe,
.throttle = event__repipe,
.unthrottle = event__repipe,
.attr = event__repipe,
.event_type = event__repipe,
.tracing_data = event__repipe,
.build_id = event__repipe,
.attr = event__repipe_synth,
.event_type = event__repipe_synth,
.tracing_data = event__repipe_synth,
.build_id = event__repipe_synth,
};

extern volatile int session_done;
Expand Down
21 changes: 5 additions & 16 deletions tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,22 +304,11 @@ process_raw_event(event_t *raw_event __used, void *data,
}
}

static int process_sample_event(event_t *event, struct perf_session *session)
static int process_sample_event(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct sample_data data;
struct thread *thread;
struct thread *thread = perf_session__findnew(session, event->ip.pid);

memset(&data, 0, sizeof(data));
data.time = -1;
data.cpu = -1;
data.period = 1;

event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
data.pid, data.tid, data.ip, data.period);

thread = perf_session__findnew(session, event->ip.pid);
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
event->header.type);
Expand All @@ -328,8 +317,8 @@ static int process_sample_event(event_t *event, struct perf_session *session)

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

process_raw_event(event, data.raw_data, data.cpu,
data.time, thread);
process_raw_event(event, sample->raw_data, sample->cpu,
sample->time, thread);

return 0;
}
Expand Down
12 changes: 4 additions & 8 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,22 +834,18 @@ static void dump_info(void)
die("Unknown type of information\n");
}

static int process_sample_event(event_t *self, struct perf_session *s)
static int process_sample_event(event_t *self, struct sample_data *sample,
struct perf_session *s)
{
struct sample_data data;
struct thread *thread;
struct thread *thread = perf_session__findnew(s, sample->tid);

bzero(&data, sizeof(data));
event__parse_sample(self, s->sample_type, &data);

thread = perf_session__findnew(s, data.tid);
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
self->header.type);
return -1;
}

process_raw_event(data.raw_data, data.cpu, data.time, thread);
process_raw_event(sample->raw_data, sample->cpu, sample->time, thread);

return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static int *fd[MAX_NR_CPUS][MAX_COUNTERS];

static u64 user_interval = ULLONG_MAX;
static u64 default_interval = 0;
static u64 sample_type;

static int nr_cpus = 0;
static unsigned int page_size;
Expand Down Expand Up @@ -129,6 +130,7 @@ static void write_output(void *buf, size_t size)
}

static int process_synthesized_event(event_t *event,
struct sample_data *sample __used,
struct perf_session *self __used)
{
write_output(event, event->header.size);
Expand Down Expand Up @@ -287,6 +289,9 @@ static void create_counter(int counter, int cpu)
attr->sample_type |= PERF_SAMPLE_CPU;
}

if (!sample_type)
sample_type = attr->sample_type;

attr->mmap = track;
attr->comm = track;
attr->inherit = !no_inherit;
Expand Down Expand Up @@ -642,6 +647,8 @@ static int __cmd_record(int argc, const char **argv)
open_counters(cpumap[i]);
}

perf_session__set_sample_type(session, sample_type);

if (pipe_output) {
err = perf_header__write_pipe(output);
if (err < 0)
Expand Down
15 changes: 8 additions & 7 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ static int add_event_total(struct perf_session *session,
return 0;
}

static int process_sample_event(event_t *event, struct perf_session *session)
static int process_sample_event(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct sample_data data = { .period = 1, };
struct addr_location al;
struct perf_event_attr *attr;

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

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

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

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

return 0;
}

static int process_read_event(event_t *event, struct perf_session *session __used)
static int process_read_event(event_t *event, struct sample_data *sample __used,
struct perf_session *session __used)
{
struct perf_event_attr *attr;

Expand Down
21 changes: 6 additions & 15 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1606,25 +1606,15 @@ process_raw_event(event_t *raw_event __used, struct perf_session *session,
process_sched_migrate_task_event(data, session, event, cpu, timestamp, thread);
}

static int process_sample_event(event_t *event, struct perf_session *session)
static int process_sample_event(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct sample_data data;
struct thread *thread;

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

memset(&data, 0, sizeof(data));
data.time = -1;
data.cpu = -1;
data.period = -1;

event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
data.pid, data.tid, data.ip, data.period);

thread = perf_session__findnew(session, data.pid);
thread = perf_session__findnew(session, sample->pid);
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
event->header.type);
Expand All @@ -1633,10 +1623,11 @@ static int process_sample_event(event_t *event, struct perf_session *session)

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

if (profile_cpu != -1 && profile_cpu != (int)data.cpu)
if (profile_cpu != -1 && profile_cpu != (int)sample->cpu)
return 0;

process_raw_event(event, session, data.raw_data, data.cpu, data.time, thread);
process_raw_event(event, session, sample->raw_data, sample->cpu,
sample->time, thread);

return 0;
}
Expand Down
34 changes: 12 additions & 22 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,11 @@ static int cleanup_scripting(void)

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

static int process_sample_event(event_t *event, struct perf_session *session)
static int process_sample_event(event_t *event, struct sample_data *sample,
struct perf_session *session)
{
struct sample_data data;
struct thread *thread;
struct thread *thread = perf_session__findnew(session, event->ip.pid);

memset(&data, 0, sizeof(data));
data.time = -1;
data.cpu = -1;
data.period = 1;

event__parse_sample(event, session->sample_type, &data);

dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc,
data.pid, data.tid, data.ip, data.period);

thread = perf_session__findnew(session, event->ip.pid);
if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
event->header.type);
Expand All @@ -87,32 +76,33 @@ static int process_sample_event(event_t *event, struct perf_session *session)

if (session->sample_type & PERF_SAMPLE_RAW) {
if (debug_mode) {
if (data.time < last_timestamp) {
if (sample->time < last_timestamp) {
pr_err("Samples misordered, previous: %llu "
"this: %llu\n", last_timestamp,
data.time);
sample->time);
nr_unordered++;
}
last_timestamp = data.time;
last_timestamp = sample->time;
return 0;
}
/*
* FIXME: better resolve from pid from the struct trace_entry
* field, although it should be the same than this perf
* event pid
*/
scripting_ops->process_event(data.cpu, data.raw_data,
data.raw_size,
data.time, thread->comm);
scripting_ops->process_event(sample->cpu, sample->raw_data,
sample->raw_size,
sample->time, thread->comm);
}

session->hists.stats.total_period += data.period;
session->hists.stats.total_period += sample->period;
return 0;
}

static u64 nr_lost;

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

Expand Down
Loading

0 comments on commit 640c03c

Please sign in to comment.