lkml.org 
[lkml]   [2012]   [Apr]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 02/13] perf annotate: Parse instruction
On 4/19/12 2:33 PM, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo<acme@redhat.com>
>
> For lines with instructions find the name and operands, breaking those
> tokens for consumption by the browser.
>
> 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-6aazb9f5o3d9zi28e6rruv12@git.kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo<acme@redhat.com>
> ---
> 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


\
 
 \ /
  Last update: 2012-04-20 01:59    [from the cache]
©2003-2011 Jasper Spaans