Commit 0a269a6b authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf hists: Introduce hist_entry__init function

Move the 'struct hist_entry' initialization code to a separate function.
It'll be useful and more clear for the following patches that introduce
allocation callbacks.

Releasing the hist_entry object in hist_entry__new function
(where it's allocated) rather than in hist_entry__init.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1467701765-26194-2-git-send-email-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 44530d58
...@@ -352,86 +352,93 @@ void hists__delete_entries(struct hists *hists) ...@@ -352,86 +352,93 @@ void hists__delete_entries(struct hists *hists)
* histogram, sorted on item, collects periods * histogram, sorted on item, collects periods
*/ */
static struct hist_entry *hist_entry__new(struct hist_entry *template, static int hist_entry__init(struct hist_entry *he,
bool sample_self) struct hist_entry *template,
{ bool sample_self)
size_t callchain_size = 0; {
struct hist_entry *he; *he = *template;
if (symbol_conf.cumulate_callchain) {
he->stat_acc = malloc(sizeof(he->stat));
if (he->stat_acc == NULL)
return -ENOMEM;
memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
if (!sample_self)
memset(&he->stat, 0, sizeof(he->stat));
}
if (symbol_conf.use_callchain) map__get(he->ms.map);
callchain_size = sizeof(struct callchain_root);
he = zalloc(sizeof(*he) + callchain_size); if (he->branch_info) {
/*
* This branch info is (a part of) allocated from
* sample__resolve_bstack() and will be freed after
* adding new entries. So we need to save a copy.
*/
he->branch_info = malloc(sizeof(*he->branch_info));
if (he->branch_info == NULL) {
map__zput(he->ms.map);
free(he->stat_acc);
return -ENOMEM;
}
if (he != NULL) { memcpy(he->branch_info, template->branch_info,
*he = *template; sizeof(*he->branch_info));
if (symbol_conf.cumulate_callchain) { map__get(he->branch_info->from.map);
he->stat_acc = malloc(sizeof(he->stat)); map__get(he->branch_info->to.map);
if (he->stat_acc == NULL) { }
free(he);
return NULL;
}
memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
if (!sample_self)
memset(&he->stat, 0, sizeof(he->stat));
}
map__get(he->ms.map); if (he->mem_info) {
map__get(he->mem_info->iaddr.map);
map__get(he->mem_info->daddr.map);
}
if (he->branch_info) { if (symbol_conf.use_callchain)
/* callchain_init(he->callchain);
* This branch info is (a part of) allocated from
* sample__resolve_bstack() and will be freed after
* adding new entries. So we need to save a copy.
*/
he->branch_info = malloc(sizeof(*he->branch_info));
if (he->branch_info == NULL) {
map__zput(he->ms.map);
free(he->stat_acc);
free(he);
return NULL;
}
memcpy(he->branch_info, template->branch_info, if (he->raw_data) {
sizeof(*he->branch_info)); he->raw_data = memdup(he->raw_data, he->raw_size);
map__get(he->branch_info->from.map); if (he->raw_data == NULL) {
map__get(he->branch_info->to.map); map__put(he->ms.map);
if (he->branch_info) {
map__put(he->branch_info->from.map);
map__put(he->branch_info->to.map);
free(he->branch_info);
}
if (he->mem_info) {
map__put(he->mem_info->iaddr.map);
map__put(he->mem_info->daddr.map);
}
free(he->stat_acc);
return -ENOMEM;
} }
}
INIT_LIST_HEAD(&he->pairs.node);
thread__get(he->thread);
if (he->mem_info) { if (!symbol_conf.report_hierarchy)
map__get(he->mem_info->iaddr.map); he->leaf = true;
map__get(he->mem_info->daddr.map);
}
if (symbol_conf.use_callchain) return 0;
callchain_init(he->callchain); }
if (he->raw_data) { static struct hist_entry *hist_entry__new(struct hist_entry *template,
he->raw_data = memdup(he->raw_data, he->raw_size); bool sample_self)
{
size_t callchain_size = 0;
struct hist_entry *he;
int err = 0;
if (he->raw_data == NULL) { if (symbol_conf.use_callchain)
map__put(he->ms.map); callchain_size = sizeof(struct callchain_root);
if (he->branch_info) {
map__put(he->branch_info->from.map);
map__put(he->branch_info->to.map);
free(he->branch_info);
}
if (he->mem_info) {
map__put(he->mem_info->iaddr.map);
map__put(he->mem_info->daddr.map);
}
free(he->stat_acc);
free(he);
return NULL;
}
}
INIT_LIST_HEAD(&he->pairs.node);
thread__get(he->thread);
if (!symbol_conf.report_hierarchy) he = zalloc(sizeof(*he) + callchain_size);
he->leaf = true; if (he) {
err = hist_entry__init(he, template, sample_self);
if (err)
zfree(&he);
} }
return he; return he;
......
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