Chris@69: /*********************************************************************** Chris@69: Copyright (c) 2006-2011, Skype Limited. All rights reserved. Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: - Redistributions of source code must retain the above copyright notice, Chris@69: this list of conditions and the following disclaimer. Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: - Neither the name of Internet Society, IETF or IETF Trust, nor the Chris@69: names of specific contributors, may be used to endorse or promote Chris@69: products derived from this software without specific prior written Chris@69: permission. Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" Chris@69: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE Chris@69: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE Chris@69: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE Chris@69: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR Chris@69: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF Chris@69: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS Chris@69: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN Chris@69: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) Chris@69: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE Chris@69: POSSIBILITY OF SUCH DAMAGE. Chris@69: ***********************************************************************/ Chris@69: Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: Chris@69: #include "debug.h" Chris@69: #include "SigProc_FIX.h" Chris@69: Chris@69: #if SILK_TIC_TOC Chris@69: Chris@69: #ifdef _WIN32 Chris@69: Chris@69: #if (defined(_WIN32) || defined(_WINCE)) Chris@69: #include /* timer */ Chris@69: #else /* Linux or Mac*/ Chris@69: #include Chris@69: #endif Chris@69: Chris@69: unsigned long silk_GetHighResolutionTime(void) /* O time in usec*/ Chris@69: { Chris@69: /* Returns a time counter in microsec */ Chris@69: /* the resolution is platform dependent */ Chris@69: /* but is typically 1.62 us resolution */ Chris@69: LARGE_INTEGER lpPerformanceCount; Chris@69: LARGE_INTEGER lpFrequency; Chris@69: QueryPerformanceCounter(&lpPerformanceCount); Chris@69: QueryPerformanceFrequency(&lpFrequency); Chris@69: return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart); Chris@69: } Chris@69: #else /* Linux or Mac*/ Chris@69: unsigned long GetHighResolutionTime(void) /* O time in usec*/ Chris@69: { Chris@69: struct timeval tv; Chris@69: gettimeofday(&tv, 0); Chris@69: return((tv.tv_sec*1000000)+(tv.tv_usec)); Chris@69: } Chris@69: #endif Chris@69: Chris@69: int silk_Timer_nTimers = 0; Chris@69: int silk_Timer_depth_ctr = 0; Chris@69: char silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN]; Chris@69: #ifdef WIN32 Chris@69: LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX]; Chris@69: #else Chris@69: unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX]; Chris@69: #endif Chris@69: unsigned int silk_Timer_cnt[silk_NUM_TIMERS_MAX]; Chris@69: opus_int64 silk_Timer_min[silk_NUM_TIMERS_MAX]; Chris@69: opus_int64 silk_Timer_sum[silk_NUM_TIMERS_MAX]; Chris@69: opus_int64 silk_Timer_max[silk_NUM_TIMERS_MAX]; Chris@69: opus_int64 silk_Timer_depth[silk_NUM_TIMERS_MAX]; Chris@69: Chris@69: #ifdef WIN32 Chris@69: void silk_TimerSave(char *file_name) Chris@69: { Chris@69: if( silk_Timer_nTimers > 0 ) Chris@69: { Chris@69: int k; Chris@69: FILE *fp; Chris@69: LARGE_INTEGER lpFrequency; Chris@69: LARGE_INTEGER lpPerformanceCount1, lpPerformanceCount2; Chris@69: int del = 0x7FFFFFFF; Chris@69: double avg, sum_avg; Chris@69: /* estimate overhead of calling performance counters */ Chris@69: for( k = 0; k < 1000; k++ ) { Chris@69: QueryPerformanceCounter(&lpPerformanceCount1); Chris@69: QueryPerformanceCounter(&lpPerformanceCount2); Chris@69: lpPerformanceCount2.QuadPart -= lpPerformanceCount1.QuadPart; Chris@69: if( (int)lpPerformanceCount2.LowPart < del ) Chris@69: del = lpPerformanceCount2.LowPart; Chris@69: } Chris@69: QueryPerformanceFrequency(&lpFrequency); Chris@69: /* print results to file */ Chris@69: sum_avg = 0.0f; Chris@69: for( k = 0; k < silk_Timer_nTimers; k++ ) { Chris@69: if (silk_Timer_depth[k] == 0) { Chris@69: sum_avg += (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart * silk_Timer_cnt[k]; Chris@69: } Chris@69: } Chris@69: fp = fopen(file_name, "w"); Chris@69: fprintf(fp, " min avg %% max count\n"); Chris@69: for( k = 0; k < silk_Timer_nTimers; k++ ) { Chris@69: if (silk_Timer_depth[k] == 0) { Chris@69: fprintf(fp, "%-28s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 1) { Chris@69: fprintf(fp, " %-27s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 2) { Chris@69: fprintf(fp, " %-26s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 3) { Chris@69: fprintf(fp, " %-25s", silk_Timer_tags[k]); Chris@69: } else { Chris@69: fprintf(fp, " %-24s", silk_Timer_tags[k]); Chris@69: } Chris@69: avg = (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart; Chris@69: fprintf(fp, "%8.2f", (1e6 * (silk_max_64(silk_Timer_min[k] - del, 0))) / lpFrequency.QuadPart); Chris@69: fprintf(fp, "%12.2f %6.2f", avg, 100.0 * avg / sum_avg * silk_Timer_cnt[k]); Chris@69: fprintf(fp, "%12.2f", (1e6 * (silk_max_64(silk_Timer_max[k] - del, 0))) / lpFrequency.QuadPart); Chris@69: fprintf(fp, "%10d\n", silk_Timer_cnt[k]); Chris@69: } Chris@69: fprintf(fp, " microseconds\n"); Chris@69: fclose(fp); Chris@69: } Chris@69: } Chris@69: #else Chris@69: void silk_TimerSave(char *file_name) Chris@69: { Chris@69: if( silk_Timer_nTimers > 0 ) Chris@69: { Chris@69: int k; Chris@69: FILE *fp; Chris@69: /* print results to file */ Chris@69: fp = fopen(file_name, "w"); Chris@69: fprintf(fp, " min avg max count\n"); Chris@69: for( k = 0; k < silk_Timer_nTimers; k++ ) Chris@69: { Chris@69: if (silk_Timer_depth[k] == 0) { Chris@69: fprintf(fp, "%-28s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 1) { Chris@69: fprintf(fp, " %-27s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 2) { Chris@69: fprintf(fp, " %-26s", silk_Timer_tags[k]); Chris@69: } else if (silk_Timer_depth[k] == 3) { Chris@69: fprintf(fp, " %-25s", silk_Timer_tags[k]); Chris@69: } else { Chris@69: fprintf(fp, " %-24s", silk_Timer_tags[k]); Chris@69: } Chris@69: fprintf(fp, "%d ", silk_Timer_min[k]); Chris@69: fprintf(fp, "%f ", (double)silk_Timer_sum[k] / (double)silk_Timer_cnt[k]); Chris@69: fprintf(fp, "%d ", silk_Timer_max[k]); Chris@69: fprintf(fp, "%10d\n", silk_Timer_cnt[k]); Chris@69: } Chris@69: fprintf(fp, " microseconds\n"); Chris@69: fclose(fp); Chris@69: } Chris@69: } Chris@69: #endif Chris@69: Chris@69: #endif /* SILK_TIC_TOC */ Chris@69: Chris@69: #if SILK_DEBUG Chris@69: FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ]; Chris@69: int silk_debug_store_count = 0; Chris@69: #endif /* SILK_DEBUG */ Chris@69: