media/libopus/silk/debug.h

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 #ifndef SILK_DEBUG_H
michael@0 29 #define SILK_DEBUG_H
michael@0 30
michael@0 31 #include "typedef.h"
michael@0 32 #include <stdio.h> /* file writing */
michael@0 33 #include <string.h> /* strcpy, strcmp */
michael@0 34
michael@0 35 #ifdef __cplusplus
michael@0 36 extern "C"
michael@0 37 {
michael@0 38 #endif
michael@0 39
michael@0 40 unsigned long GetHighResolutionTime(void); /* O time in usec*/
michael@0 41
michael@0 42 /* make SILK_DEBUG dependent on compiler's _DEBUG */
michael@0 43 #if defined _WIN32
michael@0 44 #ifdef _DEBUG
michael@0 45 #define SILK_DEBUG 1
michael@0 46 #else
michael@0 47 #define SILK_DEBUG 0
michael@0 48 #endif
michael@0 49
michael@0 50 /* overrule the above */
michael@0 51 #if 0
michael@0 52 /* #define NO_ASSERTS*/
michael@0 53 #undef SILK_DEBUG
michael@0 54 #define SILK_DEBUG 1
michael@0 55 #endif
michael@0 56 #else
michael@0 57 #define SILK_DEBUG 0
michael@0 58 #endif
michael@0 59
michael@0 60 /* Flag for using timers */
michael@0 61 #define SILK_TIC_TOC 0
michael@0 62
michael@0 63
michael@0 64 #if SILK_TIC_TOC
michael@0 65
michael@0 66 #if (defined(_WIN32) || defined(_WINCE))
michael@0 67 #include <windows.h> /* timer */
michael@0 68 #else /* Linux or Mac*/
michael@0 69 #include <sys/time.h>
michael@0 70 #endif
michael@0 71
michael@0 72 /*********************************/
michael@0 73 /* timer functions for profiling */
michael@0 74 /*********************************/
michael@0 75 /* example: */
michael@0 76 /* */
michael@0 77 /* TIC(LPC) */
michael@0 78 /* do_LPC(in_vec, order, acoef); // do LPC analysis */
michael@0 79 /* TOC(LPC) */
michael@0 80 /* */
michael@0 81 /* and call the following just before exiting (from main) */
michael@0 82 /* */
michael@0 83 /* silk_TimerSave("silk_TimingData.txt"); */
michael@0 84 /* */
michael@0 85 /* results are now in silk_TimingData.txt */
michael@0 86
michael@0 87 void silk_TimerSave(char *file_name);
michael@0 88
michael@0 89 /* max number of timers (in different locations) */
michael@0 90 #define silk_NUM_TIMERS_MAX 50
michael@0 91 /* max length of name tags in TIC(..), TOC(..) */
michael@0 92 #define silk_NUM_TIMERS_MAX_TAG_LEN 30
michael@0 93
michael@0 94 extern int silk_Timer_nTimers;
michael@0 95 extern int silk_Timer_depth_ctr;
michael@0 96 extern char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN];
michael@0 97 #ifdef _WIN32
michael@0 98 extern LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX];
michael@0 99 #else
michael@0 100 extern unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX];
michael@0 101 #endif
michael@0 102 extern unsigned int silk_Timer_cnt[silk_NUM_TIMERS_MAX];
michael@0 103 extern opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX];
michael@0 104 extern opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX];
michael@0 105 extern opus_int64 silk_Timer_min[silk_NUM_TIMERS_MAX];
michael@0 106 extern opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX];
michael@0 107
michael@0 108 /* WARNING: TIC()/TOC can measure only up to 0.1 seconds at a time */
michael@0 109 #ifdef _WIN32
michael@0 110 #define TIC(TAG_NAME) { \
michael@0 111 static int init = 0; \
michael@0 112 static int ID = -1; \
michael@0 113 if( init == 0 ) \
michael@0 114 { \
michael@0 115 int k; \
michael@0 116 init = 1; \
michael@0 117 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
michael@0 118 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
michael@0 119 ID = k; \
michael@0 120 break; \
michael@0 121 } \
michael@0 122 } \
michael@0 123 if (ID == -1) { \
michael@0 124 ID = silk_Timer_nTimers; \
michael@0 125 silk_Timer_nTimers++; \
michael@0 126 silk_Timer_depth[ID] = silk_Timer_depth_ctr; \
michael@0 127 strcpy(silk_Timer_tags[ID], #TAG_NAME); \
michael@0 128 silk_Timer_cnt[ID] = 0; \
michael@0 129 silk_Timer_sum[ID] = 0; \
michael@0 130 silk_Timer_min[ID] = 0xFFFFFFFF; \
michael@0 131 silk_Timer_max[ID] = 0; \
michael@0 132 } \
michael@0 133 } \
michael@0 134 silk_Timer_depth_ctr++; \
michael@0 135 QueryPerformanceCounter(&silk_Timer_start[ID]); \
michael@0 136 }
michael@0 137 #else
michael@0 138 #define TIC(TAG_NAME) { \
michael@0 139 static int init = 0; \
michael@0 140 static int ID = -1; \
michael@0 141 if( init == 0 ) \
michael@0 142 { \
michael@0 143 int k; \
michael@0 144 init = 1; \
michael@0 145 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
michael@0 146 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
michael@0 147 ID = k; \
michael@0 148 break; \
michael@0 149 } \
michael@0 150 } \
michael@0 151 if (ID == -1) { \
michael@0 152 ID = silk_Timer_nTimers; \
michael@0 153 silk_Timer_nTimers++; \
michael@0 154 silk_Timer_depth[ID] = silk_Timer_depth_ctr; \
michael@0 155 strcpy(silk_Timer_tags[ID], #TAG_NAME); \
michael@0 156 silk_Timer_cnt[ID] = 0; \
michael@0 157 silk_Timer_sum[ID] = 0; \
michael@0 158 silk_Timer_min[ID] = 0xFFFFFFFF; \
michael@0 159 silk_Timer_max[ID] = 0; \
michael@0 160 } \
michael@0 161 } \
michael@0 162 silk_Timer_depth_ctr++; \
michael@0 163 silk_Timer_start[ID] = GetHighResolutionTime(); \
michael@0 164 }
michael@0 165 #endif
michael@0 166
michael@0 167 #ifdef _WIN32
michael@0 168 #define TOC(TAG_NAME) { \
michael@0 169 LARGE_INTEGER lpPerformanceCount; \
michael@0 170 static int init = 0; \
michael@0 171 static int ID = 0; \
michael@0 172 if( init == 0 ) \
michael@0 173 { \
michael@0 174 int k; \
michael@0 175 init = 1; \
michael@0 176 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
michael@0 177 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
michael@0 178 ID = k; \
michael@0 179 break; \
michael@0 180 } \
michael@0 181 } \
michael@0 182 } \
michael@0 183 QueryPerformanceCounter(&lpPerformanceCount); \
michael@0 184 lpPerformanceCount.QuadPart -= silk_Timer_start[ID].QuadPart; \
michael@0 185 if((lpPerformanceCount.QuadPart < 100000000) && \
michael@0 186 (lpPerformanceCount.QuadPart >= 0)) { \
michael@0 187 silk_Timer_cnt[ID]++; \
michael@0 188 silk_Timer_sum[ID] += lpPerformanceCount.QuadPart; \
michael@0 189 if( lpPerformanceCount.QuadPart > silk_Timer_max[ID] ) \
michael@0 190 silk_Timer_max[ID] = lpPerformanceCount.QuadPart; \
michael@0 191 if( lpPerformanceCount.QuadPart < silk_Timer_min[ID] ) \
michael@0 192 silk_Timer_min[ID] = lpPerformanceCount.QuadPart; \
michael@0 193 } \
michael@0 194 silk_Timer_depth_ctr--; \
michael@0 195 }
michael@0 196 #else
michael@0 197 #define TOC(TAG_NAME) { \
michael@0 198 unsigned long endTime; \
michael@0 199 static int init = 0; \
michael@0 200 static int ID = 0; \
michael@0 201 if( init == 0 ) \
michael@0 202 { \
michael@0 203 int k; \
michael@0 204 init = 1; \
michael@0 205 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
michael@0 206 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
michael@0 207 ID = k; \
michael@0 208 break; \
michael@0 209 } \
michael@0 210 } \
michael@0 211 } \
michael@0 212 endTime = GetHighResolutionTime(); \
michael@0 213 endTime -= silk_Timer_start[ID]; \
michael@0 214 if((endTime < 100000000) && \
michael@0 215 (endTime >= 0)) { \
michael@0 216 silk_Timer_cnt[ID]++; \
michael@0 217 silk_Timer_sum[ID] += endTime; \
michael@0 218 if( endTime > silk_Timer_max[ID] ) \
michael@0 219 silk_Timer_max[ID] = endTime; \
michael@0 220 if( endTime < silk_Timer_min[ID] ) \
michael@0 221 silk_Timer_min[ID] = endTime; \
michael@0 222 } \
michael@0 223 silk_Timer_depth_ctr--; \
michael@0 224 }
michael@0 225 #endif
michael@0 226
michael@0 227 #else /* SILK_TIC_TOC */
michael@0 228
michael@0 229 /* define macros as empty strings */
michael@0 230 #define TIC(TAG_NAME)
michael@0 231 #define TOC(TAG_NAME)
michael@0 232 #define silk_TimerSave(FILE_NAME)
michael@0 233
michael@0 234 #endif /* SILK_TIC_TOC */
michael@0 235
michael@0 236
michael@0 237 #if SILK_DEBUG
michael@0 238 /************************************/
michael@0 239 /* write data to file for debugging */
michael@0 240 /************************************/
michael@0 241 /* Example: DEBUG_STORE_DATA(testfile.pcm, &RIN[0], 160*sizeof(opus_int16)); */
michael@0 242
michael@0 243 #define silk_NUM_STORES_MAX 100
michael@0 244 extern FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ];
michael@0 245 extern int silk_debug_store_count;
michael@0 246
michael@0 247 /* Faster way of storing the data */
michael@0 248 #define DEBUG_STORE_DATA( FILE_NAME, DATA_PTR, N_BYTES ) { \
michael@0 249 static opus_int init = 0, cnt = 0; \
michael@0 250 static FILE **fp; \
michael@0 251 if (init == 0) { \
michael@0 252 init = 1; \
michael@0 253 cnt = silk_debug_store_count++; \
michael@0 254 silk_debug_store_fp[ cnt ] = fopen(#FILE_NAME, "wb"); \
michael@0 255 } \
michael@0 256 fwrite((DATA_PTR), (N_BYTES), 1, silk_debug_store_fp[ cnt ]); \
michael@0 257 }
michael@0 258
michael@0 259 /* Call this at the end of main() */
michael@0 260 #define SILK_DEBUG_STORE_CLOSE_FILES { \
michael@0 261 opus_int i; \
michael@0 262 for( i = 0; i < silk_debug_store_count; i++ ) { \
michael@0 263 fclose( silk_debug_store_fp[ i ] ); \
michael@0 264 } \
michael@0 265 }
michael@0 266
michael@0 267 #else /* SILK_DEBUG */
michael@0 268
michael@0 269 /* define macros as empty strings */
michael@0 270 #define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES)
michael@0 271 #define SILK_DEBUG_STORE_CLOSE_FILES
michael@0 272
michael@0 273 #endif /* SILK_DEBUG */
michael@0 274
michael@0 275 #ifdef __cplusplus
michael@0 276 }
michael@0 277 #endif
michael@0 278
michael@0 279 #endif /* SILK_DEBUG_H */

mercurial