summaryrefslogtreecommitdiff
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-07-05 08:56:04 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-07-12 00:00:39 -0300
commitf542e7670e48bc9d0aed351c1fd2ae0b65cc6f68 (patch)
tree465c63ef93a84bfee9368fd4a10ff0f9d9c2d2c0 /tools/perf/util/hist.c
parent0a269a6bb3f86abb218b8632f13c4ecd9b6b92af (diff)
perf hists: Introduce hist_entry_ops
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 <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-3-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/hist.c')
-rw-r--r--tools/perf/util/hist.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 04f3b52a319c..355b7601ddb7 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -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;
@@ -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);
@@ -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);
}
/*