perf scripting cleanups
Arnaldo Carvalho de Melo
maintainercover perf scripting cleanups
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);
In tools/perf/util/scripting-engines/trace-event-python.c has this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parm there if you don't have any other subtle use for that...
- Arnaldo
Arnaldo Carvalho de Melo (2):
perf script: No need to lookup thread twice
perf scripting: No need to pass thread twice to the scripting
callbacks
tools/perf/builtin-script.c | 14 +++----------- tools/perf/util/scripting-engines/trace-event-perl.c | 5 ++--- tools/perf/util/scripting-engines/trace-event-python.c | 13 +++++-------- tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/trace-event.h | 3 +-- 5 files changed, 11 insertions(+), 25 deletions(-)
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 1/2 perf script: No need to lookup thread twice
From: Arnaldo Carvalho de Melo <[email protected]>
We get the thread when we call perf_event__preprocess_sample(), no need to do it before that.
--- tools/perf/builtin-script.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
tools/perf/builtin-script.c +1 -9
@@ -549,14 +549,6 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, struct machine *machine) {struct addr_location al; -struct thread *thread =machine__findnew_thread (machine, sample->pid, - sample->tid); - -if (thread ==NULL ) { -pr_debug ("problem processing %d event, skipping it.\n" , - event->header.type); -return -1 ; - }if (debug_mode) {if (sample->time < last_timestamp) {
@@ -581,7 +573,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,if (cpu_list && !test_bit (sample->cpu, cpu_bitmap))return 0 ; - scripting_ops->process_event (event, sample, evsel, thread, &al); + scripting_ops->process_event (event, sample, evsel, al.thread, &al);return 0 ; }
Signature · 1 line
1.9.3
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/core] perf script: No need to lookup thread twice
perf script: No need to lookup thread twice
Commit-ID: 79628f2cfe0f488b23e5dc99a4a9a599032fa653 Gitweb: http://git.kernel.org/tip/79628f2cfe0f488b23e5dc99a4a9a599032fa653 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Wed, 1 Apr 2015 13:26:45 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 2 Apr 2015 13:18:21 -0300
perf script: No need to lookup thread twice
We get the thread when we call perf_event__preprocess_sample(), no need to do it before that.
--- tools/perf/builtin-script.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
tools/perf/builtin-script.c +1 -9
@@ -549,14 +549,6 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, struct machine *machine) {struct addr_location al; -struct thread *thread =machine__findnew_thread (machine, sample->pid, - sample->tid); - -if (thread ==NULL ) { -pr_debug ("problem processing %d event, skipping it.\n" , - event->header.type); -return -1 ; - }if (debug_mode) {if (sample->time < last_timestamp) {
@@ -581,7 +573,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,if (cpu_list && !test_bit (sample->cpu, cpu_bitmap))return 0 ; - scripting_ops->process_event (event, sample, evsel, thread, &al); + scripting_ops->process_event (event, sample, evsel, al.thread, &al);return 0 ; }
Arnaldo Carvalho de Melo
maintainerPATCH 2/2 perf scripting: No need to pass thread twice to the scripting callbacks
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It is already in the addr_location, so remove the redundant 'thread' parameter from the callback signatures.
--- tools/perf/builtin-script.c | 6 +++--- tools/perf/util/scripting-engines/trace-event-perl.c | 5 ++--- tools/perf/util/scripting-engines/trace-event-python.c | 13 +++++-------- tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/trace-event.h | 3 +-- 5 files changed, 11 insertions(+), 17 deletions(-)
tools/perf/builtin-script.c +3 -3
@@ -446,9 +446,9 @@ static void print_sample_bts(union perf_event *event, }static void process_event (union perf_event *event,struct perf_sample *sample, -struct perf_evsel *evsel,struct thread *thread, -struct addr_location *al) +struct perf_evsel *evsel,struct addr_location *al) { +struct thread *thread = al->thread;struct perf_event_attr *attr = &evsel->attr;if (output[attr->type].fields ==0 )
@@ -573,7 +573,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,if (cpu_list && !test_bit (sample->cpu, cpu_bitmap))return 0 ; - scripting_ops->process_event (event, sample, evsel, al.thread, &al); + scripting_ops->process_event (event, sample, evsel, &al);return 0 ; }
tools/perf/util/scripting-engines/trace-event-perl.c +2 -3
@@ -360,10 +360,9 @@ static void perl_process_event_generic(union perf_event *event,static void perl_process_event (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread, -struct addr_location *al__maybe_unused ) +struct addr_location *al) { -perl_process_tracepoint (sample, evsel, thread); +perl_process_tracepoint (sample, evsel, al->thread);perl_process_event_generic (event, sample, evsel); }
tools/perf/util/scripting-engines/trace-event-python.c +5 -8
@@ -381,7 +381,6 @@ exit:static void python_process_tracepoint (struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {struct event_format *event = evsel->tp_format;
@@ -395,7 +394,7 @@ static void python_process_tracepoint(struct perf_sample *sample,int cpu = sample->cpu;void *data = sample->raw_data;unsigned long long nsecs = sample->time; -const char *comm =thread__comm_str (thread); +const char *comm =thread__comm_str (al->thread); t =PyTuple_New (MAX_FIELDS );if (!t)
@@ -766,7 +765,6 @@ static int python_process_call_return(struct call_return *cr, void *data)static void python_process_general_event (struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {PyObject *handler, *t, *dict, *callchain, *dict_sample;
@@ -816,7 +814,7 @@ static void python_process_general_event(struct perf_sample *sample,pydict_set_item_string_decref (dict,"raw_buf" ,PyString_FromStringAndSize ( (const char *)sample->raw_data, sample->raw_size));pydict_set_item_string_decref (dict,"comm" , -PyString_FromString (thread__comm_str (thread))); +PyString_FromString (thread__comm_str (al->thread)));if (al->map) {pydict_set_item_string_decref (dict,"dso" ,PyString_FromString (al->map->dso->name));
@@ -843,22 +841,21 @@ exit:static void python_process_event (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {struct tables *tables = &tables_global;switch (evsel->attr.type) {case PERF_TYPE_TRACEPOINT : -python_process_tracepoint (sample, evsel, thread, al); +python_process_tracepoint (sample, evsel, al);break ;/* Reserve for future process_hw/sw/raw APIs */ default :if (tables->db_export_mode)db_export__sample (&tables->dbe, event, sample, evsel, - thread, al); + al->thread, al);else -python_process_general_event (sample, evsel, thread, al); +python_process_general_event (sample, evsel, al); } }
tools/perf/util/trace-event-scripting.c +0 -1
@@ -43,7 +43,6 @@ static int stop_script_unsupported(void)static void process_event_unsupported (union perf_event *event__maybe_unused ,struct perf_sample *sample__maybe_unused ,struct perf_evsel *evsel__maybe_unused , -struct thread *thread__maybe_unused ,struct addr_location *al__maybe_unused ) { }
tools/perf/util/trace-event.h +1 -2
@@ -72,8 +72,7 @@ struct scripting_ops {void (*process_event) (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread, -struct addr_location *al); +struct addr_location *al);int (*generate_script) (struct pevent *pevent,const char *outfile); };
Signature · 1 line
1.9.3
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/core] perf scripting: No need to pass thread twice to the scripting callbacks
perf scripting: No need to pass thread twice to the scripting callbacks
Commit-ID: f9d5d549d2c2934be84b0bc7e5e034834459f591 Gitweb: http://git.kernel.org/tip/f9d5d549d2c2934be84b0bc7e5e034834459f591 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Wed, 1 Apr 2015 13:29:25 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 2 Apr 2015 13:18:41 -0300
perf scripting: No need to pass thread twice to the scripting callbacks
It is already in the addr_location, so remove the redundant 'thread' parameter from the callback signatures.
--- tools/perf/builtin-script.c | 6 +++--- tools/perf/util/scripting-engines/trace-event-perl.c | 5 ++--- tools/perf/util/scripting-engines/trace-event-python.c | 13 +++++-------- tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/trace-event.h | 3 +-- 5 files changed, 11 insertions(+), 17 deletions(-)
tools/perf/builtin-script.c +3 -3
@@ -446,9 +446,9 @@ static void print_sample_bts(union perf_event *event, }static void process_event (union perf_event *event,struct perf_sample *sample, -struct perf_evsel *evsel,struct thread *thread, -struct addr_location *al) +struct perf_evsel *evsel,struct addr_location *al) { +struct thread *thread = al->thread;struct perf_event_attr *attr = &evsel->attr;if (output[attr->type].fields ==0 )
@@ -573,7 +573,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,if (cpu_list && !test_bit (sample->cpu, cpu_bitmap))return 0 ; - scripting_ops->process_event (event, sample, evsel, al.thread, &al); + scripting_ops->process_event (event, sample, evsel, &al);return 0 ; }
tools/perf/util/scripting-engines/trace-event-perl.c +2 -3
@@ -360,10 +360,9 @@ static void perl_process_event_generic(union perf_event *event,static void perl_process_event (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread, -struct addr_location *al__maybe_unused ) +struct addr_location *al) { -perl_process_tracepoint (sample, evsel, thread); +perl_process_tracepoint (sample, evsel, al->thread);perl_process_event_generic (event, sample, evsel); }
tools/perf/util/scripting-engines/trace-event-python.c +5 -8
@@ -381,7 +381,6 @@ exit:static void python_process_tracepoint (struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {struct event_format *event = evsel->tp_format;
@@ -395,7 +394,7 @@ static void python_process_tracepoint(struct perf_sample *sample,int cpu = sample->cpu;void *data = sample->raw_data;unsigned long long nsecs = sample->time; -const char *comm =thread__comm_str (thread); +const char *comm =thread__comm_str (al->thread); t =PyTuple_New (MAX_FIELDS );if (!t)
@@ -766,7 +765,6 @@ static int python_process_call_return(struct call_return *cr, void *data)static void python_process_general_event (struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {PyObject *handler, *t, *dict, *callchain, *dict_sample;
@@ -816,7 +814,7 @@ static void python_process_general_event(struct perf_sample *sample,pydict_set_item_string_decref (dict,"raw_buf" ,PyString_FromStringAndSize ( (const char *)sample->raw_data, sample->raw_size));pydict_set_item_string_decref (dict,"comm" , -PyString_FromString (thread__comm_str (thread))); +PyString_FromString (thread__comm_str (al->thread)));if (al->map) {pydict_set_item_string_decref (dict,"dso" ,PyString_FromString (al->map->dso->name));
@@ -843,22 +841,21 @@ exit:static void python_process_event (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) {struct tables *tables = &tables_global;switch (evsel->attr.type) {case PERF_TYPE_TRACEPOINT : -python_process_tracepoint (sample, evsel, thread, al); +python_process_tracepoint (sample, evsel, al);break ;/* Reserve for future process_hw/sw/raw APIs */ default :if (tables->db_export_mode)db_export__sample (&tables->dbe, event, sample, evsel, - thread, al); + al->thread, al);else -python_process_general_event (sample, evsel, thread, al); +python_process_general_event (sample, evsel, al); } }
tools/perf/util/trace-event-scripting.c +0 -1
@@ -43,7 +43,6 @@ static int stop_script_unsupported(void)static void process_event_unsupported (union perf_event *event__maybe_unused ,struct perf_sample *sample__maybe_unused ,struct perf_evsel *evsel__maybe_unused , -struct thread *thread__maybe_unused ,struct addr_location *al__maybe_unused ) { }
tools/perf/util/trace-event.h +1 -2
@@ -72,8 +72,7 @@ struct scripting_ops {void (*process_event) (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread, -struct addr_location *al); +struct addr_location *al);int (*generate_script) (struct pevent *pevent,const char *outfile); };
Quoted 11 lines · Arnaldo Carvalho de Melo
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);In
tools/perf/util/scripting-engines/trace-event-python.chas this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parm there if you don't have any other subtle use for that...
For both patches,
Thanks,
Namhyung
Jiri Olsa
Acked-byQuoted 9 lines · Namhyung Kim
Quoted 8 lines · Arnaldo Carvalho de Melo
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);
Quoted 7 lines
Quoted 3 lines
In
tools/perf/util/scripting-engines/trace-event-python.chas this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parm there if you don't have any other subtle use for that...For both patches,
Acked-by Namhyung Kim <[email protected]>
looks ok for me too
jirka
Adrian Hunter
reviewerQuoted 10 lines · Arnaldo Carvalho de Melo
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);In
tools/perf/util/scripting-engines/trace-event-python.chas this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parm
Yes please remove it too.
Quoted 1 line
there if you don't have any other subtle use for that...
Nope
Quoted 15 lines
- Arnaldo
Arnaldo Carvalho de Melo (2):
perf script: No need to lookup thread twice
perf scripting: No need to pass thread twice to the scripting
callbackstools/perf/builtin-script.c | 14 +++----------- tools/perf/util/scripting-engines/trace-event-perl.c | 5 ++--- tools/perf/util/scripting-engines/trace-event-python.c | 13 +++++-------- tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/trace-event.h | 3 +-- 5 files changed, 11 insertions(+), 25 deletions(-)
Em Thu, Apr 02, 2015 at 12:16:40PM +0300, Adrian Hunter escreveu:
Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 8 lines
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);
Quoted 8 lines
Quoted 2 lines
In
tools/perf/util/scripting-engines/trace-event-python.chas this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parmYes please remove it too.
Quoted 1 line
there if you don't have any other subtle use for that...
Nope
Ok, adding it as below, with your Acked-by, there is the one at the bottom too, i.s. struct export_sample doesn't need a ->thread field, same reason, if you are ok with that too, will add your Acked-by.
- Arnaldo
Quoted 1 line
From
765b042be1054ec7b5f76b3a004e0aff503e350fMon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Thu, 2 Apr 2015 11:08:30 -0300
Subject: [PATCH 1/1] perf db-export: No need to pass thread twice to
db_export__sample
As it is available via another parameter, address_location->thread.
--- tools/perf/util/db-export.c | 3 ++- tools/perf/util/db-export.h | 2 +- tools/perf/util/scripting-engines/trace-event-python.c | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/db-export.c +2 -1
@@ -282,8 +282,9 @@ int db_export__branch_type(struct db_export *dbe, u32 branch_type,int db_export__sample (struct db_export *dbe,union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al) +struct addr_location *al) { +struct thread * thread = al->thread;struct export_sample es = { .event = event, .sample = sample,
tools/perf/util/db-export.h +1 -1
@@ -97,7 +97,7 @@ int db_export__branch_type(struct db_export *dbe, u32 branch_type, const char *name);int db_export__sample (struct db_export *dbe,union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel, -struct thread *thread,struct addr_location *al); +struct addr_location *al);int db_export__branch_types (struct db_export *dbe);
tools/perf/util/scripting-engines/trace-event-python.c +1 -2
@@ -852,8 +852,7 @@ static void python_process_event(union perf_event *event,/* Reserve for future process_hw/sw/raw APIs */ default :if (tables->db_export_mode) -db_export__sample (&tables->dbe, event, sample, evsel, - al->thread, al); +db_export__sample (&tables->dbe, event, sample, evsel, al);else python_process_general_event (sample, evsel, al); }
Signature · 1 line
1.8.3.1
tools/perf/util/db-export.c +0 -1
@@ -289,7 +289,6 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, .event = event, .sample = sample, .evsel = evsel, - .thread = thread, .al = al, };struct thread *main_thread;
tools/perf/util/db-export.h +0 -1
@@ -34,7 +34,6 @@ struct export_sample {union perf_event *event;struct perf_sample *sample;struct perf_evsel *evsel; -struct thread *thread;struct addr_location *al;u64 db_id;u64 comm_db_id;
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -679,7 +679,7 @@ static int python_export_sample(struct db_export *dbe,tuple_set_u64 (t,0 , es->db_id);tuple_set_u64 (t,1 , es->evsel->db_id);tuple_set_u64 (t,2 , es->al->machine->db_id); -tuple_set_u64 (t,3 , es->thread->db_id); +tuple_set_u64 (t,3 , es->al->thread->db_id);tuple_set_u64 (t,4 , es->comm_db_id);tuple_set_u64 (t,5 , es->dso_db_id);tuple_set_u64 (t,6 , es->sym_db_id);
Adrian Hunter
reviewerQuoted 15 lines · Arnaldo Carvalho de Melo
Em Thu, Apr 02, 2015 at 12:16:40PM +0300, Adrian Hunter escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 10 lines
Hi David, Jiri,
Please take a look if it is ok for you guys
Adrian, there is another thing:
db_export__sample(&tables->dbe, event, sample, evsel, al->thread, al);In
tools/perf/util/scripting-engines/trace-event-python.chas this redundancy as well, see the (al->thread, al), I'll probably remove that extra thread parmYes please remove it too.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
there if you don't have any other subtle use for that...
Nope
Ok, adding it as below, with your Acked-by, there is the one at the bottom too, i.s. struct
export_sampledoesn't need a ->thread field, same reason, if you are ok with that too, will add your Acked-by.
Yes that also looks fine.
tip-bot for Arnaldo Carvalho de Melo
merge bot[tip:perf/core] perf db-export: No need to have -> thread twice in struct export_sample
In reply to Arnaldo Carvalho de Meloperf db-export: No need to have ->thread twice in struct export_sample
Commit-ID: b83e868d0a0350c107b98417b4dcc73834506f98 Gitweb: http://git.kernel.org/tip/b83e868d0a0350c107b98417b4dcc73834506f98 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 2 Apr 2015 11:16:05 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 2 Apr 2015 13:18:43 -0300
perf db-export: No need to have ->thread twice in struct export_sample
As it comes from address_location->thread, that is already stored as export_sample->al, where the thread can be obtained.
--- tools/perf/util/db-export.c | 1 - tools/perf/util/db-export.h | 1 - tools/perf/util/scripting-engines/trace-event-python.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/util/db-export.c +0 -1
@@ -289,7 +289,6 @@ int db_export__sample(struct db_export *dbe, union perf_event *event, .event = event, .sample = sample, .evsel = evsel, - .thread = thread, .al = al, };struct thread *main_thread;
tools/perf/util/db-export.h +0 -1
@@ -34,7 +34,6 @@ struct export_sample {union perf_event *event;struct perf_sample *sample;struct perf_evsel *evsel; -struct thread *thread;struct addr_location *al;u64 db_id;u64 comm_db_id;
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
@@ -679,7 +679,7 @@ static int python_export_sample(struct db_export *dbe,tuple_set_u64 (t,0 , es->db_id);tuple_set_u64 (t,1 , es->evsel->db_id);tuple_set_u64 (t,2 , es->al->machine->db_id); -tuple_set_u64 (t,3 , es->thread->db_id); +tuple_set_u64 (t,3 , es->al->thread->db_id);tuple_set_u64 (t,4 , es->comm_db_id);tuple_set_u64 (t,5 , es->dso_db_id);tuple_set_u64 (t,6 , es->sym_db_id);