media/libopus/silk/debug.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial