Yay! The SVG file is shown!
[gbricks.git] / trace.c
blobc273c242a9f1a7eac221e181dda83c78f228e5c8
1 #include <stdio.h>
2 #include <time.h>
4 /* See: http://balau82.wordpress.com/2010/10/06/trace-and-profile-function-calls-with-gcc/ */
6 # ifdef __cplusplus
7 extern "C" {
8 # endif
10 static FILE *fp_trace;
12 void __attribute__ ((constructor)) trace_begin (void) __attribute__ ((no_instrument_function));
13 void __attribute__ ((destructor)) trace_end (void) __attribute__ ((no_instrument_function));
14 void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));
15 void __cyg_profile_func_exit( void *, void * ) __attribute__ ((no_instrument_function));
18 void __attribute__ ((constructor)) trace_begin (void)
20 fp_trace = fopen("trace.out", "w");
23 void __attribute__ ((destructor)) trace_end (void)
25 if(fp_trace != NULL) {
26 fclose(fp_trace);
30 void __cyg_profile_func_enter (void *func, void *caller)
32 if(fp_trace != NULL) {
33 fprintf(fp_trace, "e %p %p %lu\n", func, caller, time(NULL) );
37 void __cyg_profile_func_exit (void *func, void *caller)
39 if(fp_trace != NULL) {
40 fprintf(fp_trace, "x %p %p %lu\n", func, caller, time(NULL));
44 # ifdef __cplusplus
46 # endif