diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 22:32:05 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 22:32:05 -0400 |
commit | dc4552bf7176573ccf79af04ab8648b015738f4a (patch) | |
tree | 6bad99fd2b37a112c0dbe9aa71d1577e316eae4d | |
parent | a7cb8863dd352f052e7b2b86a17410070d1b69af (diff) |
perf tools: Add dump_stack function
To help in debugging the tools, provides functionality roughly similar
to the function with the same name in the kernel.
Copied from glibc backtrace function man page.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.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-6nw2sak21bqy8h1m2syyo816@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/util.c | 19 | ||||
-rw-r--r-- | tools/perf/util/util.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index d03599fbe78b..1b8775c3707d 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -1,6 +1,9 @@ | |||
1 | #include "../perf.h" | 1 | #include "../perf.h" |
2 | #include "util.h" | 2 | #include "util.h" |
3 | #include <sys/mman.h> | 3 | #include <sys/mman.h> |
4 | #include <execinfo.h> | ||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
4 | 7 | ||
5 | /* | 8 | /* |
6 | * XXX We need to find a better place for these things... | 9 | * XXX We need to find a better place for these things... |
@@ -158,3 +161,19 @@ size_t hex_width(u64 v) | |||
158 | 161 | ||
159 | return n; | 162 | return n; |
160 | } | 163 | } |
164 | |||
165 | /* Obtain a backtrace and print it to stdout. */ | ||
166 | void dump_stack(void) | ||
167 | { | ||
168 | void *array[16]; | ||
169 | size_t size = backtrace(array, ARRAY_SIZE(array)); | ||
170 | char **strings = backtrace_symbols(array, size); | ||
171 | size_t i; | ||
172 | |||
173 | printf("Obtained %zd stack frames.\n", size); | ||
174 | |||
175 | for (i = 0; i < size; i++) | ||
176 | printf("%s\n", strings[i]); | ||
177 | |||
178 | free(strings); | ||
179 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index b13c7331eaf8..00a93a91a235 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -266,4 +266,6 @@ size_t hex_width(u64 v); | |||
266 | 266 | ||
267 | char *rtrim(char *s); | 267 | char *rtrim(char *s); |
268 | 268 | ||
269 | void dump_stack(void); | ||
270 | |||
269 | #endif | 271 | #endif |