debug.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /***********************************************************************
  2. Copyright (c) 2006-2011, Skype Limited. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  12. names of specific contributors, may be used to endorse or promote
  13. products derived from this software without specific prior written
  14. permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. ***********************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "debug.h"
  31. #include "SigProc_FIX.h"
  32. #if SILK_TIC_TOC
  33. #ifdef _WIN32
  34. #if (defined(_WIN32) || defined(_WINCE))
  35. #include <windows.h> /* timer */
  36. #else /* Linux or Mac*/
  37. #include <sys/time.h>
  38. #endif
  39. unsigned long silk_GetHighResolutionTime(void) /* O time in usec*/
  40. {
  41. /* Returns a time counter in microsec */
  42. /* the resolution is platform dependent */
  43. /* but is typically 1.62 us resolution */
  44. LARGE_INTEGER lpPerformanceCount;
  45. LARGE_INTEGER lpFrequency;
  46. QueryPerformanceCounter(&lpPerformanceCount);
  47. QueryPerformanceFrequency(&lpFrequency);
  48. return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart);
  49. }
  50. #else /* Linux or Mac*/
  51. unsigned long GetHighResolutionTime(void) /* O time in usec*/
  52. {
  53. struct timeval tv;
  54. gettimeofday(&tv, 0);
  55. return((tv.tv_sec*1000000)+(tv.tv_usec));
  56. }
  57. #endif
  58. int silk_Timer_nTimers = 0;
  59. int silk_Timer_depth_ctr = 0;
  60. char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN];
  61. #ifdef WIN32
  62. LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX];
  63. #else
  64. unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX];
  65. #endif
  66. unsigned int silk_Timer_cnt[silk_NUM_TIMERS_MAX];
  67. opus_int64 silk_Timer_min[silk_NUM_TIMERS_MAX];
  68. opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX];
  69. opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX];
  70. opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX];
  71. #ifdef WIN32
  72. void silk_TimerSave(char *file_name)
  73. {
  74. if( silk_Timer_nTimers > 0 )
  75. {
  76. int k;
  77. FILE *fp;
  78. LARGE_INTEGER lpFrequency;
  79. LARGE_INTEGER lpPerformanceCount1, lpPerformanceCount2;
  80. int del = 0x7FFFFFFF;
  81. double avg, sum_avg;
  82. /* estimate overhead of calling performance counters */
  83. for( k = 0; k < 1000; k++ ) {
  84. QueryPerformanceCounter(&lpPerformanceCount1);
  85. QueryPerformanceCounter(&lpPerformanceCount2);
  86. lpPerformanceCount2.QuadPart -= lpPerformanceCount1.QuadPart;
  87. if( (int)lpPerformanceCount2.LowPart < del )
  88. del = lpPerformanceCount2.LowPart;
  89. }
  90. QueryPerformanceFrequency(&lpFrequency);
  91. /* print results to file */
  92. sum_avg = 0.0f;
  93. for( k = 0; k < silk_Timer_nTimers; k++ ) {
  94. if (silk_Timer_depth[k] == 0) {
  95. sum_avg += (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart * silk_Timer_cnt[k];
  96. }
  97. }
  98. fp = fopen(file_name, "w");
  99. fprintf(fp, " min avg %% max count\n");
  100. for( k = 0; k < silk_Timer_nTimers; k++ ) {
  101. if (silk_Timer_depth[k] == 0) {
  102. fprintf(fp, "%-28s", silk_Timer_tags[k]);
  103. } else if (silk_Timer_depth[k] == 1) {
  104. fprintf(fp, " %-27s", silk_Timer_tags[k]);
  105. } else if (silk_Timer_depth[k] == 2) {
  106. fprintf(fp, " %-26s", silk_Timer_tags[k]);
  107. } else if (silk_Timer_depth[k] == 3) {
  108. fprintf(fp, " %-25s", silk_Timer_tags[k]);
  109. } else {
  110. fprintf(fp, " %-24s", silk_Timer_tags[k]);
  111. }
  112. avg = (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart;
  113. fprintf(fp, "%8.2f", (1e6 * (silk_max_64(silk_Timer_min[k] - del, 0))) / lpFrequency.QuadPart);
  114. fprintf(fp, "%12.2f %6.2f", avg, 100.0 * avg / sum_avg * silk_Timer_cnt[k]);
  115. fprintf(fp, "%12.2f", (1e6 * (silk_max_64(silk_Timer_max[k] - del, 0))) / lpFrequency.QuadPart);
  116. fprintf(fp, "%10d\n", silk_Timer_cnt[k]);
  117. }
  118. fprintf(fp, " microseconds\n");
  119. fclose(fp);
  120. }
  121. }
  122. #else
  123. void silk_TimerSave(char *file_name)
  124. {
  125. if( silk_Timer_nTimers > 0 )
  126. {
  127. int k;
  128. FILE *fp;
  129. /* print results to file */
  130. fp = fopen(file_name, "w");
  131. fprintf(fp, " min avg max count\n");
  132. for( k = 0; k < silk_Timer_nTimers; k++ )
  133. {
  134. if (silk_Timer_depth[k] == 0) {
  135. fprintf(fp, "%-28s", silk_Timer_tags[k]);
  136. } else if (silk_Timer_depth[k] == 1) {
  137. fprintf(fp, " %-27s", silk_Timer_tags[k]);
  138. } else if (silk_Timer_depth[k] == 2) {
  139. fprintf(fp, " %-26s", silk_Timer_tags[k]);
  140. } else if (silk_Timer_depth[k] == 3) {
  141. fprintf(fp, " %-25s", silk_Timer_tags[k]);
  142. } else {
  143. fprintf(fp, " %-24s", silk_Timer_tags[k]);
  144. }
  145. fprintf(fp, "%d ", silk_Timer_min[k]);
  146. fprintf(fp, "%f ", (double)silk_Timer_sum[k] / (double)silk_Timer_cnt[k]);
  147. fprintf(fp, "%d ", silk_Timer_max[k]);
  148. fprintf(fp, "%10d\n", silk_Timer_cnt[k]);
  149. }
  150. fprintf(fp, " microseconds\n");
  151. fclose(fp);
  152. }
  153. }
  154. #endif
  155. #endif /* SILK_TIC_TOC */
  156. #if SILK_DEBUG
  157. FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ];
  158. int silk_debug_store_count = 0;
  159. #endif /* SILK_DEBUG */