media/libopus/silk/debug.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libopus/silk/debug.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,170 @@
     1.4 +/***********************************************************************
     1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved.
     1.6 +Redistribution and use in source and binary forms, with or without
     1.7 +modification, are permitted provided that the following conditions
     1.8 +are met:
     1.9 +- Redistributions of source code must retain the above copyright notice,
    1.10 +this list of conditions and the following disclaimer.
    1.11 +- Redistributions in binary form must reproduce the above copyright
    1.12 +notice, this list of conditions and the following disclaimer in the
    1.13 +documentation and/or other materials provided with the distribution.
    1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the
    1.15 +names of specific contributors, may be used to endorse or promote
    1.16 +products derived from this software without specific prior written
    1.17 +permission.
    1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 +POSSIBILITY OF SUCH DAMAGE.
    1.29 +***********************************************************************/
    1.30 +
    1.31 +#ifdef HAVE_CONFIG_H
    1.32 +#include "config.h"
    1.33 +#endif
    1.34 +
    1.35 +#include "debug.h"
    1.36 +#include "SigProc_FIX.h"
    1.37 +
    1.38 +#if SILK_TIC_TOC
    1.39 +
    1.40 +#ifdef _WIN32
    1.41 +
    1.42 +#if (defined(_WIN32) || defined(_WINCE))
    1.43 +#include <windows.h>    /* timer */
    1.44 +#else   /* Linux or Mac*/
    1.45 +#include <sys/time.h>
    1.46 +#endif
    1.47 +
    1.48 +unsigned long silk_GetHighResolutionTime(void) /* O  time in usec*/
    1.49 +{
    1.50 +    /* Returns a time counter in microsec   */
    1.51 +    /* the resolution is platform dependent */
    1.52 +    /* but is typically 1.62 us resolution  */
    1.53 +    LARGE_INTEGER lpPerformanceCount;
    1.54 +    LARGE_INTEGER lpFrequency;
    1.55 +    QueryPerformanceCounter(&lpPerformanceCount);
    1.56 +    QueryPerformanceFrequency(&lpFrequency);
    1.57 +    return (unsigned long)((1000000*(lpPerformanceCount.QuadPart)) / lpFrequency.QuadPart);
    1.58 +}
    1.59 +#else   /* Linux or Mac*/
    1.60 +unsigned long GetHighResolutionTime(void) /* O  time in usec*/
    1.61 +{
    1.62 +    struct timeval tv;
    1.63 +    gettimeofday(&tv, 0);
    1.64 +    return((tv.tv_sec*1000000)+(tv.tv_usec));
    1.65 +}
    1.66 +#endif
    1.67 +
    1.68 +int           silk_Timer_nTimers = 0;
    1.69 +int           silk_Timer_depth_ctr = 0;
    1.70 +char          silk_Timer_tags[silk_NUM_TIMERS_MAX][silk_NUM_TIMERS_MAX_TAG_LEN];
    1.71 +#ifdef WIN32
    1.72 +LARGE_INTEGER silk_Timer_start[silk_NUM_TIMERS_MAX];
    1.73 +#else
    1.74 +unsigned long silk_Timer_start[silk_NUM_TIMERS_MAX];
    1.75 +#endif
    1.76 +unsigned int  silk_Timer_cnt[silk_NUM_TIMERS_MAX];
    1.77 +opus_int64     silk_Timer_min[silk_NUM_TIMERS_MAX];
    1.78 +opus_int64     silk_Timer_sum[silk_NUM_TIMERS_MAX];
    1.79 +opus_int64     silk_Timer_max[silk_NUM_TIMERS_MAX];
    1.80 +opus_int64     silk_Timer_depth[silk_NUM_TIMERS_MAX];
    1.81 +
    1.82 +#ifdef WIN32
    1.83 +void silk_TimerSave(char *file_name)
    1.84 +{
    1.85 +    if( silk_Timer_nTimers > 0 )
    1.86 +    {
    1.87 +        int k;
    1.88 +        FILE *fp;
    1.89 +        LARGE_INTEGER lpFrequency;
    1.90 +        LARGE_INTEGER lpPerformanceCount1, lpPerformanceCount2;
    1.91 +        int del = 0x7FFFFFFF;
    1.92 +        double avg, sum_avg;
    1.93 +        /* estimate overhead of calling performance counters */
    1.94 +        for( k = 0; k < 1000; k++ ) {
    1.95 +            QueryPerformanceCounter(&lpPerformanceCount1);
    1.96 +            QueryPerformanceCounter(&lpPerformanceCount2);
    1.97 +            lpPerformanceCount2.QuadPart -= lpPerformanceCount1.QuadPart;
    1.98 +            if( (int)lpPerformanceCount2.LowPart < del )
    1.99 +                del = lpPerformanceCount2.LowPart;
   1.100 +        }
   1.101 +        QueryPerformanceFrequency(&lpFrequency);
   1.102 +        /* print results to file */
   1.103 +        sum_avg = 0.0f;
   1.104 +        for( k = 0; k < silk_Timer_nTimers; k++ ) {
   1.105 +            if (silk_Timer_depth[k] == 0) {
   1.106 +                sum_avg += (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart * silk_Timer_cnt[k];
   1.107 +            }
   1.108 +        }
   1.109 +        fp = fopen(file_name, "w");
   1.110 +        fprintf(fp, "                                min         avg     %%         max      count\n");
   1.111 +        for( k = 0; k < silk_Timer_nTimers; k++ ) {
   1.112 +            if (silk_Timer_depth[k] == 0) {
   1.113 +                fprintf(fp, "%-28s", silk_Timer_tags[k]);
   1.114 +            } else if (silk_Timer_depth[k] == 1) {
   1.115 +                fprintf(fp, " %-27s", silk_Timer_tags[k]);
   1.116 +            } else if (silk_Timer_depth[k] == 2) {
   1.117 +                fprintf(fp, "  %-26s", silk_Timer_tags[k]);
   1.118 +            } else if (silk_Timer_depth[k] == 3) {
   1.119 +                fprintf(fp, "   %-25s", silk_Timer_tags[k]);
   1.120 +            } else {
   1.121 +                fprintf(fp, "    %-24s", silk_Timer_tags[k]);
   1.122 +            }
   1.123 +            avg = (1e6 * silk_Timer_sum[k] / silk_Timer_cnt[k] - del) / lpFrequency.QuadPart;
   1.124 +            fprintf(fp, "%8.2f", (1e6 * (silk_max_64(silk_Timer_min[k] - del, 0))) / lpFrequency.QuadPart);
   1.125 +            fprintf(fp, "%12.2f %6.2f", avg, 100.0 * avg / sum_avg * silk_Timer_cnt[k]);
   1.126 +            fprintf(fp, "%12.2f", (1e6 * (silk_max_64(silk_Timer_max[k] - del, 0))) / lpFrequency.QuadPart);
   1.127 +            fprintf(fp, "%10d\n", silk_Timer_cnt[k]);
   1.128 +        }
   1.129 +        fprintf(fp, "                                microseconds\n");
   1.130 +        fclose(fp);
   1.131 +    }
   1.132 +}
   1.133 +#else
   1.134 +void silk_TimerSave(char *file_name)
   1.135 +{
   1.136 +    if( silk_Timer_nTimers > 0 )
   1.137 +    {
   1.138 +        int k;
   1.139 +        FILE *fp;
   1.140 +        /* print results to file */
   1.141 +        fp = fopen(file_name, "w");
   1.142 +        fprintf(fp, "                                min         avg         max      count\n");
   1.143 +        for( k = 0; k < silk_Timer_nTimers; k++ )
   1.144 +        {
   1.145 +            if (silk_Timer_depth[k] == 0) {
   1.146 +                fprintf(fp, "%-28s", silk_Timer_tags[k]);
   1.147 +            } else if (silk_Timer_depth[k] == 1) {
   1.148 +                fprintf(fp, " %-27s", silk_Timer_tags[k]);
   1.149 +            } else if (silk_Timer_depth[k] == 2) {
   1.150 +                fprintf(fp, "  %-26s", silk_Timer_tags[k]);
   1.151 +            } else if (silk_Timer_depth[k] == 3) {
   1.152 +                fprintf(fp, "   %-25s", silk_Timer_tags[k]);
   1.153 +            } else {
   1.154 +                fprintf(fp, "    %-24s", silk_Timer_tags[k]);
   1.155 +            }
   1.156 +            fprintf(fp, "%d ", silk_Timer_min[k]);
   1.157 +            fprintf(fp, "%f ", (double)silk_Timer_sum[k] / (double)silk_Timer_cnt[k]);
   1.158 +            fprintf(fp, "%d ", silk_Timer_max[k]);
   1.159 +            fprintf(fp, "%10d\n", silk_Timer_cnt[k]);
   1.160 +        }
   1.161 +        fprintf(fp, "                                microseconds\n");
   1.162 +        fclose(fp);
   1.163 +    }
   1.164 +}
   1.165 +#endif
   1.166 +
   1.167 +#endif /* SILK_TIC_TOC */
   1.168 +
   1.169 +#if SILK_DEBUG
   1.170 +FILE *silk_debug_store_fp[ silk_NUM_STORES_MAX ];
   1.171 +int silk_debug_store_count = 0;
   1.172 +#endif /* SILK_DEBUG */
   1.173 +

mercurial