From b7fff6b5f977115be1757f18b1aca928803b1e17 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 19 Dec 2013 16:34:52 -0300 Subject: perf scripting python: Shorten function signatures Removing unused parameters. Cc: Adrian Hunter Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-fspmnjadohrik8uvhytyu8lp@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- .../util/scripting-engines/trace-event-python.c | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'tools/perf/util/scripting-engines/trace-event-python.c') diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 53c20e7fd90..fc007926eb1 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -231,13 +231,10 @@ static inline struct event_format *find_cache_event(struct perf_evsel *evsel) return event; } -static void python_process_tracepoint(union perf_event *perf_event - __maybe_unused, - struct perf_sample *sample, - struct perf_evsel *evsel, - struct machine *machine __maybe_unused, - struct thread *thread, - struct addr_location *al) +static void python_process_tracepoint(struct perf_sample *sample, + struct perf_evsel *evsel, + struct thread *thread, + struct addr_location *al) { PyObject *handler, *retval, *context, *t, *obj, *dict = NULL; static char handler_name[256]; @@ -351,11 +348,8 @@ static void python_process_tracepoint(union perf_event *perf_event Py_DECREF(t); } -static void python_process_general_event(union perf_event *perf_event - __maybe_unused, - struct perf_sample *sample, +static void python_process_general_event(struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine __maybe_unused, struct thread *thread, struct addr_location *al) { @@ -411,22 +405,20 @@ exit: Py_DECREF(t); } -static void python_process_event(union perf_event *perf_event, +static void python_process_event(union perf_event *event __maybe_unused, struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine, + struct machine *machine __maybe_unused, struct thread *thread, struct addr_location *al) { switch (evsel->attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(perf_event, sample, evsel, - machine, thread, al); + python_process_tracepoint(sample, evsel, thread, al); break; /* Reserve for future process_hw/sw/raw APIs */ default: - python_process_general_event(perf_event, sample, evsel, - machine, thread, al); + python_process_general_event(sample, evsel, thread, al); } } -- cgit v1.2.3-70-g09d2 From cc22e575a6fddbe3183ac14c28e2f792704995c5 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 19 Dec 2013 17:20:06 -0300 Subject: perf symbols: Add 'machine' member to struct addr_location The addr_location struct should fully qualify an address, and to do that it should have in it the machine where the thread was found. Thus all functions that receive an addr_location now don't need to also receive a 'machine', those functions just need to access al->machine instead, just like it does with the other parts of an address location: al->thread, al->map, etc. Cc: Adrian Hunter Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-o51iiee7vyq4r3k362uvuylg@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-report.c | 28 ++++++++++------------ tools/perf/builtin-script.c | 16 ++++++------- tools/perf/util/event.c | 1 + .../perf/util/scripting-engines/trace-event-perl.c | 1 - .../util/scripting-engines/trace-event-python.c | 1 - tools/perf/util/session.c | 4 ++-- tools/perf/util/session.h | 2 +- tools/perf/util/symbol.h | 1 + tools/perf/util/trace-event-scripting.c | 3 +-- tools/perf/util/trace-event.h | 1 - 10 files changed, 26 insertions(+), 32 deletions(-) (limited to 'tools/perf/util/scripting-engines/trace-event-python.c') diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index da156a44cb1..ec7399a8487 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -77,10 +77,10 @@ static int report__config(const char *var, const char *value, void *cb) static int report__resolve_callchain(struct report *rep, struct symbol **parent, struct perf_evsel *evsel, struct addr_location *al, - struct perf_sample *sample, struct machine *machine) + struct perf_sample *sample) { if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { - return machine__resolve_callchain(machine, evsel, al->thread, sample, + return machine__resolve_callchain(al->machine, evsel, al->thread, sample, parent, al, rep->max_stack); } return 0; @@ -95,7 +95,7 @@ static int hist_entry__append_callchain(struct hist_entry *he, struct perf_sampl static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al, struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine, union perf_event *event) + union perf_event *event) { struct report *rep = container_of(tool, struct report, tool); struct symbol *parent = NULL; @@ -103,12 +103,12 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati struct hist_entry *he; struct mem_info *mi, *mx; uint64_t cost; - int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine); + int err = report__resolve_callchain(rep, &parent, evsel, al, sample); if (err) return err; - mi = machine__resolve_mem(machine, al->thread, sample, cpumode); + mi = machine__resolve_mem(al->machine, al->thread, sample, cpumode); if (!mi) return -ENOMEM; @@ -148,20 +148,19 @@ out: } static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_location *al, - struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine) + struct perf_sample *sample, struct perf_evsel *evsel) { struct report *rep = container_of(tool, struct report, tool); struct symbol *parent = NULL; unsigned i; struct hist_entry *he; struct branch_info *bi, *bx; - int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine); + int err = report__resolve_callchain(rep, &parent, evsel, al, sample); if (err) return err; - bi = machine__resolve_bstack(machine, al->thread, + bi = machine__resolve_bstack(al->machine, al->thread, sample->branch_stack); if (!bi) return -ENOMEM; @@ -204,13 +203,12 @@ out: } static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evsel, - struct addr_location *al, struct perf_sample *sample, - struct machine *machine) + struct addr_location *al, struct perf_sample *sample) { struct report *rep = container_of(tool, struct report, tool); struct symbol *parent = NULL; struct hist_entry *he; - int err = report__resolve_callchain(rep, &parent, evsel, al, sample, machine); + int err = report__resolve_callchain(rep, &parent, evsel, al, sample); if (err) return err; @@ -256,18 +254,18 @@ static int process_sample_event(struct perf_tool *tool, return 0; if (sort__mode == SORT_MODE__BRANCH) { - ret = report__add_branch_hist_entry(tool, &al, sample, evsel, machine); + ret = report__add_branch_hist_entry(tool, &al, sample, evsel); if (ret < 0) pr_debug("problem adding lbr entry, skipping event\n"); } else if (rep->mem_mode == 1) { - ret = report__add_mem_hist_entry(tool, &al, sample, evsel, machine, event); + ret = report__add_mem_hist_entry(tool, &al, sample, evsel, event); if (ret < 0) pr_debug("problem adding mem entry, skipping event\n"); } else { if (al.map != NULL) al.map->dso->hit = 1; - ret = report__add_hist_entry(tool, evsel, &al, sample, machine); + ret = report__add_hist_entry(tool, evsel, &al, sample); if (ret < 0) pr_debug("problem incrementing symbol period, skipping event\n"); } diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index f8ab125aac4..62ef190c432 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -423,7 +423,6 @@ static void print_sample_addr(union perf_event *event, static void print_sample_bts(union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine, struct thread *thread, struct addr_location *al) { @@ -435,7 +434,7 @@ static void print_sample_bts(union perf_event *event, printf(" "); else printf("\n"); - perf_evsel__print_ip(evsel, sample, machine, al, + perf_evsel__print_ip(evsel, sample, al, output[attr->type].print_ip_opts, PERF_MAX_STACK_DEPTH); } @@ -446,14 +445,13 @@ static void print_sample_bts(union perf_event *event, if (PRINT_FIELD(ADDR) || ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) && !output[attr->type].user_set)) - print_sample_addr(event, sample, machine, thread, attr); + print_sample_addr(event, sample, al->machine, thread, attr); printf("\n"); } static void process_event(union perf_event *event, struct perf_sample *sample, - struct perf_evsel *evsel, struct machine *machine, - struct thread *thread, + struct perf_evsel *evsel, struct thread *thread, struct addr_location *al) { struct perf_event_attr *attr = &evsel->attr; @@ -469,7 +467,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample, } if (is_bts_event(attr)) { - print_sample_bts(event, sample, evsel, machine, thread, al); + print_sample_bts(event, sample, evsel, thread, al); return; } @@ -477,7 +475,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample, event_format__print(evsel->tp_format, sample->cpu, sample->raw_data, sample->raw_size); if (PRINT_FIELD(ADDR)) - print_sample_addr(event, sample, machine, thread, attr); + print_sample_addr(event, sample, al->machine, thread, attr); if (PRINT_FIELD(IP)) { if (!symbol_conf.use_callchain) @@ -485,7 +483,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample, else printf("\n"); - perf_evsel__print_ip(evsel, sample, machine, al, + perf_evsel__print_ip(evsel, sample, al, output[attr->type].print_ip_opts, PERF_MAX_STACK_DEPTH); } @@ -574,7 +572,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, machine, thread, &al); + scripting_ops->process_event(event, sample, evsel, thread, &al); evsel->hists.stats.total_period += sample->period; return 0; diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 694876877ae..fe202279916 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -638,6 +638,7 @@ void thread__find_addr_map(struct thread *thread, struct map_groups *mg = &thread->mg; bool load_map = false; + al->machine = machine; al->thread = thread; al->addr = addr; al->cpumode = cpumode; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index b672ef0ae46..3773c4841ca 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -371,7 +371,6 @@ 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 machine *machine __maybe_unused, struct thread *thread, struct addr_location *al __maybe_unused) { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index fc007926eb1..b258de6357a 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -408,7 +408,6 @@ exit: static void python_process_event(union perf_event *event __maybe_unused, struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine __maybe_unused, struct thread *thread, struct addr_location *al) { diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 989b2e37762..cbacaab3e9c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1467,7 +1467,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, } void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, - struct machine *machine, struct addr_location *al, + struct addr_location *al, unsigned int print_opts, unsigned int stack_depth) { struct callchain_cursor_node *node; @@ -1482,7 +1482,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, if (symbol_conf.use_callchain && sample->callchain) { struct addr_location node_al; - if (machine__resolve_callchain(machine, evsel, al->thread, + if (machine__resolve_callchain(al->machine, evsel, al->thread, sample, NULL, NULL, PERF_MAX_STACK_DEPTH) != 0) { if (verbose) diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 9c25d49900a..3140f8ae614 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -106,7 +106,7 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, unsigned int type); void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, - struct machine *machine, struct addr_location *al, + struct addr_location *al, unsigned int print_opts, unsigned int stack_depth); int perf_session__cpu_bitmap(struct perf_session *session, diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 8a9d910c534..cbd68036180 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -164,6 +164,7 @@ struct mem_info { }; struct addr_location { + struct machine *machine; struct thread *thread; struct map *map; struct symbol *sym; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c index 95199e4eea9..57aaccc1692 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -38,9 +38,8 @@ 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 machine *machine __maybe_unused, struct thread *thread __maybe_unused, - struct addr_location *al __maybe_unused) + struct addr_location *al __maybe_unused) { } diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 3a01618c5b8..7b6d6868832 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -68,7 +68,6 @@ struct scripting_ops { void (*process_event) (union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, - struct machine *machine, struct thread *thread, struct addr_location *al); int (*generate_script) (struct pevent *pevent, const char *outfile); -- cgit v1.2.3-70-g09d2 From f5385650c02cd4373c4124c8a8fac3b5f9851e7f Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 26 Dec 2013 15:54:57 -0300 Subject: perf tools: No need to test against NULL before calling free() Its perfectly fine to call free(NULL), so no need to clutter the source code with all those superfluous testing. Cc: Adrian Hunter Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-uux5wpvevlerd42gqer13e7n@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kvm.c | 4 +- tools/perf/ui/browsers/scripts.c | 3 +- tools/perf/util/header.c | 6 +-- tools/perf/util/probe-event.c | 62 ++++++++-------------- tools/perf/util/probe-finder.c | 12 ++--- .../perf/util/scripting-engines/trace-event-perl.c | 3 +- .../util/scripting-engines/trace-event-python.c | 3 +- 7 files changed, 31 insertions(+), 62 deletions(-) (limited to 'tools/perf/util/scripting-engines/trace-event-python.c') diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5a80da6ba41..a6ec1052c29 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1158,9 +1158,7 @@ out: if (kvm->timerfd >= 0) close(kvm->timerfd); - if (pollfds) - free(pollfds); - + free(pollfds); return err; } diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c index d63c68ea02a..402d2bd30b0 100644 --- a/tools/perf/ui/browsers/scripts.c +++ b/tools/perf/ui/browsers/scripts.c @@ -173,8 +173,7 @@ int script_browse(const char *script_opt) if (script.b.width > AVERAGE_LINE_LEN) script.b.width = AVERAGE_LINE_LEN; - if (line) - free(line); + free(line); pclose(fp); script.nr_lines = nr_entries; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 61c54213704..10730b0af80 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1232,10 +1232,8 @@ static void free_event_desc(struct perf_evsel *events) return; for (evsel = events; evsel->attr.size; evsel++) { - if (evsel->name) - free(evsel->name); - if (evsel->id) - free(evsel->id); + free(evsel->name); + free(evsel->id); } free(events); diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 72b56aef105..095a98ec744 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -401,9 +401,7 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, } } - if (tmp) - free(tmp); - + free(tmp); return ret; } @@ -1382,8 +1380,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp) error: pr_debug("Failed to synthesize perf probe point: %s\n", strerror(-ret)); - if (buf) - free(buf); + free(buf); return NULL; } @@ -1584,34 +1581,25 @@ void clear_perf_probe_event(struct perf_probe_event *pev) struct perf_probe_arg_field *field, *next; int i; - if (pev->event) - free(pev->event); - if (pev->group) - free(pev->group); - if (pp->file) - free(pp->file); - if (pp->function) - free(pp->function); - if (pp->lazy_line) - free(pp->lazy_line); + free(pev->event); + free(pev->group); + free(pp->file); + free(pp->function); + free(pp->lazy_line); + for (i = 0; i < pev->nargs; i++) { - if (pev->args[i].name) - free(pev->args[i].name); - if (pev->args[i].var) - free(pev->args[i].var); - if (pev->args[i].type) - free(pev->args[i].type); + free(pev->args[i].name); + free(pev->args[i].var); + free(pev->args[i].type); field = pev->args[i].field; while (field) { next = field->next; - if (field->name) - free(field->name); + free(field->name); free(field); field = next; } } - if (pev->args) - free(pev->args); + free(pev->args); memset(pev, 0, sizeof(*pev)); } @@ -1620,21 +1608,14 @@ static void clear_probe_trace_event(struct probe_trace_event *tev) struct probe_trace_arg_ref *ref, *next; int i; - if (tev->event) - free(tev->event); - if (tev->group) - free(tev->group); - if (tev->point.symbol) - free(tev->point.symbol); - if (tev->point.module) - free(tev->point.module); + free(tev->event); + free(tev->group); + free(tev->point.symbol); + free(tev->point.module); for (i = 0; i < tev->nargs; i++) { - if (tev->args[i].name) - free(tev->args[i].name); - if (tev->args[i].value) - free(tev->args[i].value); - if (tev->args[i].type) - free(tev->args[i].type); + free(tev->args[i].name); + free(tev->args[i].value); + free(tev->args[i].type); ref = tev->args[i].ref; while (ref) { next = ref->next; @@ -1642,8 +1623,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev) ref = next; } } - if (tev->args) - free(tev->args); + free(tev->args); memset(tev, 0, sizeof(*tev)); } diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 7db7e05ccb8..8c087359b7c 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -1414,10 +1414,8 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg, if (ret < 0) { /* Free vlist for error */ while (af.nvls--) { - if (af.vls[af.nvls].point.symbol) - free(af.vls[af.nvls].point.symbol); - if (af.vls[af.nvls].vars) - strlist__delete(af.vls[af.nvls].vars); + free(af.vls[af.nvls].point.symbol); + strlist__delete(af.vls[af.nvls].vars); } free(af.vls); *vls = NULL; @@ -1524,10 +1522,8 @@ post: if (fname) { ppt->file = strdup(fname); if (ppt->file == NULL) { - if (ppt->function) { - free(ppt->function); - ppt->function = NULL; - } + free(ppt->function); + ppt->function = NULL; ret = -ENOMEM; goto end; } diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 3773c4841ca..e108207c5de 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -194,8 +194,7 @@ static void define_event_symbols(struct event_format *event, zero_flag_atom = 0; break; case PRINT_FIELD: - if (cur_field_name) - free(cur_field_name); + free(cur_field_name); cur_field_name = strdup(args->field.name); break; case PRINT_FLAGS: diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index b258de6357a..cd9774df375 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -161,8 +161,7 @@ static void define_event_symbols(struct event_format *event, zero_flag_atom = 0; break; case PRINT_FIELD: - if (cur_field_name) - free(cur_field_name); + free(cur_field_name); cur_field_name = strdup(args->field.name); break; case PRINT_FLAGS: -- cgit v1.2.3-70-g09d2