diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-19 15:21:59 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-24 11:33:31 -0400 |
commit | 8c2b7cac78e17886e8089389a570a290c9b5ca67 (patch) | |
tree | 94302f8f9f6dcdf61e2df74ef9f9f75f0d903f71 /tools | |
parent | bb8c16db43e48f2012c3ae8c7d682f834c5986d9 (diff) |
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')
-rw-r--r-- | tools/perf/util/debug.c | 32 | ||||
-rw-r--r-- | tools/perf/util/debug.h | 3 | ||||
-rw-r--r-- | tools/perf/util/util.c | 31 | ||||
-rw-r--r-- | tools/perf/util/util.h | 3 |
4 files changed, 34 insertions, 35 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 6e1d7e159649..9eaf86f4003b 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -8,7 +8,9 @@ | |||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <api/debug.h> | 9 | #include <api/debug.h> |
10 | #include <linux/time64.h> | 10 | #include <linux/time64.h> |
11 | 11 | #ifdef HAVE_BACKTRACE_SUPPORT | |
12 | #include <execinfo.h> | ||
13 | #endif | ||
12 | #include "cache.h" | 14 | #include "cache.h" |
13 | #include "color.h" | 15 | #include "color.h" |
14 | #include "event.h" | 16 | #include "event.h" |
@@ -248,3 +250,31 @@ void perf_debug_setup(void) | |||
248 | { | 250 | { |
249 | libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper); | 251 | libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper); |
250 | } | 252 | } |
253 | |||
254 | /* Obtain a backtrace and print it to stdout. */ | ||
255 | #ifdef HAVE_BACKTRACE_SUPPORT | ||
256 | void dump_stack(void) | ||
257 | { | ||
258 | void *array[16]; | ||
259 | size_t size = backtrace(array, ARRAY_SIZE(array)); | ||
260 | char **strings = backtrace_symbols(array, size); | ||
261 | size_t i; | ||
262 | |||
263 | printf("Obtained %zd stack frames.\n", size); | ||
264 | |||
265 | for (i = 0; i < size; i++) | ||
266 | printf("%s\n", strings[i]); | ||
267 | |||
268 | free(strings); | ||
269 | } | ||
270 | #else | ||
271 | void dump_stack(void) {} | ||
272 | #endif | ||
273 | |||
274 | void sighandler_dump_stack(int sig) | ||
275 | { | ||
276 | psignal(sig, "perf"); | ||
277 | dump_stack(); | ||
278 | signal(sig, SIG_DFL); | ||
279 | raise(sig); | ||
280 | } | ||
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 98832f5531d3..8a23ea1a71c7 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -56,4 +56,7 @@ int perf_debug_option(const char *str); | |||
56 | void perf_debug_setup(void); | 56 | void perf_debug_setup(void); |
57 | int perf_quiet_option(void); | 57 | int perf_quiet_option(void); |
58 | 58 | ||
59 | void dump_stack(void); | ||
60 | void sighandler_dump_stack(int sig); | ||
61 | |||
59 | #endif /* __PERF_DEBUG_H */ | 62 | #endif /* __PERF_DEBUG_H */ |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index eb49330c77d4..ae8036f06329 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -4,9 +4,6 @@ | |||
4 | #include <api/fs/fs.h> | 4 | #include <api/fs/fs.h> |
5 | #include <sys/mman.h> | 5 | #include <sys/mman.h> |
6 | #include <sys/utsname.h> | 6 | #include <sys/utsname.h> |
7 | #ifdef HAVE_BACKTRACE_SUPPORT | ||
8 | #include <execinfo.h> | ||
9 | #endif | ||
10 | #include <dirent.h> | 7 | #include <dirent.h> |
11 | #include <inttypes.h> | 8 | #include <inttypes.h> |
12 | #include <signal.h> | 9 | #include <signal.h> |
@@ -353,34 +350,6 @@ int hex2u64(const char *ptr, u64 *long_val) | |||
353 | return p - ptr; | 350 | return p - ptr; |
354 | } | 351 | } |
355 | 352 | ||
356 | /* Obtain a backtrace and print it to stdout. */ | ||
357 | #ifdef HAVE_BACKTRACE_SUPPORT | ||
358 | void dump_stack(void) | ||
359 | { | ||
360 | void *array[16]; | ||
361 | size_t size = backtrace(array, ARRAY_SIZE(array)); | ||
362 | char **strings = backtrace_symbols(array, size); | ||
363 | size_t i; | ||
364 | |||
365 | printf("Obtained %zd stack frames.\n", size); | ||
366 | |||
367 | for (i = 0; i < size; i++) | ||
368 | printf("%s\n", strings[i]); | ||
369 | |||
370 | free(strings); | ||
371 | } | ||
372 | #else | ||
373 | void dump_stack(void) {} | ||
374 | #endif | ||
375 | |||
376 | void sighandler_dump_stack(int sig) | ||
377 | { | ||
378 | psignal(sig, "perf"); | ||
379 | dump_stack(); | ||
380 | signal(sig, SIG_DFL); | ||
381 | raise(sig); | ||
382 | } | ||
383 | |||
384 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) | 353 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) |
385 | { | 354 | { |
386 | struct parse_tag *i = tags; | 355 | struct parse_tag *i = tags; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index c3f6d0de69c5..07c4293742e7 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -80,9 +80,6 @@ void event_attr_init(struct perf_event_attr *attr); | |||
80 | size_t hex_width(u64 v); | 80 | size_t hex_width(u64 v); |
81 | int hex2u64(const char *ptr, u64 *val); | 81 | int hex2u64(const char *ptr, u64 *val); |
82 | 82 | ||
83 | void dump_stack(void); | ||
84 | void sighandler_dump_stack(int sig); | ||
85 | |||
86 | extern unsigned int page_size; | 83 | extern unsigned int page_size; |
87 | extern int cacheline_size; | 84 | extern int cacheline_size; |
88 | extern int sysctl_perf_event_max_stack; | 85 | extern int sysctl_perf_event_max_stack; |