Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
f542e767 0a269a6b

+33 -4
+27 -4
tools/perf/util/hist.c
··· 424 424 return 0; 425 425 } 426 426 427 + static void *hist_entry__zalloc(size_t size) 428 + { 429 + return zalloc(size + sizeof(struct hist_entry)); 430 + } 431 + 432 + static void hist_entry__free(void *ptr) 433 + { 434 + free(ptr); 435 + } 436 + 437 + static struct hist_entry_ops default_ops = { 438 + .new = hist_entry__zalloc, 439 + .free = hist_entry__free, 440 + }; 441 + 427 442 static struct hist_entry *hist_entry__new(struct hist_entry *template, 428 443 bool sample_self) 429 444 { 445 + struct hist_entry_ops *ops = template->ops; 430 446 size_t callchain_size = 0; 431 447 struct hist_entry *he; 432 448 int err = 0; 433 449 450 + if (!ops) 451 + ops = template->ops = &default_ops; 452 + 434 453 if (symbol_conf.use_callchain) 435 454 callchain_size = sizeof(struct callchain_root); 436 455 437 - he = zalloc(sizeof(*he) + callchain_size); 456 + he = ops->new(callchain_size); 438 457 if (he) { 439 458 err = hist_entry__init(he, template, sample_self); 440 - if (err) 441 - zfree(&he); 459 + if (err) { 460 + ops->free(he); 461 + he = NULL; 462 + } 442 463 } 443 464 444 465 return he; ··· 1071 1050 1072 1051 void hist_entry__delete(struct hist_entry *he) 1073 1052 { 1053 + struct hist_entry_ops *ops = he->ops; 1054 + 1074 1055 thread__zput(he->thread); 1075 1056 map__zput(he->ms.map); 1076 1057 ··· 1097 1074 free_callchain(he->callchain); 1098 1075 free(he->trace_output); 1099 1076 free(he->raw_data); 1100 - free(he); 1077 + ops->free(he); 1101 1078 } 1102 1079 1103 1080 /*
+6
tools/perf/util/sort.h
··· 67 67 }; 68 68 }; 69 69 70 + struct hist_entry_ops { 71 + void *(*new)(size_t size); 72 + void (*free)(void *ptr); 73 + }; 74 + 70 75 /** 71 76 * struct hist_entry - histogram entry 72 77 * ··· 130 125 void *trace_output; 131 126 struct perf_hpp_list *hpp_list; 132 127 struct hist_entry *parent_he; 128 + struct hist_entry_ops *ops; 133 129 union { 134 130 /* this is for hierarchical entry structure */ 135 131 struct {