[patch 1/4] perf_counter tools: Make symbol loading consistently return number of loaded symbols

Mike Galbraith
2009-07-02T06:06:13Z

perf_counter tools: Make symbol loading consistently return number of loaded symbols.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>

---
tools/perf/builtin-annotate.c | 2 +-
tools/perf/builtin-report.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/util/symbol.c | 9 ++++++---
4 files changed, 9 insertions(+), 6 deletions(-)

Index: linux-2.6/tools/perf/builtin-annotate.c
===================================================================
--- linux-2.6.orig/tools/perf/builtin-annotate.c
+++ linux-2.6/tools/perf/builtin-annotate.c
@@ -172,7 +172,7 @@ static int load_kernel(void)
return -1;

err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose);
- if (err) {
+ if (err <= 0) {
dso__delete(kernel_dso);
kernel_dso = NULL;
} else
Index: linux-2.6/tools/perf/builtin-report.c
===================================================================
--- linux-2.6.orig/tools/perf/builtin-report.c
+++ linux-2.6/tools/perf/builtin-report.c
@@ -189,7 +189,7 @@ static int load_kernel(void)
return -1;

err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose);
- if (err) {
+ if (err <= 0) {
dso__delete(kernel_dso);
kernel_dso = NULL;
} else
Index: linux-2.6/tools/perf/builtin-top.c
===================================================================
--- linux-2.6.orig/tools/perf/builtin-top.c
+++ linux-2.6/tools/perf/builtin-top.c
@@ -364,7 +364,7 @@ static int parse_symbols(void)
if (kernel_dso == NULL)
return -1;

- if (dso__load_kernel(kernel_dso, NULL, symbol_filter, 1) != 0)
+ if (dso__load_kernel(kernel_dso, NULL, symbol_filter, 1) <= 0)
goto out_delete_dso;

node = rb_first(&kernel_dso->syms);
Index: linux-2.6/tools/perf/util/symbol.c
===================================================================
--- linux-2.6.orig/tools/perf/util/symbol.c
+++ linux-2.6/tools/perf/util/symbol.c
@@ -146,6 +146,7 @@ static int dso__load_kallsyms(struct dso
char *line = NULL;
size_t n;
FILE *file = fopen("/proc/kallsyms", "r");
+ int count = 0;

if (file == NULL)
goto out_failure;
@@ -188,8 +189,10 @@ static int dso__load_kallsyms(struct dso

if (filter && filter(self, sym))
symbol__delete(sym, self->sym_priv_size);
- else
+ else {
dso__insert_symbol(self, sym);
+ count++;
+ }
}

/*
@@ -212,7 +215,7 @@ static int dso__load_kallsyms(struct dso
free(line);
fclose(file);

- return 0;
+ return count;

out_delete_line:
free(line);
@@ -639,7 +642,7 @@ int dso__load_kernel(struct dso *self, c
if (vmlinux)
err = dso__load_vmlinux(self, vmlinux, filter, verbose);

- if (err < 0)
+ if (err <= 0)
err = dso__load_kallsyms(self, filter, verbose);

return err;