Re: [PATCH 02/13] perf annotate: Parse instruction

From: David Ahern
Date: Thu Apr 19 2012 - 19:56:02 EST


On 4/19/12 2:33 PM, Arnaldo Carvalho de Melo wrote:
From: Arnaldo Carvalho de Melo<acme@xxxxxxxxxx>

For lines with instructions find the name and operands, breaking those
tokens for consumption by the browser.

Cc: David Ahern<dsahern@xxxxxxxxx>
Cc: Frederic Weisbecker<fweisbec@xxxxxxxxx>
Cc: Mike Galbraith<efault@xxxxxx>
Cc: Namhyung Kim<namhyung@xxxxxxxxx>
Cc: Paul Mackerras<paulus@xxxxxxxxx>
Cc: Peter Zijlstra<peterz@xxxxxxxxxxxxx>
Cc: Stephane Eranian<eranian@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-6aazb9f5o3d9zi28e6rruv12@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo<acme@xxxxxxxxxx>
---
tools/perf/util/annotate.c | 65 +++++++++++++++++++++++++++++++++++++++++++-
tools/perf/util/annotate.h | 3 ++
2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index ef1d57d..a72585a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -80,16 +80,50 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,

static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
{
- struct disasm_line *dl = malloc(sizeof(*dl) + privsize);
+ struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);

if (dl != NULL) {
dl->offset = offset;
dl->line = strdup(line);
if (dl->line == NULL)
goto out_delete;
+
+ if (offset != -1) {
+ char *name = dl->line, tmp;
+
+ while (isspace(name[0]))
+ ++name;
+
+ if (name[0] == '\0')
+ goto out_delete;
+
+ dl->operands = name + 1;
+
+ while (dl->operands[0] != '\0'&&
+ !isspace(dl->operands[0]))
+ ++dl->operands;
+
+ tmp = dl->operands[0];
+ dl->operands[0] = '\0';
+ dl->name = strdup(name);

This strdup seems unnecessary. The parsing seems to be:

dl->line = "\W*name\W*operands"
dl->name = -^ ^- = dl_operands

so name and operands are 2 different parts of the same buffer.

David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/