summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/debug.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-04-19 16:21:59 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-04-24 12:33:31 -0300
commit8c2b7cac78e17886e8089389a570a290c9b5ca67 (patch)
tree94302f8f9f6dcdf61e2df74ef9f9f75f0d903f71 /tools/perf/util/debug.c
parentbb8c16db43e48f2012c3ae8c7d682f834c5986d9 (diff)
downloadop-kernel-dev-8c2b7cac78e17886e8089389a570a290c9b5ca67.zip
op-kernel-dev-8c2b7cac78e17886e8089389a570a290c9b5ca67.tar.gz
perf debug: Move dump_stack() and sighandler_dump_stack() to debug.h
Two more out of util.h. Link: http://lkml.kernel.org/n/tip-polkuxm1cpr06lbgue5pyqum@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/debug.c')
-rw-r--r--tools/perf/util/debug.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 6e1d7e1..9eaf86f 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -8,7 +8,9 @@
#include <stdio.h>
#include <api/debug.h>
#include <linux/time64.h>
-
+#ifdef HAVE_BACKTRACE_SUPPORT
+#include <execinfo.h>
+#endif
#include "cache.h"
#include "color.h"
#include "event.h"
@@ -248,3 +250,31 @@ void perf_debug_setup(void)
{
libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);
}
+
+/* Obtain a backtrace and print it to stdout. */
+#ifdef HAVE_BACKTRACE_SUPPORT
+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);
+}
+#else
+void dump_stack(void) {}
+#endif
+
+void sighandler_dump_stack(int sig)
+{
+ psignal(sig, "perf");
+ dump_stack();
+ signal(sig, SIG_DFL);
+ raise(sig);
+}
OpenPOWER on IntegriCloud