From ed20973aeaa592c1f61f7f80be07d4485888a09f Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 7 Aug 2012 23:32:05 -0300 Subject: [PATCH] --- yaml --- r: 323633 b: refs/heads/master c: dc4552bf7176573ccf79af04ab8648b015738f4a h: refs/heads/master i: 323631: 2bc4828bec39f65b89e22e7a518e6ddcb0bb05fe v: v3 --- [refs] | 2 +- trunk/tools/perf/util/util.c | 19 +++++++++++++++++++ trunk/tools/perf/util/util.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 659694f13f26..d757896cabb4 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a7cb8863dd352f052e7b2b86a17410070d1b69af +refs/heads/master: dc4552bf7176573ccf79af04ab8648b015738f4a diff --git a/trunk/tools/perf/util/util.c b/trunk/tools/perf/util/util.c index d03599fbe78b..1b8775c3707d 100644 --- a/trunk/tools/perf/util/util.c +++ b/trunk/tools/perf/util/util.c @@ -1,6 +1,9 @@ #include "../perf.h" #include "util.h" #include +#include +#include +#include /* * XXX We need to find a better place for these things... @@ -158,3 +161,19 @@ size_t hex_width(u64 v) return n; } + +/* Obtain a backtrace and print it to stdout. */ +void dump_stack(void) +{ + void *array[16]; + size_t size = backtrace(array, ARRAY_SIZE(array)); + char **strings = backtrace_symbols(array, size); + size_t i; + + printf("Obtained %zd stack frames.\n", size); + + for (i = 0; i < size; i++) + printf("%s\n", strings[i]); + + free(strings); +} diff --git a/trunk/tools/perf/util/util.h b/trunk/tools/perf/util/util.h index b13c7331eaf8..00a93a91a235 100644 --- a/trunk/tools/perf/util/util.h +++ b/trunk/tools/perf/util/util.h @@ -266,4 +266,6 @@ size_t hex_width(u64 v); char *rtrim(char *s); +void dump_stack(void); + #endif