Skip to content

Commit

Permalink
perf tools: Resolve machine earlier and pass it to perf_event_ops
Browse files Browse the repository at this point in the history
Reducing the exposure of perf_session further, so that we can use the
classes in cases where no perf.data file is created.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-stua66dcscsezzrcdugvbmvd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Nov 28, 2011
1 parent d20deb6 commit 743eb86
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 375 deletions.
4 changes: 2 additions & 2 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ static int process_sample_event(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct perf_session *session)
struct machine *machine)
{
struct perf_annotate *ann = container_of(ops, struct perf_annotate, ops);
struct addr_location al;

if (perf_event__preprocess_sample(event, session, &al, sample,
if (perf_event__preprocess_sample(event, machine, &al, sample,
symbol__annotate_init) < 0) {
pr_warning("problem processing %d event, skipping it.\n",
event->header.type);
Expand Down
9 changes: 5 additions & 4 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "util/debug.h"
#include "util/event.h"
#include "util/hist.h"
#include "util/evsel.h"
#include "util/session.h"
#include "util/sort.h"
#include "util/symbol.h"
Expand All @@ -34,11 +35,11 @@ static int diff__process_sample_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel __used,
struct perf_session *session)
struct machine *machine)
{
struct addr_location al;

if (perf_event__preprocess_sample(event, session, &al, sample, NULL) < 0) {
if (perf_event__preprocess_sample(event, machine, &al, sample, NULL) < 0) {
pr_warning("problem processing %d event, skipping it.\n",
event->header.type);
return -1;
Expand All @@ -47,12 +48,12 @@ static int diff__process_sample_event(struct perf_event_ops *ops __used,
if (al.filtered || al.sym == NULL)
return 0;

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

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

Expand Down
70 changes: 38 additions & 32 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static bool inject_build_ids;

static int perf_event__repipe_synth(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_session *session __used)
struct machine *machine __used)
{
uint32_t size;
void *buf = event;
Expand All @@ -37,10 +37,23 @@ static int perf_event__repipe_synth(struct perf_event_ops *ops __used,
return 0;
}

static int perf_event__repipe_op2_synth(struct perf_event_ops *ops,
union perf_event *event,
struct perf_session *session __used)
{
return perf_event__repipe_synth(ops, event, NULL);
}

static int perf_event__repipe_event_type_synth(struct perf_event_ops *ops,
union perf_event *event)
{
return perf_event__repipe_synth(ops, event, NULL);
}

static int perf_event__repipe_tracing_data_synth(union perf_event *event,
struct perf_session *session)
struct perf_session *session __used)
{
return perf_event__repipe_synth(NULL, event, session);
return perf_event__repipe_synth(NULL, event, NULL);
}

static int perf_event__repipe_attr(union perf_event *event,
Expand All @@ -52,42 +65,42 @@ static int perf_event__repipe_attr(union perf_event *event,
static int perf_event__repipe(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
struct machine *machine)
{
return perf_event__repipe_synth(ops, event, session);
return perf_event__repipe_synth(ops, event, machine);
}

static int perf_event__repipe_sample(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_evsel *evsel __used,
struct perf_session *session)
struct machine *machine)
{
return perf_event__repipe_synth(ops, event, session);
return perf_event__repipe_synth(ops, event, machine);
}

static int perf_event__repipe_mmap(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session)
struct machine *machine)
{
int err;

err = perf_event__process_mmap(ops, event, sample, session);
perf_event__repipe(ops, event, sample, session);
err = perf_event__process_mmap(ops, event, sample, machine);
perf_event__repipe(ops, event, sample, machine);

return err;
}

static int perf_event__repipe_task(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session)
struct machine *machine)
{
int err;

err = perf_event__process_task(ops, event, sample, session);
perf_event__repipe(ops, event, sample, session);
err = perf_event__process_task(ops, event, sample, machine);
perf_event__repipe(ops, event, sample, machine);

return err;
}
Expand All @@ -97,7 +110,7 @@ static int perf_event__repipe_tracing_data(union perf_event *event,
{
int err;

perf_event__repipe_synth(NULL, event, session);
perf_event__repipe_synth(NULL, event, NULL);
err = perf_event__process_tracing_data(event, session);

return err;
Expand All @@ -118,28 +131,21 @@ static int dso__read_build_id(struct dso *self)
}

static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops,
struct perf_session *session)
struct machine *machine)
{
u16 misc = PERF_RECORD_MISC_USER;
struct machine *machine;
int err;

if (dso__read_build_id(self) < 0) {
pr_debug("no build_id found for %s\n", self->long_name);
return -1;
}

machine = perf_session__find_host_machine(session);
if (machine == NULL) {
pr_err("Can't find machine for session\n");
return -1;
}

if (self->kernel)
misc = PERF_RECORD_MISC_KERNEL;

err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe,
machine, session);
machine);
if (err) {
pr_err("Can't synthesize build_id event for %s\n", self->long_name);
return -1;
Expand All @@ -152,29 +158,29 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel __used,
struct perf_session *session)
struct machine *machine)
{
struct addr_location al;
struct thread *thread;
u8 cpumode;

cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

thread = perf_session__findnew(session, event->ip.pid);
thread = machine__findnew_thread(machine, event->ip.pid);
if (thread == NULL) {
pr_err("problem processing %d event, skipping it.\n",
event->header.type);
goto repipe;
}

thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
event->ip.pid, event->ip.ip, &al);
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
event->ip.ip, &al);

if (al.map != NULL) {
if (!al.map->dso->hit) {
al.map->dso->hit = 1;
if (map__load(al.map, NULL) >= 0) {
dso__inject_build_id(al.map->dso, ops, session);
dso__inject_build_id(al.map->dso, ops, machine);
/*
* If this fails, too bad, let the other side
* account this as unresolved.
Expand All @@ -187,7 +193,7 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops,
}

repipe:
perf_event__repipe(ops, event, sample, session);
perf_event__repipe(ops, event, sample, machine);
return 0;
}

Expand All @@ -198,13 +204,13 @@ struct perf_event_ops inject_ops = {
.fork = perf_event__repipe,
.exit = perf_event__repipe,
.lost = perf_event__repipe,
.read = perf_event__repipe,
.read = perf_event__repipe_sample,
.throttle = perf_event__repipe,
.unthrottle = perf_event__repipe,
.attr = perf_event__repipe_attr,
.event_type = perf_event__repipe_synth,
.event_type = perf_event__repipe_event_type_synth,
.tracing_data = perf_event__repipe_tracing_data_synth,
.build_id = perf_event__repipe_synth,
.build_id = perf_event__repipe_op2_synth,
};

extern volatile int session_done;
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ static int process_sample_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel __used,
struct perf_session *session)
struct machine *machine)
{
struct thread *thread = perf_session__findnew(session, event->ip.pid);
struct thread *thread = machine__findnew_thread(machine, event->ip.pid);

if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,9 @@ static int process_sample_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample,
struct perf_evsel *evsel __used,
struct perf_session *s)
struct machine *machine)
{
struct thread *thread = perf_session__findnew(s, sample->tid);
struct thread *thread = machine__findnew_thread(machine, sample->tid);

if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
Expand Down
38 changes: 17 additions & 21 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void write_output(struct perf_record *rec, void *buf, size_t size)
static int process_synthesized_event(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *self __used)
struct machine *machine __used)
{
struct perf_record *rec = container_of(ops, struct perf_record, ops);
write_output(rec, event, event->header.size);
Expand Down Expand Up @@ -320,8 +320,6 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
{
int err;
struct perf_event_ops *ops = data;
struct perf_record *rec = container_of(ops, struct perf_record, ops);
struct perf_session *psession = rec->session;

if (machine__is_host(machine))
return;
Expand All @@ -335,7 +333,7 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
*in module instead of in guest kernel.
*/
err = perf_event__synthesize_modules(ops, process_synthesized_event,
psession, machine);
machine);
if (err < 0)
pr_err("Couldn't record guest kernel [%d]'s reference"
" relocation symbol.\n", machine->pid);
Expand All @@ -345,11 +343,10 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
* have no _text sometimes.
*/
err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event,
psession, machine, "_text");
machine, "_text");
if (err < 0)
err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event,
psession, machine,
"_stext");
machine, "_stext");
if (err < 0)
pr_err("Couldn't record guest kernel [%d]'s reference"
" relocation symbol.\n", machine->pid);
Expand Down Expand Up @@ -497,6 +494,12 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)

rec->post_processing_offset = lseek(output, 0, SEEK_CUR);

machine = perf_session__find_host_machine(session);
if (!machine) {
pr_err("Couldn't find native kernel information.\n");
return -1;
}

if (opts->pipe_output) {
err = perf_event__synthesize_attrs(ops, session,
process_synthesized_event);
Expand All @@ -506,7 +509,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
}

err = perf_event__synthesize_event_types(ops, process_synthesized_event,
session);
machine);
if (err < 0) {
pr_err("Couldn't synthesize event_types.\n");
return err;
Expand All @@ -522,8 +525,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
* propagate errors that now are calling die()
*/
err = perf_event__synthesize_tracing_data(ops, output, evsel_list,
process_synthesized_event,
session);
process_synthesized_event);
if (err <= 0) {
pr_err("Couldn't record tracing data.\n");
return err;
Expand All @@ -532,24 +534,18 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
}
}

machine = perf_session__find_host_machine(session);
if (!machine) {
pr_err("Couldn't find native kernel information.\n");
return -1;
}

err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event,
session, machine, "_text");
machine, "_text");
if (err < 0)
err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event,
session, machine, "_stext");
machine, "_stext");
if (err < 0)
pr_err("Couldn't record kernel reference relocation symbol\n"
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
"Check /proc/kallsyms permission or run as root.\n");

err = perf_event__synthesize_modules(ops, process_synthesized_event,
session, machine);
machine);
if (err < 0)
pr_err("Couldn't record kernel module information.\n"
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
Expand All @@ -562,10 +558,10 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
if (!opts->system_wide)
perf_event__synthesize_thread_map(ops, evsel_list->threads,
process_synthesized_event,
session);
machine);
else
perf_event__synthesize_threads(ops, process_synthesized_event,
session);
machine);

if (rec->realtime_prio) {
struct sched_param param;
Expand Down
Loading

0 comments on commit 743eb86

Please sign in to comment.