rt_stat.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /******************************************************************************
  2. 版权所有:
  3. 文件名称: rt_stat.h
  4. 文件版本: 01.01
  5. 创建作者: sunxi
  6. 创建日期: 2020-06-18
  7. 功能说明:
  8. 其它说明:
  9. 修改记录:
  10. */
  11. #ifndef _RT_STAT_H
  12. #define _RT_STAT_H
  13. /*------------------------------- 头文件 --------------------------------------
  14. */
  15. /*------------------------------- 宏定义 --------------------------------------
  16. */
  17. #define RT_STAT_OTHER_NUM 8
  18. #define RT_STAT_BIG_LOOP 0
  19. /*------------------------------ 类型结构 -------------------------------------
  20. */
  21. struct rt_stat
  22. {
  23. const char * name;
  24. unsigned long min;
  25. unsigned long max;
  26. unsigned long sum;
  27. unsigned long cnt;
  28. };
  29. /*------------------------------ 函数声明 -------------------------------------
  30. */
  31. extern struct rt_stat g_stat_other[8];
  32. static inline void rt_stat_init(struct rt_stat *stat,const char *name)
  33. {
  34. stat->name = name;
  35. stat->cnt = 0;
  36. stat->sum = 0;
  37. stat->max = 0;
  38. stat->min = -1;
  39. }
  40. static inline void rt_stat_in(struct rt_stat *stat,unsigned long n)
  41. {
  42. stat->cnt++;
  43. stat->sum += n;
  44. if(n < stat->min)
  45. {
  46. stat->min = n;
  47. }
  48. if(n > stat->max)
  49. {
  50. stat->max = n;
  51. }
  52. }
  53. static inline void rt_stat_other_init(int index,const char *name)
  54. {
  55. struct rt_stat *stat = &g_stat_other[index];
  56. stat->name = name;
  57. stat->cnt = 0;
  58. stat->sum = 0;
  59. stat->max = 0;
  60. stat->min = -1;
  61. }
  62. static inline void rt_stat_other_in(int index,unsigned long n)
  63. {
  64. struct rt_stat *stat = &g_stat_other[index];
  65. stat->cnt++;
  66. stat->sum += n;
  67. if(n < stat->min)
  68. {
  69. stat->min = n;
  70. }
  71. if(n > stat->max)
  72. {
  73. stat->max = n;
  74. }
  75. }
  76. static inline void rt_stat_printf(struct rt_stat *stat)
  77. {
  78. unsigned long avg = 0;
  79. if(stat->cnt)
  80. {
  81. avg = stat->sum/stat->cnt;
  82. }
  83. rt_printf("%-24s%ld\t%ld\t%ld\t%-016ld%ld\r\n",stat->name,stat->min,stat->max,avg,stat->sum,stat->cnt);
  84. }
  85. void rt_stat_printf_q16(struct rt_stat *stat);
  86. int rt_stat_other_reset(void);
  87. int rt_stat_other_printf(void);
  88. #endif //_RT_STAT_H
  89. /*------------------------------ 文件结束 -------------------------------------
  90. */