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