diff options
-rw-r--r-- | tools/perf/Makefile | 6 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 32 | ||||
-rw-r--r-- | tools/perf/config/feature-tests.mak | 11 |
3 files changed, 48 insertions, 1 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d80a33324785..a7d8745e0ab2 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -753,6 +753,12 @@ ifndef NO_STRLCPY | |||
753 | endif | 753 | endif |
754 | endif | 754 | endif |
755 | 755 | ||
756 | ifndef NO_ON_EXIT | ||
757 | ifeq ($(call try-cc,$(SOURCE_ON_EXIT),),y) | ||
758 | BASIC_CFLAGS += -DHAVE_ON_EXIT | ||
759 | endif | ||
760 | endif | ||
761 | |||
756 | ifndef NO_BACKTRACE | 762 | ifndef NO_BACKTRACE |
757 | ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y) | 763 | ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y) |
758 | BASIC_CFLAGS += -DBACKTRACE_SUPPORT | 764 | BASIC_CFLAGS += -DBACKTRACE_SUPPORT |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e9231659754d..73b5d7f91194 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -31,6 +31,38 @@ | |||
31 | #include <sched.h> | 31 | #include <sched.h> |
32 | #include <sys/mman.h> | 32 | #include <sys/mman.h> |
33 | 33 | ||
34 | #ifndef HAVE_ON_EXIT | ||
35 | #ifndef ATEXIT_MAX | ||
36 | #define ATEXIT_MAX 32 | ||
37 | #endif | ||
38 | static int __on_exit_count = 0; | ||
39 | typedef void (*on_exit_func_t) (int, void *); | ||
40 | static on_exit_func_t __on_exit_funcs[ATEXIT_MAX]; | ||
41 | static void *__on_exit_args[ATEXIT_MAX]; | ||
42 | static int __exitcode = 0; | ||
43 | static void __handle_on_exit_funcs(void); | ||
44 | static int on_exit(on_exit_func_t function, void *arg); | ||
45 | #define exit(x) (exit)(__exitcode = (x)) | ||
46 | |||
47 | static int on_exit(on_exit_func_t function, void *arg) | ||
48 | { | ||
49 | if (__on_exit_count == ATEXIT_MAX) | ||
50 | return -ENOMEM; | ||
51 | else if (__on_exit_count == 0) | ||
52 | atexit(__handle_on_exit_funcs); | ||
53 | __on_exit_funcs[__on_exit_count] = function; | ||
54 | __on_exit_args[__on_exit_count++] = arg; | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static void __handle_on_exit_funcs(void) | ||
59 | { | ||
60 | int i; | ||
61 | for (i = 0; i < __on_exit_count; i++) | ||
62 | __on_exit_funcs[i] (__exitcode, __on_exit_args[i]); | ||
63 | } | ||
64 | #endif | ||
65 | |||
34 | enum write_mode_t { | 66 | enum write_mode_t { |
35 | WRITE_FORCE, | 67 | WRITE_FORCE, |
36 | WRITE_APPEND | 68 | WRITE_APPEND |
diff --git a/tools/perf/config/feature-tests.mak b/tools/perf/config/feature-tests.mak index 4add41bb0c7e..eaeb0fd6f395 100644 --- a/tools/perf/config/feature-tests.mak +++ b/tools/perf/config/feature-tests.mak | |||
@@ -203,4 +203,13 @@ int main(void) | |||
203 | return audit_open(); | 203 | return audit_open(); |
204 | } | 204 | } |
205 | endef | 205 | endef |
206 | endif \ No newline at end of file | 206 | endif |
207 | |||
208 | define SOURCE_ON_EXIT | ||
209 | #include <stdio.h> | ||
210 | |||
211 | int main(void) | ||
212 | { | ||
213 | return on_exit(NULL, NULL); | ||
214 | } | ||
215 | endef | ||