FreeRTOS Tetris
tracer.h
1 #ifndef __TRACER_H__
2 #define __TRACER_H__
3 #include <time.h>
4 #include <stdio.h>
5 
6 static FILE *fp_trace = NULL;
7 
8 void __attribute__((constructor)) trace_begin(void)
9 {
10  fp_trace = fopen("trace.out", "w");
11 }
12 
13 void __attribute__((destructor)) trace_end(void)
14 {
15  if (fp_trace) {
16  fclose(fp_trace);
17  }
18 }
19 
20 void __attribute((no_instrument_function))
21 __cyg_profile_func_enter(void *func, void *caller)
22 {
23  if (fp_trace) {
24  fprintf(fp_trace, "e %p %p %lu\n", func, caller, time(NULL));
25  }
26 }
27 
28 void __attribute((no_instrument_function))
29 __cyg_profile_func_exit(void *func, void *caller)
30 {
31  if (fp_trace) {
32  fprintf(fp_trace, "x %p %p %lu\n", func, caller, time(NULL));
33  }
34 }
35 #endif