aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-07-05 02:56:04 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-07-11 23:00:39 -0400
commitf542e7670e48bc9d0aed351c1fd2ae0b65cc6f68 (patch)
tree465c63ef93a84bfee9368fd4a10ff0f9d9c2d2c0 /tools/perf
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')
-rw-r--r--tools/perf/util/hist.c31
-rw-r--r--tools/perf/util/sort.h6
2 files changed, 33 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,
424 return 0; 424 return 0;
425} 425}
426 426
427static void *hist_entry__zalloc(size_t size)
428{
429 return zalloc(size + sizeof(struct hist_entry));
430}
431
432static void hist_entry__free(void *ptr)
433{
434 free(ptr);
435}
436
437static struct hist_entry_ops default_ops = {
438 .new = hist_entry__zalloc,
439 .free = hist_entry__free,
440};
441
427static struct hist_entry *hist_entry__new(struct hist_entry *template, 442static struct hist_entry *hist_entry__new(struct hist_entry *template,
428 bool sample_self) 443 bool sample_self)
429{ 444{
445 struct hist_entry_ops *ops = template->ops;
430 size_t callchain_size = 0; 446 size_t callchain_size = 0;
431 struct hist_entry *he; 447 struct hist_entry *he;
432 int err = 0; 448 int err = 0;
433 449
450 if (!ops)
451 ops = template->ops = &default_ops;
452
434 if (symbol_conf.use_callchain) 453 if (symbol_conf.use_callchain)
435 callchain_size = sizeof(struct callchain_root); 454 callchain_size = sizeof(struct callchain_root);
436 455
437 he = zalloc(sizeof(*he) + callchain_size); 456 he = ops->new(callchain_size);
438 if (he) { 457 if (he) {
439 err = hist_entry__init(he, template, sample_self); 458 err = hist_entry__init(he, template, sample_self);
440 if (err) 459 if (err) {
441 zfree(&he); 460 ops->free(he);
461 he = NULL;
462 }
442 } 463 }
443 464
444 return he; 465 return he;
@@ -1050,6 +1071,8 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
1050 1071
1051void hist_entry__delete(struct hist_entry *he) 1072void hist_entry__delete(struct hist_entry *he)
1052{ 1073{
1074 struct hist_entry_ops *ops = he->ops;
1075
1053 thread__zput(he->thread); 1076 thread__zput(he->thread);
1054 map__zput(he->ms.map); 1077 map__zput(he->ms.map);
1055 1078
@@ -1074,7 +1097,7 @@ void hist_entry__delete(struct hist_entry *he)
1074 free_callchain(he->callchain); 1097 free_callchain(he->callchain);
1075 free(he->trace_output); 1098 free(he->trace_output);
1076 free(he->raw_data); 1099 free(he->raw_data);
1077 free(he); 1100 ops->free(he);
1078} 1101}
1079 1102
1080/* 1103/*
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index ebb59cacd092..7ca37ea17395 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -67,6 +67,11 @@ struct hist_entry_diff {
67 }; 67 };
68}; 68};
69 69
70struct hist_entry_ops {
71 void *(*new)(size_t size);
72 void (*free)(void *ptr);
73};
74
70/** 75/**
71 * struct hist_entry - histogram entry 76 * struct hist_entry - histogram entry
72 * 77 *
@@ -125,6 +130,7 @@ struct hist_entry {
125 void *trace_output; 130 void *trace_output;
126 struct perf_hpp_list *hpp_list; 131 struct perf_hpp_list *hpp_list;
127 struct hist_entry *parent_he; 132 struct hist_entry *parent_he;
133 struct hist_entry_ops *ops;
128 union { 134 union {
129 /* this is for hierarchical entry structure */ 135 /* this is for hierarchical entry structure */
130 struct { 136 struct {