diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-12 12:26:20 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-12 12:26:20 -0400 |
commit | c46219ac34f0f365bac700ca6a10ef979c643233 (patch) | |
tree | b23272866f5755d859a31fb7e5e0127b4545639a /tools | |
parent | 7a997fe4019f556a81530d3a737d817a2b0d622f (diff) |
perf annotate: Introduce ->free() method in ins_ops
So that we don't special case disasm_line__free, allowing each
instruction class to provide an specialized destructor, like is needed
for 'lock'.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-xxw4vs5n077tf35jsvjzylhb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/annotate.c | 28 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 1 |
2 files changed, 21 insertions, 8 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 1dce09874d93..8069dfb5ba77 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -21,6 +21,14 @@ const char *disassembler_style; | |||
21 | static struct ins *ins__find(const char *name); | 21 | static struct ins *ins__find(const char *name); |
22 | static int disasm_line__parse(char *line, char **namep, char **rawp); | 22 | static int disasm_line__parse(char *line, char **namep, char **rawp); |
23 | 23 | ||
24 | static void ins__delete(struct ins_operands *ops) | ||
25 | { | ||
26 | free(ops->source.raw); | ||
27 | free(ops->source.name); | ||
28 | free(ops->target.raw); | ||
29 | free(ops->target.name); | ||
30 | } | ||
31 | |||
24 | static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, | 32 | static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, |
25 | struct ins_operands *ops) | 33 | struct ins_operands *ops) |
26 | { | 34 | { |
@@ -192,7 +200,15 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size, | |||
192 | size - printed, ops->locked.ops); | 200 | size - printed, ops->locked.ops); |
193 | } | 201 | } |
194 | 202 | ||
203 | static void lock__delete(struct ins_operands *ops) | ||
204 | { | ||
205 | free(ops->locked.ops); | ||
206 | free(ops->target.raw); | ||
207 | free(ops->target.name); | ||
208 | } | ||
209 | |||
195 | static struct ins_ops lock_ops = { | 210 | static struct ins_ops lock_ops = { |
211 | .free = lock__delete, | ||
196 | .parse = lock__parse, | 212 | .parse = lock__parse, |
197 | .scnprintf = lock__scnprintf, | 213 | .scnprintf = lock__scnprintf, |
198 | }; | 214 | }; |
@@ -542,14 +558,10 @@ void disasm_line__free(struct disasm_line *dl) | |||
542 | { | 558 | { |
543 | free(dl->line); | 559 | free(dl->line); |
544 | free(dl->name); | 560 | free(dl->name); |
545 | if (dl->ins && dl->ins->ops == &lock_ops) { | 561 | if (dl->ins && dl->ins->ops->free) |
546 | free(dl->ops.locked.ops); | 562 | dl->ins->ops->free(&dl->ops); |
547 | } else { | 563 | else |
548 | free(dl->ops.source.raw); | 564 | ins__delete(&dl->ops); |
549 | free(dl->ops.source.name); | ||
550 | } | ||
551 | free(dl->ops.target.raw); | ||
552 | free(dl->ops.target.name); | ||
553 | free(dl); | 565 | free(dl); |
554 | } | 566 | } |
555 | 567 | ||
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index b79d3260647c..78a5692dd718 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -32,6 +32,7 @@ struct ins_operands { | |||
32 | }; | 32 | }; |
33 | 33 | ||
34 | struct ins_ops { | 34 | struct ins_ops { |
35 | void (*free)(struct ins_operands *ops); | ||
35 | int (*parse)(struct ins_operands *ops); | 36 | int (*parse)(struct ins_operands *ops); |
36 | int (*scnprintf)(struct ins *ins, char *bf, size_t size, | 37 | int (*scnprintf)(struct ins *ins, char *bf, size_t size, |
37 | struct ins_operands *ops); | 38 | struct ins_operands *ops); |