annotate src/opus-1.3/silk/debug.h @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /***********************************************************************
Chris@69 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Chris@69 3 Redistribution and use in source and binary forms, with or without
Chris@69 4 modification, are permitted provided that the following conditions
Chris@69 5 are met:
Chris@69 6 - Redistributions of source code must retain the above copyright notice,
Chris@69 7 this list of conditions and the following disclaimer.
Chris@69 8 - Redistributions in binary form must reproduce the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer in the
Chris@69 10 documentation and/or other materials provided with the distribution.
Chris@69 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
Chris@69 12 names of specific contributors, may be used to endorse or promote
Chris@69 13 products derived from this software without specific prior written
Chris@69 14 permission.
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@69 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@69 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Chris@69 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Chris@69 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Chris@69 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Chris@69 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Chris@69 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Chris@69 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Chris@69 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Chris@69 25 POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 ***********************************************************************/
Chris@69 27
Chris@69 28 #ifndef SILK_DEBUG_H
Chris@69 29 #define SILK_DEBUG_H
Chris@69 30
Chris@69 31 #include "typedef.h"
Chris@69 32 #include <stdio.h> /* file writing */
Chris@69 33 #include <string.h> /* strcpy, strcmp */
Chris@69 34
Chris@69 35 #ifdef __cplusplus
Chris@69 36 extern "C"
Chris@69 37 {
Chris@69 38 #endif
Chris@69 39
Chris@69 40 unsigned long GetHighResolutionTime(void); /* O time in usec*/
Chris@69 41
Chris@69 42 /* Set to 1 to enable DEBUG_STORE_DATA() macros for dumping
Chris@69 43 * intermediate signals from the codec.
Chris@69 44 */
Chris@69 45 #define SILK_DEBUG 0
Chris@69 46
Chris@69 47 /* Flag for using timers */
Chris@69 48 #define SILK_TIC_TOC 0
Chris@69 49
Chris@69 50
Chris@69 51 #if SILK_TIC_TOC
Chris@69 52
Chris@69 53 #if (defined(_WIN32) || defined(_WINCE))
Chris@69 54 #include <windows.h> /* timer */
Chris@69 55 #else /* Linux or Mac*/
Chris@69 56 #include <sys/time.h>
Chris@69 57 #endif
Chris@69 58
Chris@69 59 /*********************************/
Chris@69 60 /* timer functions for profiling */
Chris@69 61 /*********************************/
Chris@69 62 /* example: */
Chris@69 63 /* */
Chris@69 64 /* TIC(LPC) */
Chris@69 65 /* do_LPC(in_vec, order, acoef); // do LPC analysis */
Chris@69 66 /* TOC(LPC) */
Chris@69 67 /* */
Chris@69 68 /* and call the following just before exiting (from main) */
Chris@69 69 /* */
Chris@69 70 /* silk_TimerSave("silk_TimingData.txt"); */
Chris@69 71 /* */
Chris@69 72 /* results are now in silk_TimingData.txt */
Chris@69 73
Chris@69 74 void silk_TimerSave(char *file_name);
Chris@69 75
Chris@69 76 /* max number of timers (in different locations) */
Chris@69 77 #define silk_NUM_TIMERS_MAX 50
Chris@69 78 /* max length of name tags in TIC(..), TOC(..) */
Chris@69 79 #define silk_NUM_TIMERS_MAX_TAG_LEN 30
Chris@69 80
Chris@69 81 extern int silk_Timer_nTimers;
Chris@69 82 extern int silk_Timer_depth_ctr;
Chris@69 83 extern char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN];
Chris@69 84 #ifdef _WIN32
Chris@69 85 extern LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX];
Chris@69 86 #else
Chris@69 87 extern unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX];
Chris@69 88 #endif
Chris@69 89 extern unsigned int silk_Timer_cnt[silk_NUM_TIMERS_MAX];
Chris@69 90 extern opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX];
Chris@69 91 extern opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX];
Chris@69 92 extern opus_int64 silk_Timer_min[silk_NUM_TIMERS_MAX];
Chris@69 93 extern opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX];
Chris@69 94
Chris@69 95 /* WARNING: TIC()/TOC can measure only up to 0.1 seconds at a time */
Chris@69 96 #ifdef _WIN32
Chris@69 97 #define TIC(TAG_NAME) { \
Chris@69 98 static int init = 0; \
Chris@69 99 static int ID = -1; \
Chris@69 100 if( init == 0 ) \
Chris@69 101 { \
Chris@69 102 int k; \
Chris@69 103 init = 1; \
Chris@69 104 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
Chris@69 105 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
Chris@69 106 ID = k; \
Chris@69 107 break; \
Chris@69 108 } \
Chris@69 109 } \
Chris@69 110 if (ID == -1) { \
Chris@69 111 ID = silk_Timer_nTimers; \
Chris@69 112 silk_Timer_nTimers++; \
Chris@69 113 silk_Timer_depth[ID] = silk_Timer_depth_ctr; \
Chris@69 114 strcpy(silk_Timer_tags[ID], #TAG_NAME); \
Chris@69 115 silk_Timer_cnt[ID] = 0; \
Chris@69 116 silk_Timer_sum[ID] = 0; \
Chris@69 117 silk_Timer_min[ID] = 0xFFFFFFFF; \
Chris@69 118 silk_Timer_max[ID] = 0; \
Chris@69 119 } \
Chris@69 120 } \
Chris@69 121 silk_Timer_depth_ctr++; \
Chris@69 122 QueryPerformanceCounter(&silk_Timer_start[ID]); \
Chris@69 123 }
Chris@69 124 #else
Chris@69 125 #define TIC(TAG_NAME) { \
Chris@69 126 static int init = 0; \
Chris@69 127 static int ID = -1; \
Chris@69 128 if( init == 0 ) \
Chris@69 129 { \
Chris@69 130 int k; \
Chris@69 131 init = 1; \
Chris@69 132 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
Chris@69 133 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
Chris@69 134 ID = k; \
Chris@69 135 break; \
Chris@69 136 } \
Chris@69 137 } \
Chris@69 138 if (ID == -1) { \
Chris@69 139 ID = silk_Timer_nTimers; \
Chris@69 140 silk_Timer_nTimers++; \
Chris@69 141 silk_Timer_depth[ID] = silk_Timer_depth_ctr; \
Chris@69 142 strcpy(silk_Timer_tags[ID], #TAG_NAME); \
Chris@69 143 silk_Timer_cnt[ID] = 0; \
Chris@69 144 silk_Timer_sum[ID] = 0; \
Chris@69 145 silk_Timer_min[ID] = 0xFFFFFFFF; \
Chris@69 146 silk_Timer_max[ID] = 0; \
Chris@69 147 } \
Chris@69 148 } \
Chris@69 149 silk_Timer_depth_ctr++; \
Chris@69 150 silk_Timer_start[ID] = GetHighResolutionTime(); \
Chris@69 151 }
Chris@69 152 #endif
Chris@69 153
Chris@69 154 #ifdef _WIN32
Chris@69 155 #define TOC(TAG_NAME) { \
Chris@69 156 LARGE_INTEGER lpPerformanceCount; \
Chris@69 157 static int init = 0; \
Chris@69 158 static int ID = 0; \
Chris@69 159 if( init == 0 ) \
Chris@69 160 { \
Chris@69 161 int k; \
Chris@69 162 init = 1; \
Chris@69 163 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
Chris@69 164 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
Chris@69 165 ID = k; \
Chris@69 166 break; \
Chris@69 167 } \
Chris@69 168 } \
Chris@69 169 } \
Chris@69 170 QueryPerformanceCounter(&lpPerformanceCount); \
Chris@69 171 lpPerformanceCount.QuadPart -= silk_Timer_start[ID].QuadPart; \
Chris@69 172 if((lpPerformanceCount.QuadPart < 100000000) && \
Chris@69 173 (lpPerformanceCount.QuadPart >= 0)) { \
Chris@69 174 silk_Timer_cnt[ID]++; \
Chris@69 175 silk_Timer_sum[ID] += lpPerformanceCount.QuadPart; \
Chris@69 176 if( lpPerformanceCount.QuadPart > silk_Timer_max[ID] ) \
Chris@69 177 silk_Timer_max[ID] = lpPerformanceCount.QuadPart; \
Chris@69 178 if( lpPerformanceCount.QuadPart < silk_Timer_min[ID] ) \
Chris@69 179 silk_Timer_min[ID] = lpPerformanceCount.QuadPart; \
Chris@69 180 } \
Chris@69 181 silk_Timer_depth_ctr--; \
Chris@69 182 }
Chris@69 183 #else
Chris@69 184 #define TOC(TAG_NAME) { \
Chris@69 185 unsigned long endTime; \
Chris@69 186 static int init = 0; \
Chris@69 187 static int ID = 0; \
Chris@69 188 if( init == 0 ) \
Chris@69 189 { \
Chris@69 190 int k; \
Chris@69 191 init = 1; \
Chris@69 192 for( k = 0; k < silk_Timer_nTimers; k++ ) { \
Chris@69 193 if( strcmp(silk_Timer_tags[k], #TAG_NAME) == 0 ) { \
Chris@69 194 ID = k; \
Chris@69 195 break; \
Chris@69 196 } \
Chris@69 197 } \
Chris@69 198 } \
Chris@69 199 endTime = GetHighResolutionTime(); \
Chris@69 200 endTime -= silk_Timer_start[ID]; \
Chris@69 201 if((endTime < 100000000) && \
Chris@69 202 (endTime >= 0)) { \
Chris@69 203 silk_Timer_cnt[ID]++; \
Chris@69 204 silk_Timer_sum[ID] += endTime; \
Chris@69 205 if( endTime > silk_Timer_max[ID] ) \
Chris@69 206 silk_Timer_max[ID] = endTime; \
Chris@69 207 if( endTime < silk_Timer_min[ID] ) \
Chris@69 208 silk_Timer_min[ID] = endTime; \
Chris@69 209 } \
Chris@69 210 silk_Timer_depth_ctr--; \
Chris@69 211 }
Chris@69 212 #endif
Chris@69 213
Chris@69 214 #else /* SILK_TIC_TOC */
Chris@69 215
Chris@69 216 /* define macros as empty strings */
Chris@69 217 #define TIC(TAG_NAME)
Chris@69 218 #define TOC(TAG_NAME)
Chris@69 219 #define silk_TimerSave(FILE_NAME)
Chris@69 220
Chris@69 221 #endif /* SILK_TIC_TOC */
Chris@69 222
Chris@69 223
Chris@69 224 #if SILK_DEBUG
Chris@69 225 /************************************/
Chris@69 226 /* write data to file for debugging */
Chris@69 227 /************************************/
Chris@69 228 /* Example: DEBUG_STORE_DATA(testfile.pcm, &RIN[0], 160*sizeof(opus_int16)); */
Chris@69 229
Chris@69 230 #define silk_NUM_STORES_MAX 100
Chris@69 231 extern FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ];
Chris@69 232 extern int silk_debug_store_count;
Chris@69 233
Chris@69 234 /* Faster way of storing the data */
Chris@69 235 #define DEBUG_STORE_DATA( FILE_NAME, DATA_PTR, N_BYTES ) { \
Chris@69 236 static opus_int init = 0, cnt = 0; \
Chris@69 237 static FILE **fp; \
Chris@69 238 if (init == 0) { \
Chris@69 239 init = 1; \
Chris@69 240 cnt = silk_debug_store_count++; \
Chris@69 241 silk_debug_store_fp[ cnt ] = fopen(#FILE_NAME, "wb"); \
Chris@69 242 } \
Chris@69 243 fwrite((DATA_PTR), (N_BYTES), 1, silk_debug_store_fp[ cnt ]); \
Chris@69 244 }
Chris@69 245
Chris@69 246 /* Call this at the end of main() */
Chris@69 247 #define SILK_DEBUG_STORE_CLOSE_FILES { \
Chris@69 248 opus_int i; \
Chris@69 249 for( i = 0; i < silk_debug_store_count; i++ ) { \
Chris@69 250 fclose( silk_debug_store_fp[ i ] ); \
Chris@69 251 } \
Chris@69 252 }
Chris@69 253
Chris@69 254 #else /* SILK_DEBUG */
Chris@69 255
Chris@69 256 /* define macros as empty strings */
Chris@69 257 #define DEBUG_STORE_DATA(FILE_NAME, DATA_PTR, N_BYTES)
Chris@69 258 #define SILK_DEBUG_STORE_CLOSE_FILES
Chris@69 259
Chris@69 260 #endif /* SILK_DEBUG */
Chris@69 261
Chris@69 262 #ifdef __cplusplus
Chris@69 263 }
Chris@69 264 #endif
Chris@69 265
Chris@69 266 #endif /* SILK_DEBUG_H */