diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2012-10-08 02:43:26 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-08 16:38:25 -0400 |
commit | 78da39faf7c903bb6e3c20a726fde1bf98d10af8 (patch) | |
tree | c3aa294624d66d52ce6952568ac95880c202a16a /tools/perf/builtin-record.c | |
parent | 355afe816312faf20d81fdcade29e0361d72a7b4 (diff) |
perf tools: Add on_exit implementation
on_exit() is only available in new versions of glibc.
It is not implemented in Bionic and will lead to linking errors when
compiling for Android.
Implement a wrapper for on_exit using atexit.
The implementation for on_exit is the one sent by Bernhard Rosenkraenzer in
https://lkml.org/lkml/2012/8/23/316. The configuration part from the Makefile
is different than the one from the original patch.
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Irina Tirdea <irina.tirdea@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1349678613-7045-2-git-send-email-irina.tirdea@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r-- | tools/perf/builtin-record.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 |