mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-22 23:04:43 +00:00
perf parse events: Demystify memory allocations
List heads are currently allocated way down the function chain in __add_event and add_tracepoint and then freed when the scanner code calls parse_events_update_lists. Be more explicit with where memory is allocated and who should free it. With this patch the list_head is allocated in the scanner code and freed when the scanner code calls parse_events_update_lists. Signed-off-by: David Ahern <dsahern@gmail.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1372793245-4136-7-git-send-email-dsahern@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
c549aca501
commit
c5cd8ac07e
3 changed files with 61 additions and 63 deletions
|
@ -264,40 +264,29 @@ const char *event_type(int type)
|
|||
|
||||
|
||||
|
||||
static int __add_event(struct list_head **_list, int *idx,
|
||||
static int __add_event(struct list_head *list, int *idx,
|
||||
struct perf_event_attr *attr,
|
||||
char *name, struct cpu_map *cpus)
|
||||
{
|
||||
struct perf_evsel *evsel;
|
||||
struct list_head *list = *_list;
|
||||
|
||||
if (!list) {
|
||||
list = malloc(sizeof(*list));
|
||||
if (!list)
|
||||
return -ENOMEM;
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
|
||||
event_attr_init(attr);
|
||||
|
||||
evsel = perf_evsel__new(attr, (*idx)++);
|
||||
if (!evsel) {
|
||||
free(list);
|
||||
if (!evsel)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
evsel->cpus = cpus;
|
||||
if (name)
|
||||
evsel->name = strdup(name);
|
||||
list_add_tail(&evsel->node, list);
|
||||
*_list = list;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_event(struct list_head **_list, int *idx,
|
||||
static int add_event(struct list_head *list, int *idx,
|
||||
struct perf_event_attr *attr, char *name)
|
||||
{
|
||||
return __add_event(_list, idx, attr, name, NULL);
|
||||
return __add_event(list, idx, attr, name, NULL);
|
||||
}
|
||||
|
||||
static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
|
||||
|
@ -318,7 +307,7 @@ static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES]
|
|||
return -1;
|
||||
}
|
||||
|
||||
int parse_events_add_cache(struct list_head **list, int *idx,
|
||||
int parse_events_add_cache(struct list_head *list, int *idx,
|
||||
char *type, char *op_result1, char *op_result2)
|
||||
{
|
||||
struct perf_event_attr attr;
|
||||
|
@ -379,31 +368,21 @@ int parse_events_add_cache(struct list_head **list, int *idx,
|
|||
return add_event(list, idx, &attr, name);
|
||||
}
|
||||
|
||||
static int add_tracepoint(struct list_head **listp, int *idx,
|
||||
static int add_tracepoint(struct list_head *list, int *idx,
|
||||
char *sys_name, char *evt_name)
|
||||
{
|
||||
struct perf_evsel *evsel;
|
||||
struct list_head *list = *listp;
|
||||
|
||||
if (!list) {
|
||||
list = malloc(sizeof(*list));
|
||||
if (!list)
|
||||
return -ENOMEM;
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
|
||||
evsel = perf_evsel__newtp(sys_name, evt_name, (*idx)++);
|
||||
if (!evsel) {
|
||||
free(list);
|
||||
if (!evsel)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
list_add_tail(&evsel->node, list);
|
||||
*listp = list;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_tracepoint_multi_event(struct list_head **list, int *idx,
|
||||
static int add_tracepoint_multi_event(struct list_head *list, int *idx,
|
||||
char *sys_name, char *evt_name)
|
||||
{
|
||||
char evt_path[MAXPATHLEN];
|
||||
|
@ -435,7 +414,7 @@ static int add_tracepoint_multi_event(struct list_head **list, int *idx,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int add_tracepoint_event(struct list_head **list, int *idx,
|
||||
static int add_tracepoint_event(struct list_head *list, int *idx,
|
||||
char *sys_name, char *evt_name)
|
||||
{
|
||||
return strpbrk(evt_name, "*?") ?
|
||||
|
@ -443,7 +422,7 @@ static int add_tracepoint_event(struct list_head **list, int *idx,
|
|||
add_tracepoint(list, idx, sys_name, evt_name);
|
||||
}
|
||||
|
||||
static int add_tracepoint_multi_sys(struct list_head **list, int *idx,
|
||||
static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
|
||||
char *sys_name, char *evt_name)
|
||||
{
|
||||
struct dirent *events_ent;
|
||||
|
@ -475,7 +454,7 @@ static int add_tracepoint_multi_sys(struct list_head **list, int *idx,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int parse_events_add_tracepoint(struct list_head **list, int *idx,
|
||||
int parse_events_add_tracepoint(struct list_head *list, int *idx,
|
||||
char *sys, char *event)
|
||||
{
|
||||
int ret;
|
||||
|
@ -530,7 +509,7 @@ do { \
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parse_events_add_breakpoint(struct list_head **list, int *idx,
|
||||
int parse_events_add_breakpoint(struct list_head *list, int *idx,
|
||||
void *ptr, char *type)
|
||||
{
|
||||
struct perf_event_attr attr;
|
||||
|
@ -611,7 +590,7 @@ static int config_attr(struct perf_event_attr *attr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parse_events_add_numeric(struct list_head **list, int *idx,
|
||||
int parse_events_add_numeric(struct list_head *list, int *idx,
|
||||
u32 type, u64 config,
|
||||
struct list_head *head_config)
|
||||
{
|
||||
|
@ -644,7 +623,7 @@ static char *pmu_event_name(struct list_head *head_terms)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int parse_events_add_pmu(struct list_head **list, int *idx,
|
||||
int parse_events_add_pmu(struct list_head *list, int *idx,
|
||||
char *name, struct list_head *head_config)
|
||||
{
|
||||
struct perf_event_attr attr;
|
||||
|
@ -687,6 +666,7 @@ void parse_events__set_leader(char *name, struct list_head *list)
|
|||
leader->group_name = name ? strdup(name) : NULL;
|
||||
}
|
||||
|
||||
/* list_event is assumed to point to malloc'ed memory */
|
||||
void parse_events_update_lists(struct list_head *list_event,
|
||||
struct list_head *list_all)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue