Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338872
b: refs/heads/master
c: 78da39f
h: refs/heads/master
v: v3
  • Loading branch information
Bernhard Rosenkraenzer authored and Arnaldo Carvalho de Melo committed Oct 8, 2012
1 parent 1640c77 commit 7a3e6b4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 355afe816312faf20d81fdcade29e0361d72a7b4
refs/heads/master: 78da39faf7c903bb6e3c20a726fde1bf98d10af8
6 changes: 6 additions & 0 deletions trunk/tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,12 @@ ifndef NO_STRLCPY
endif
endif

ifndef NO_ON_EXIT
ifeq ($(call try-cc,$(SOURCE_ON_EXIT),),y)
BASIC_CFLAGS += -DHAVE_ON_EXIT
endif
endif

ifndef NO_BACKTRACE
ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
BASIC_CFLAGS += -DBACKTRACE_SUPPORT
Expand Down
32 changes: 32 additions & 0 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@
#include <sched.h>
#include <sys/mman.h>

#ifndef HAVE_ON_EXIT
#ifndef ATEXIT_MAX
#define ATEXIT_MAX 32
#endif
static int __on_exit_count = 0;
typedef void (*on_exit_func_t) (int, void *);
static on_exit_func_t __on_exit_funcs[ATEXIT_MAX];
static void *__on_exit_args[ATEXIT_MAX];
static int __exitcode = 0;
static void __handle_on_exit_funcs(void);
static int on_exit(on_exit_func_t function, void *arg);
#define exit(x) (exit)(__exitcode = (x))

static int on_exit(on_exit_func_t function, void *arg)
{
if (__on_exit_count == ATEXIT_MAX)
return -ENOMEM;
else if (__on_exit_count == 0)
atexit(__handle_on_exit_funcs);
__on_exit_funcs[__on_exit_count] = function;
__on_exit_args[__on_exit_count++] = arg;
return 0;
}

static void __handle_on_exit_funcs(void)
{
int i;
for (i = 0; i < __on_exit_count; i++)
__on_exit_funcs[i] (__exitcode, __on_exit_args[i]);
}
#endif

enum write_mode_t {
WRITE_FORCE,
WRITE_APPEND
Expand Down
11 changes: 10 additions & 1 deletion trunk/tools/perf/config/feature-tests.mak
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,13 @@ int main(void)
return audit_open();
}
endef
endif
endif

define SOURCE_ON_EXIT
#include <stdio.h>

int main(void)
{
return on_exit(NULL, NULL);
}
endef

0 comments on commit 7a3e6b4

Please sign in to comment.