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: Jiri 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.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
44530d588e
commit
0a269a6bb3
@ -352,26 +352,16 @@ 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,
|
||||||
|
struct hist_entry *template,
|
||||||
bool sample_self)
|
bool sample_self)
|
||||||
{
|
{
|
||||||
size_t callchain_size = 0;
|
|
||||||
struct hist_entry *he;
|
|
||||||
|
|
||||||
if (symbol_conf.use_callchain)
|
|
||||||
callchain_size = sizeof(struct callchain_root);
|
|
||||||
|
|
||||||
he = zalloc(sizeof(*he) + callchain_size);
|
|
||||||
|
|
||||||
if (he != NULL) {
|
|
||||||
*he = *template;
|
*he = *template;
|
||||||
|
|
||||||
if (symbol_conf.cumulate_callchain) {
|
if (symbol_conf.cumulate_callchain) {
|
||||||
he->stat_acc = malloc(sizeof(he->stat));
|
he->stat_acc = malloc(sizeof(he->stat));
|
||||||
if (he->stat_acc == NULL) {
|
if (he->stat_acc == NULL)
|
||||||
free(he);
|
return -ENOMEM;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
|
memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
|
||||||
if (!sample_self)
|
if (!sample_self)
|
||||||
memset(&he->stat, 0, sizeof(he->stat));
|
memset(&he->stat, 0, sizeof(he->stat));
|
||||||
@ -389,8 +379,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
|
|||||||
if (he->branch_info == NULL) {
|
if (he->branch_info == NULL) {
|
||||||
map__zput(he->ms.map);
|
map__zput(he->ms.map);
|
||||||
free(he->stat_acc);
|
free(he->stat_acc);
|
||||||
free(he);
|
return -ENOMEM;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(he->branch_info, template->branch_info,
|
memcpy(he->branch_info, template->branch_info,
|
||||||
@ -423,8 +412,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
|
|||||||
map__put(he->mem_info->daddr.map);
|
map__put(he->mem_info->daddr.map);
|
||||||
}
|
}
|
||||||
free(he->stat_acc);
|
free(he->stat_acc);
|
||||||
free(he);
|
return -ENOMEM;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
INIT_LIST_HEAD(&he->pairs.node);
|
INIT_LIST_HEAD(&he->pairs.node);
|
||||||
@ -432,6 +420,25 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template,
|
|||||||
|
|
||||||
if (!symbol_conf.report_hierarchy)
|
if (!symbol_conf.report_hierarchy)
|
||||||
he->leaf = true;
|
he->leaf = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct hist_entry *hist_entry__new(struct hist_entry *template,
|
||||||
|
bool sample_self)
|
||||||
|
{
|
||||||
|
size_t callchain_size = 0;
|
||||||
|
struct hist_entry *he;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (symbol_conf.use_callchain)
|
||||||
|
callchain_size = sizeof(struct callchain_root);
|
||||||
|
|
||||||
|
he = zalloc(sizeof(*he) + callchain_size);
|
||||||
|
if (he) {
|
||||||
|
err = hist_entry__init(he, template, sample_self);
|
||||||
|
if (err)
|
||||||
|
zfree(&he);
|
||||||
}
|
}
|
||||||
|
|
||||||
return he;
|
return he;
|
||||||
|
Loading…
Reference in New Issue
Block a user