annotate src/opus-1.3/silk/debug.c @ 154:4664ac0c1032

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