Skip to content

Commit

Permalink
perf evsel: Delete the event selectors at exit
Browse files Browse the repository at this point in the history
Freeing all the possibly allocated resources, reducing complexity
on each tool exit path.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Jan 3, 2011
1 parent 1e7972c commit 70d544d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 0 additions & 2 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
out_free_event_array:
free(event_array);
out_free_fd:
list_for_each_entry(pos, &evsel_list, node)
perf_evsel__free_fd(pos);
free(all_tids);
all_tids = NULL;
out_symbol_exit:
Expand Down
4 changes: 1 addition & 3 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
if (status != -1)
print_stat(argc, argv);
out_free_fd:
list_for_each_entry(pos, &evsel_list, node) {
perf_evsel__free_fd(pos);
list_for_each_entry(pos, &evsel_list, node)
perf_evsel__free_stat_priv(pos);
}
out:
return status;
}
4 changes: 1 addition & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)

status = __cmd_top();
out_free_fd:
list_for_each_entry(pos, &evsel_list, node) {
perf_evsel__free_fd(pos);
list_for_each_entry(pos, &evsel_list, node)
perf_evsel__free_mmap(pos);
}

return status;
}
2 changes: 2 additions & 0 deletions tools/perf/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
status = p->fn(argc, argv, prefix);
exit_browser(status);

perf_evsel_list__delete();

if (status)
return status & 0xff;

Expand Down
11 changes: 11 additions & 0 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,14 @@ int perf_evsel_list__create_default(void)
++nr_counters;
return 0;
}

void perf_evsel_list__delete(void)
{
struct perf_evsel *pos, *n;

list_for_each_entry_safe(pos, n, &evsel_list, node) {
list_del_init(&pos->node);
perf_evsel__delete(pos);
}
nr_counters = 0;
}
1 change: 1 addition & 0 deletions tools/perf/util/parse-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct perf_evsel;
extern struct list_head evsel_list;

int perf_evsel_list__create_default(void);
void perf_evsel_list__delete(void);

struct option;

Expand Down

0 comments on commit 70d544d

Please sign in to comment.