perf script: Stop using pevent directly

We can get all that is needed using just event_format, that is available
via evsel->tp_format now.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
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-2hsr1686epa9f0vx4yg7z2zj@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7f7f8d0b
...@@ -28,11 +28,6 @@ static bool system_wide; ...@@ -28,11 +28,6 @@ static bool system_wide;
static const char *cpu_list; static const char *cpu_list;
static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
struct perf_script {
struct perf_tool tool;
struct perf_session *session;
};
enum perf_output_field { enum perf_output_field {
PERF_OUTPUT_COMM = 1U << 0, PERF_OUTPUT_COMM = 1U << 0,
PERF_OUTPUT_TID = 1U << 1, PERF_OUTPUT_TID = 1U << 1,
...@@ -399,11 +394,8 @@ static void print_sample_bts(union perf_event *event, ...@@ -399,11 +394,8 @@ static void print_sample_bts(union perf_event *event,
printf("\n"); printf("\n");
} }
static void process_event(union perf_event *event __unused, static void process_event(union perf_event *event, struct perf_sample *sample,
struct pevent *pevent __unused, struct perf_evsel *evsel, struct machine *machine,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine,
struct thread *thread) struct thread *thread)
{ {
struct perf_event_attr *attr = &evsel->attr; struct perf_event_attr *attr = &evsel->attr;
...@@ -488,7 +480,6 @@ static int process_sample_event(struct perf_tool *tool __used, ...@@ -488,7 +480,6 @@ static int process_sample_event(struct perf_tool *tool __used,
struct machine *machine) struct machine *machine)
{ {
struct addr_location al; struct addr_location al;
struct perf_script *scr = container_of(tool, struct perf_script, tool);
struct thread *thread = machine__findnew_thread(machine, event->ip.tid); struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
if (thread == NULL) { if (thread == NULL) {
...@@ -520,15 +511,13 @@ static int process_sample_event(struct perf_tool *tool __used, ...@@ -520,15 +511,13 @@ static int process_sample_event(struct perf_tool *tool __used,
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
return 0; return 0;
scripting_ops->process_event(event, scr->session->pevent, scripting_ops->process_event(event, sample, evsel, machine, thread);
sample, evsel, machine, thread);
evsel->hists.stats.total_period += sample->period; evsel->hists.stats.total_period += sample->period;
return 0; return 0;
} }
static struct perf_script perf_script = { static struct perf_tool perf_script = {
.tool = {
.sample = process_sample_event, .sample = process_sample_event,
.mmap = perf_event__process_mmap, .mmap = perf_event__process_mmap,
.comm = perf_event__process_comm, .comm = perf_event__process_comm,
...@@ -540,7 +529,6 @@ static struct perf_script perf_script = { ...@@ -540,7 +529,6 @@ static struct perf_script perf_script = {
.build_id = perf_event__process_build_id, .build_id = perf_event__process_build_id,
.ordered_samples = true, .ordered_samples = true,
.ordering_requires_timestamps = true, .ordering_requires_timestamps = true,
},
}; };
extern volatile int session_done; extern volatile int session_done;
...@@ -556,7 +544,7 @@ static int __cmd_script(struct perf_session *session) ...@@ -556,7 +544,7 @@ static int __cmd_script(struct perf_session *session)
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
ret = perf_session__process_events(session, &perf_script.tool); ret = perf_session__process_events(session, &perf_script);
if (debug_mode) if (debug_mode)
pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
...@@ -1339,12 +1327,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __used) ...@@ -1339,12 +1327,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
setup_pager(); setup_pager();
session = perf_session__new(input_name, O_RDONLY, 0, false, session = perf_session__new(input_name, O_RDONLY, 0, false,
&perf_script.tool); &perf_script);
if (session == NULL) if (session == NULL)
return -ENOMEM; return -ENOMEM;
perf_script.session = session;
if (cpu_list) { if (cpu_list) {
if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap)) if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
return -1; return -1;
......
...@@ -258,7 +258,6 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel) ...@@ -258,7 +258,6 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)
} }
static void perl_process_tracepoint(union perf_event *perf_event __unused, static void perl_process_tracepoint(union perf_event *perf_event __unused,
struct pevent *pevent,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
struct machine *machine __unused, struct machine *machine __unused,
...@@ -284,7 +283,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, ...@@ -284,7 +283,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
if (!event) if (!event)
die("ug! no event found for type %d", evsel->attr.config); die("ug! no event found for type %d", evsel->attr.config);
pid = trace_parse_common_pid(pevent, data); pid = raw_field_value(event, "common_pid", data);
sprintf(handler, "%s::%s", event->system, event->name); sprintf(handler, "%s::%s", event->system, event->name);
...@@ -317,7 +316,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, ...@@ -317,7 +316,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
offset = field->offset; offset = field->offset;
XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0))); XPUSHs(sv_2mortal(newSVpv((char *)data + offset, 0)));
} else { /* FIELD_IS_NUMERIC */ } else { /* FIELD_IS_NUMERIC */
val = read_size(pevent, data + field->offset, val = read_size(event, data + field->offset,
field->size); field->size);
if (field->flags & FIELD_IS_SIGNED) { if (field->flags & FIELD_IS_SIGNED) {
XPUSHs(sv_2mortal(newSViv(val))); XPUSHs(sv_2mortal(newSViv(val)));
...@@ -346,9 +345,9 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused, ...@@ -346,9 +345,9 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
LEAVE; LEAVE;
} }
static void perl_process_event_generic(union perf_event *pevent __unused, static void perl_process_event_generic(union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel __unused, struct perf_evsel *evsel,
struct machine *machine __unused, struct machine *machine __unused,
struct thread *thread __unused) struct thread *thread __unused)
{ {
...@@ -360,7 +359,7 @@ static void perl_process_event_generic(union perf_event *pevent __unused, ...@@ -360,7 +359,7 @@ static void perl_process_event_generic(union perf_event *pevent __unused,
ENTER; ENTER;
SAVETMPS; SAVETMPS;
PUSHMARK(SP); PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpvn((const char *)pevent, pevent->header.size))); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size)));
XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->attr, sizeof(evsel->attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->attr, sizeof(evsel->attr))));
XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample))));
XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size)));
...@@ -373,13 +372,12 @@ static void perl_process_event_generic(union perf_event *pevent __unused, ...@@ -373,13 +372,12 @@ static void perl_process_event_generic(union perf_event *pevent __unused,
} }
static void perl_process_event(union perf_event *event, static void perl_process_event(union perf_event *event,
struct pevent *pevent,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
struct machine *machine, struct machine *machine,
struct thread *thread) struct thread *thread)
{ {
perl_process_tracepoint(event, pevent, sample, evsel, machine, thread); perl_process_tracepoint(event, sample, evsel, machine, thread);
perl_process_event_generic(event, sample, evsel, machine, thread); perl_process_event_generic(event, sample, evsel, machine, thread);
} }
......
...@@ -221,7 +221,6 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel) ...@@ -221,7 +221,6 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel)
} }
static void python_process_event(union perf_event *perf_event __unused, static void python_process_event(union perf_event *perf_event __unused,
struct pevent *pevent,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
struct machine *machine __unused, struct machine *machine __unused,
...@@ -248,7 +247,7 @@ static void python_process_event(union perf_event *perf_event __unused, ...@@ -248,7 +247,7 @@ static void python_process_event(union perf_event *perf_event __unused,
if (!event) if (!event)
die("ug! no event found for type %d", (int)evsel->attr.config); die("ug! no event found for type %d", (int)evsel->attr.config);
pid = trace_parse_common_pid(pevent, data); pid = raw_field_value(event, "common_pid", data);
sprintf(handler_name, "%s__%s", event->system, event->name); sprintf(handler_name, "%s__%s", event->system, event->name);
...@@ -293,7 +292,7 @@ static void python_process_event(union perf_event *perf_event __unused, ...@@ -293,7 +292,7 @@ static void python_process_event(union perf_event *perf_event __unused,
offset = field->offset; offset = field->offset;
obj = PyString_FromString((char *)data + offset); obj = PyString_FromString((char *)data + offset);
} else { /* FIELD_IS_NUMERIC */ } else { /* FIELD_IS_NUMERIC */
val = read_size(pevent, data + field->offset, val = read_size(event, data + field->offset,
field->size); field->size);
if (field->flags & FIELD_IS_SIGNED) { if (field->flags & FIELD_IS_SIGNED) {
if ((long long)val >= LONG_MIN && if ((long long)val >= LONG_MIN &&
......
...@@ -162,9 +162,9 @@ int trace_parse_common_pid(struct pevent *pevent, void *data) ...@@ -162,9 +162,9 @@ int trace_parse_common_pid(struct pevent *pevent, void *data)
return pevent_data_pid(pevent, &record); return pevent_data_pid(pevent, &record);
} }
unsigned long long read_size(struct pevent *pevent, void *ptr, int size) unsigned long long read_size(struct event_format *event, void *ptr, int size)
{ {
return pevent_read_number(pevent, ptr, size); return pevent_read_number(event->pevent, ptr, size);
} }
void event_format__print(struct event_format *event, void event_format__print(struct event_format *event,
......
...@@ -36,7 +36,6 @@ static int stop_script_unsupported(void) ...@@ -36,7 +36,6 @@ static int stop_script_unsupported(void)
} }
static void process_event_unsupported(union perf_event *event __unused, static void process_event_unsupported(union perf_event *event __unused,
struct pevent *pevent __unused,
struct perf_sample *sample __unused, struct perf_sample *sample __unused,
struct perf_evsel *evsel __unused, struct perf_evsel *evsel __unused,
struct machine *machine __unused, struct machine *machine __unused,
......
...@@ -58,7 +58,7 @@ int trace_parse_common_pid(struct pevent *pevent, void *data); ...@@ -58,7 +58,7 @@ int trace_parse_common_pid(struct pevent *pevent, void *data);
struct event_format *trace_find_next_event(struct pevent *pevent, struct event_format *trace_find_next_event(struct pevent *pevent,
struct event_format *event); struct event_format *event);
unsigned long long read_size(struct pevent *pevent, void *ptr, int size); unsigned long long read_size(struct event_format *event, void *ptr, int size);
unsigned long long eval_flag(const char *flag); unsigned long long eval_flag(const char *flag);
struct pevent_record *trace_read_data(struct pevent *pevent, int cpu); struct pevent_record *trace_read_data(struct pevent *pevent, int cpu);
...@@ -81,7 +81,6 @@ struct scripting_ops { ...@@ -81,7 +81,6 @@ struct scripting_ops {
int (*start_script) (const char *script, int argc, const char **argv); int (*start_script) (const char *script, int argc, const char **argv);
int (*stop_script) (void); int (*stop_script) (void);
void (*process_event) (union perf_event *event, void (*process_event) (union perf_event *event,
struct pevent *pevent,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_evsel *evsel,
struct machine *machine, struct machine *machine,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment