Skip to contentSkip to conversation

perf annotate: Introduce ->free() method in ins_ops

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message May 14, 2012 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  c46219ac34f0f365bac700ca6a10ef979c643233
Gitweb:     http://git.kernel.org/tip/c46219ac34f0f365bac700ca6a10ef979c643233
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Sat, 12 May 2012 13:26:20 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 12 May 2012 13:26:20 -0300

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 <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/annotate.c |   28 ++++++++++++++++++++--------
 tools/perf/util/annotate.h |    1 +
 2 files changed, 21 insertions(+), 8 deletions(-)
tools/perf/util/annotate.c +20 -8
index 1dce098..8069dfb 100644
@@ -21,6 +21,14 @@ const char 	*disassembler_style;
 static struct ins *ins__find(const char *name);
 static int disasm_line__parse(char *line, char **namep, char **rawp);
 
+static void ins__delete(struct ins_operands *ops)
+{
+	free(ops->source.raw);
+	free(ops->source.name);
+	free(ops->target.raw);
+	free(ops->target.name);
+}
+
 static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
 			      struct ins_operands *ops)
 {
@@ -192,7 +200,15 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
 					size - printed, ops->locked.ops);
 }
 
+static void lock__delete(struct ins_operands *ops)
+{
+	free(ops->locked.ops);
+	free(ops->target.raw);
+	free(ops->target.name);
+}
+
 static struct ins_ops lock_ops = {
+	.free	   = lock__delete,
 	.parse	   = lock__parse,
 	.scnprintf = lock__scnprintf,
 };
@@ -542,14 +558,10 @@ void disasm_line__free(struct disasm_line *dl)
 {
 	free(dl->line);
 	free(dl->name);
-	if (dl->ins && dl->ins->ops == &lock_ops) {
-		free(dl->ops.locked.ops);
-	} else {
-		free(dl->ops.source.raw);
-		free(dl->ops.source.name);
-	}
-	free(dl->ops.target.raw);
-	free(dl->ops.target.name);
+	if (dl->ins && dl->ins->ops->free)
+		dl->ins->ops->free(&dl->ops);
+	else
+		ins__delete(&dl->ops);
 	free(dl);
 }
 
tools/perf/util/annotate.h +1 -0
index b79d326..78a5692 100644
@@ -32,6 +32,7 @@ struct ins_operands {
 };
 
 struct ins_ops {
+	void (*free)(struct ins_operands *ops);
 	int (*parse)(struct ins_operands *ops);
 	int (*scnprintf)(struct ins *ins, char *bf, size_t size,
 			 struct ins_operands *ops);