tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

debug.c (6941B)


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