Skip to content

Commit

Permalink
perf hists: Introduce hist_entry_ops
Browse files Browse the repository at this point in the history
Introducing allocation callbacks, that allows to extend current
hist_entry object into objects with special needs without polluting the
current hist_entry object.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
olsajiri authored and acmel committed Jul 12, 2016
1 parent 0a269a6 commit f542e76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,42 @@ static int hist_entry__init(struct hist_entry *he,
return 0;
}

static void *hist_entry__zalloc(size_t size)
{
return zalloc(size + sizeof(struct hist_entry));
}

static void hist_entry__free(void *ptr)
{
free(ptr);
}

static struct hist_entry_ops default_ops = {
.new = hist_entry__zalloc,
.free = hist_entry__free,
};

static struct hist_entry *hist_entry__new(struct hist_entry *template,
bool sample_self)
{
struct hist_entry_ops *ops = template->ops;
size_t callchain_size = 0;
struct hist_entry *he;
int err = 0;

if (!ops)
ops = template->ops = &default_ops;

if (symbol_conf.use_callchain)
callchain_size = sizeof(struct callchain_root);

he = zalloc(sizeof(*he) + callchain_size);
he = ops->new(callchain_size);
if (he) {
err = hist_entry__init(he, template, sample_self);
if (err)
zfree(&he);
if (err) {
ops->free(he);
he = NULL;
}
}

return he;
Expand Down Expand Up @@ -1050,6 +1071,8 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)

void hist_entry__delete(struct hist_entry *he)
{
struct hist_entry_ops *ops = he->ops;

thread__zput(he->thread);
map__zput(he->ms.map);

Expand All @@ -1074,7 +1097,7 @@ void hist_entry__delete(struct hist_entry *he)
free_callchain(he->callchain);
free(he->trace_output);
free(he->raw_data);
free(he);
ops->free(he);
}

/*
Expand Down
6 changes: 6 additions & 0 deletions tools/perf/util/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ struct hist_entry_diff {
};
};

struct hist_entry_ops {
void *(*new)(size_t size);
void (*free)(void *ptr);
};

/**
* struct hist_entry - histogram entry
*
Expand Down Expand Up @@ -125,6 +130,7 @@ struct hist_entry {
void *trace_output;
struct perf_hpp_list *hpp_list;
struct hist_entry *parent_he;
struct hist_entry_ops *ops;
union {
/* this is for hierarchical entry structure */
struct {
Expand Down

0 comments on commit f542e76

Please sign in to comment.