simple_profile.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef __SIMPLE_PROFILE_H
  2. #define __SIMPLE_PROFILE_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef void(*trace_f)();
  7. int start_profile(trace_f tf);
  8. int stop_profile();
  9. /* do NOT use this directly ! */
  10. extern unsigned int tick_counter;
  11. #define get_prof_time() tick_counter
  12. typedef struct {
  13. int count;
  14. int start_count, stop_count;
  15. unsigned int spent_time;
  16. } profile_data_t;
  17. #define DEFINE_PROF_POINT(name) profile_data_t prof_##name = { 0, 0, 0 };
  18. #define DECLARE_PROF_POINT(name) extern profile_data_t prof_##name;
  19. #define prof_point(name) prof_##name
  20. #define PROF_START_DECL(name) int _prof_act_##name;
  21. #define PROF_START_BODY(name) prof_point(name).count++; \
  22. prof_point(name).start_count++; \
  23. _prof_act_##name = get_prof_time();
  24. #define PROF_START(name) int _prof_act_##name; \
  25. prof_point(name).count++; \
  26. prof_point(name).start_count++; \
  27. _prof_act_##name = get_prof_time();
  28. #define PROF_STOP(name) prof_point(name).stop_count++; \
  29. prof_point(name).spent_time += get_prof_time() - _prof_act_##name;
  30. #define prof_return(a, val) prof_stop(a) return val;
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #endif