perf_trace.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #define FRAMES_TO_MS(f) output.current_sample_rate>0?1000*f/output.current_sample_rate:LONG_MIN
  3. #define BYTES_TO_MS(b) FRAMES_TO_MS(BYTES_TO_FRAME(b))
  4. #define LINE_MIN_MAX_FORMAT "%14s%10d|%10d|%11d|" " |%10d|%10d|%16d|"
  5. #define LINE_MIN_MAX_DURATION_FORMAT "%14s%10d|%10d|%11d|"
  6. #define LINE_MIN_MAX_FORMAT_STREAM "%14s%10s|%10s|%11s|" " |%10d|%10d|%16d|"
  7. #define SET_MIN_MAX(val,var) var=val; if(var<min_##var) min_##var=var; if(var>max_##var) max_##var=var
  8. #define RESET_MIN_MAX(var,mv) min_##var=mv##_MAX; max_##var=mv##_MIN
  9. #define DECLARE_MIN_MAX(var,t,mv) static t min_##var = mv##_MAX, max_##var = mv##_MIN; t var=0
  10. #define LINE_MIN_MAX(name,var) name,BYTES_TO_MS(max_##var), BYTES_TO_MS(min_##var),BYTES_TO_MS( var),max_##var,min_##var,var
  11. #define LINE_MIN_MAX_STREAM(name,var) name,"n/a","n/a","n/a",max_##var,min_##var,var
  12. #define LINE_MIN_MAX_DURATION(name,var) name,max_##var, min_##var, var
  13. #define TIME_MEASUREMENT_START(x) x=esp_timer_get_time()
  14. #define TIME_MEASUREMENT_GET(x) (esp_timer_get_time()-x)/1000
  15. #define TIMED_SECTION_START_MS_FORCE(x,force) if(hasTimeElapsed(x,force)) {
  16. #define TIMED_SECTION_START_MS(x) if(hasTimeElapsed(x,false)){
  17. #define TIMED_SECTION_START_FORCE(x,force) TIMED_SECTION_START_MS(x * 1000UL,force)
  18. #define TIMED_SECTION_START(x) TIMED_SECTION_START_MS(x * 1000UL)
  19. #define TIMED_SECTION_END }
  20. static inline bool hasTimeElapsed(time_t delayMS, bool bforce)
  21. {
  22. static time_t lastTime=0;
  23. if (lastTime <= gettime_ms() ||bforce)
  24. {
  25. lastTime = gettime_ms() + delayMS;
  26. return true;
  27. }
  28. else
  29. return false;
  30. }
  31. //#define MAX_PERF_NAME_LEN 10
  32. //#define MAX_PERF_FORMAT_LEN 12
  33. //typedef enum {BUFFER_TYPE,DURATION_TYPE,LAST } perf_formats;
  34. //typedef struct _perf_stats {
  35. // uint32_t min;
  36. // uint32_t max;
  37. // uint32_t current;
  38. // char name[MAX_PERF_NAME_LEN+1];
  39. // uint32_t timer_start;
  40. // perf_formats fmt;
  41. //} perf_stats;