1 #include <libextl/extl.h>
4 #ifdef PROFILING_ENABLED
9 #include <libextl/extl.h>
11 static FILE *fp_trace
;
12 struct timespec
*current_time
;
15 __cyg_profile_func_enter (void *func
, void *caller
)
17 if(fp_trace
!= NULL
) {
18 clock_gettime(CLOCK_REALTIME
, current_time
);
19 fprintf(fp_trace
, "e\t%p\t%p\t%ld.%09lu\n", func
, caller
, current_time
->tv_sec
, current_time
->tv_nsec
);
25 __cyg_profile_func_exit (void *func
, void *caller
)
27 if(fp_trace
!= NULL
) {
28 clock_gettime(CLOCK_REALTIME
, current_time
);
29 fprintf(fp_trace
, "x\t%p\t%p\t%ld.%09lu\n", func
, caller
, current_time
->tv_sec
, current_time
->tv_nsec
);
34 void profileLuaCall(const enum ExtlHookEvent event
, const char *name
, const char *source
, int currentline
) {
35 if(fp_trace
!= NULL
) {
36 clock_gettime(CLOCK_REALTIME
, current_time
);
37 if(event
== EXTL_HOOK_ENTER
)
38 fprintf(fp_trace
, "e\t%s %s:%d\t\t%ld.%09lu\n", name
, source
, currentline
, current_time
->tv_sec
, current_time
->tv_nsec
);
39 else if (event
== EXTL_HOOK_EXIT
)
40 fprintf(fp_trace
, "x\t%s %s:%d\t\t%ld.%09lu\n", name
, source
, currentline
, current_time
->tv_sec
, current_time
->tv_nsec
);
48 * Start profiling (if enabled at compile-time)
52 void ioncore_profiling_start(char* filename
) {
53 #ifdef PROFILING_ENABLED
54 current_time
= malloc(sizeof(struct timespec
));
55 fp_trace
= fopen(filename
, "w");
56 extl_sethook(profileLuaCall
);
61 * Stop profiling (if enabled at compile-time)
65 void ioncore_profiling_stop() {
66 #ifdef PROFILING_ENABLED
67 FILE *fp_trace_to_close
= fp_trace
;
70 if(fp_trace_to_close
!= NULL
) {
71 fflush(fp_trace_to_close
);
72 fclose(fp_trace_to_close
);