rt_stat.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /******************************************************************************
  2. 版权所有:
  3. 文件名称: rt_stat.c
  4. 文件版本: 01.01
  5. 创建作者: sunxi
  6. 创建日期: 2020-06-18
  7. 功能说明: 实时统计。
  8. 其它说明:
  9. 修改记录:
  10. */
  11. /*------------------------------- 头文件 --------------------------------------
  12. */
  13. #include "rt.h"
  14. /*------------------------------- 宏定义 --------------------------------------
  15. */
  16. /*------------------------------ 类型结构 -------------------------------------
  17. */
  18. /*------------------------------ 全局变量 -------------------------------------
  19. */
  20. struct rt_stat g_stat_other[RT_STAT_OTHER_NUM] =
  21. {
  22. {"other0", -1, 0, 0, 0},
  23. {"other1", -1, 0, 0, 0},
  24. {"other2", -1, 0, 0, 0},
  25. {"other3", -1, 0, 0, 0},
  26. {"other4", -1, 0, 0, 0},
  27. {"other5", -1, 0, 0, 0},
  28. {"other6", -1, 0, 0, 0},
  29. {"other7", -1, 0, 0, 0},
  30. };
  31. /*------------------------------ 函数声明 -------------------------------------
  32. */
  33. /*------------------------------ 外部函数 -------------------------------------
  34. 外部函数供其它实体文件引用,必须仔细检查传入参数的合法性.
  35. */
  36. static char * q16_to_str(long q16)
  37. {
  38. static char str[32];
  39. sprintf(str,"%f",(float)q16/Q16_BASE);
  40. return str;
  41. }
  42. void rt_stat_printf_q16(struct rt_stat *stat)
  43. {
  44. unsigned long avg = 0;
  45. if(stat->cnt)
  46. {
  47. avg = stat->sum/stat->cnt;
  48. }
  49. rt_printf("%-24s",stat->name);
  50. rt_printf("%s\t",q16_to_str((long)stat->min));
  51. rt_printf("%s\t",q16_to_str((long)stat->max));
  52. rt_printf("%s\t",q16_to_str((long)avg));
  53. rt_printf("%-16lu%lu\r\n",stat->sum,stat->cnt);
  54. return;
  55. }
  56. int rt_stat_other_reset(void)
  57. {
  58. int i;
  59. for(i=0; i<RT_STAT_OTHER_NUM; i++)
  60. {
  61. rt_stat_init(&g_stat_other[i],g_stat_other[i].name);
  62. }
  63. return 0;
  64. }
  65. int rt_stat_other_printf(void)
  66. {
  67. int i;
  68. rt_printf("\r\n[其它时间统计(单位:us)]\r\n");
  69. for(i=0; i<RT_STAT_OTHER_NUM; i++)
  70. {
  71. rt_stat_printf(&g_stat_other[i]);
  72. }
  73. return 0;
  74. }
  75. /*------------------------------ 内部函数 -------------------------------------
  76. 内部函数以下划线‘_’开头,不需要检查参数的合法性.
  77. */
  78. /*------------------------------ 测试函数 -------------------------------------
  79. 一个实体文件必须带一个本模块的测试函数来进行单元测试,如果的确不方便在本模块中
  80. 进行单元测试,必须在此注明实际的测试位置(例如在哪个实体文件中使用哪个测试函数).
  81. */
  82. /*------------------------------ 文件结束 -------------------------------------
  83. */