simple_profile.h

00001 #ifndef __SIMPLE_PROFILE_H
00002 #define __SIMPLE_PROFILE_H
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007         
00008 typedef void(*trace_f)();
00009 
00010 int start_profile(trace_f tf);
00011 int stop_profile();
00012 
00013 /* do NOT use this directly ! */
00014 extern unsigned int tick_counter;
00015 
00016 #define get_prof_time() tick_counter
00017 
00018 typedef struct {
00019         int count;
00020         int start_count, stop_count;
00021         unsigned int spent_time;
00022 } profile_data_t;
00023 
00024 #define DEFINE_PROF_POINT(name) profile_data_t prof_##name = { 0, 0, 0 };
00025 #define DECLARE_PROF_POINT(name) extern profile_data_t prof_##name;
00026 
00027 #define prof_point(name)        prof_##name
00028 #define PROF_START_DECL(name)   int _prof_act_##name;
00029 #define PROF_START_BODY(name)   prof_point(name).count++; \
00030                                                         prof_point(name).start_count++; \
00031                                                         _prof_act_##name = get_prof_time();
00032 
00033 #define PROF_START(name)        int _prof_act_##name; \
00034                                                         prof_point(name).count++; \
00035                                                         prof_point(name).start_count++; \
00036                                                         _prof_act_##name = get_prof_time();
00037 
00038 #define PROF_STOP(name) prof_point(name).stop_count++; \
00039                                                 prof_point(name).spent_time += get_prof_time() - _prof_act_##name;
00040 
00041 #define prof_return(a, val)     prof_stop(a) return val;
00042 
00043 #ifdef __cplusplus
00044 }
00045 #endif
00046  
00047 #endif