[svn] / trunk / xvidcore / src / utils / timer.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/utils/timer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 654 - (view) (download)

1 : edgomez 414 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Some timing functions to profile the library -
5 :     *
6 :     * NB : not thread safe and only for debug purposes.
7 :     *
8 : edgomez 603 * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
9 : edgomez 414 *
10 : edgomez 654 * This file is part of XviD, a free MPEG-4 video encoder/decoder
11 : edgomez 414 *
12 : edgomez 654 * XviD is free software; you can redistribute it and/or modify it
13 :     * under the terms of the GNU General Public License as published by
14 : edgomez 414 * the Free Software Foundation; either version 2 of the License, or
15 :     * (at your option) any later version.
16 :     *
17 :     * This program is distributed in the hope that it will be useful,
18 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 :     * GNU General Public License for more details.
21 :     *
22 :     * You should have received a copy of the GNU General Public License
23 :     * along with this program; if not, write to the Free Software
24 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 :     *
26 : edgomez 654 * Under section 8 of the GNU General Public License, the copyright
27 :     * holders of XVID explicitly forbid distribution in the following
28 :     * countries:
29 : edgomez 414 *
30 : edgomez 654 * - Japan
31 :     * - United States of America
32 :     *
33 :     * Linking XviD statically or dynamically with other modules is making a
34 :     * combined work based on XviD. Thus, the terms and conditions of the
35 :     * GNU General Public License cover the whole combination.
36 :     *
37 :     * As a special exception, the copyright holders of XviD give you
38 :     * permission to link XviD with independent modules that communicate with
39 :     * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
40 :     * license terms of these independent modules, and to copy and distribute
41 :     * the resulting combined work under terms of your choice, provided that
42 :     * every copy of the combined work is accompanied by a complete copy of
43 :     * the source code of XviD (the version of XviD used to produce the
44 :     * combined work), being distributed under the terms of the GNU General
45 :     * Public License plus this exception. An independent module is a module
46 :     * which is not derived from or based on XviD.
47 :     *
48 :     * Note that people who make modified versions of XviD are not obligated
49 :     * to grant this special exception for their modified versions; it is
50 :     * their choice whether to do so. The GNU General Public License gives
51 :     * permission to release a modified version without this exception; this
52 :     * exception also makes it possible to release a modified version which
53 :     * carries forward this exception.
54 :     *
55 :     * $Id: timer.c,v 1.6 2002-11-17 00:51:11 edgomez Exp $
56 :     *
57 : edgomez 414 ****************************************************************************/
58 : edgomez 195
59 :     #include <stdio.h>
60 :     #include <time.h>
61 :     #include "timer.h"
62 :    
63 : edgomez 414 #ifdef _PROFILING_
64 : edgomez 195
65 :     struct ts
66 :     {
67 :     int64_t current;
68 :     int64_t global;
69 :     int64_t overall;
70 :     int64_t dct;
71 :     int64_t idct;
72 :     int64_t quant;
73 :     int64_t iquant;
74 :     int64_t motion;
75 :     int64_t comp;
76 :     int64_t edges;
77 :     int64_t inter;
78 :     int64_t conv;
79 :     int64_t trans;
80 :     int64_t prediction;
81 :     int64_t coding;
82 :     int64_t interlacing;
83 :     };
84 :    
85 :     struct ts tim;
86 :    
87 :     double frequency = 0.0;
88 :    
89 :     /*
90 :     determine cpu frequency
91 :     not very precise but sufficient
92 :     */
93 :     double
94 :     get_freq()
95 :     {
96 :     int64_t x, y;
97 :     int32_t i;
98 :    
99 :     i = time(NULL);
100 :    
101 :     while (i == time(NULL));
102 :    
103 :     x = read_counter();
104 :     i++;
105 :    
106 :     while (i == time(NULL));
107 :    
108 :     y = read_counter();
109 :    
110 :     return (double) (y - x) / 1000.;
111 :     }
112 :    
113 :     // set everything to zero //
114 :     void
115 :     init_timer()
116 :     {
117 :     frequency = get_freq();
118 :    
119 :     count_frames = 0;
120 :    
121 :     tim.dct = tim.quant = tim.idct = tim.iquant = tim.motion = tim.conv =
122 :     tim.edges = tim.inter = tim.interlacing = tim.trans = tim.trans =
123 :     tim.coding = tim.global = tim.overall = 0;
124 :     }
125 :    
126 :     void
127 :     start_timer()
128 :     {
129 :     tim.current = read_counter();
130 :     }
131 :    
132 :     void
133 :     start_global_timer()
134 :     {
135 :     tim.global = read_counter();
136 :     }
137 :    
138 :     void
139 :     stop_dct_timer()
140 :     {
141 :     tim.dct += (read_counter() - tim.current);
142 :     }
143 :    
144 :     void
145 :     stop_idct_timer()
146 :     {
147 :     tim.idct += (read_counter() - tim.current);
148 :     }
149 :    
150 :     void
151 :     stop_quant_timer()
152 :     {
153 :     tim.quant += (read_counter() - tim.current);
154 :     }
155 :    
156 :     void
157 :     stop_iquant_timer()
158 :     {
159 :     tim.iquant += (read_counter() - tim.current);
160 :     }
161 :    
162 :     void
163 :     stop_motion_timer()
164 :     {
165 :     tim.motion += (read_counter() - tim.current);
166 :     }
167 :    
168 :     void
169 :     stop_comp_timer()
170 :     {
171 :     tim.comp += (read_counter() - tim.current);
172 :     }
173 :    
174 :     void
175 :     stop_edges_timer()
176 :     {
177 :     tim.edges += (read_counter() - tim.current);
178 :     }
179 :    
180 :     void
181 :     stop_inter_timer()
182 :     {
183 :     tim.inter += (read_counter() - tim.current);
184 :     }
185 :    
186 :     void
187 :     stop_conv_timer()
188 :     {
189 :     tim.conv += (read_counter() - tim.current);
190 :     }
191 :    
192 :     void
193 :     stop_transfer_timer()
194 :     {
195 :     tim.trans += (read_counter() - tim.current);
196 :     }
197 :    
198 :     void
199 :     stop_prediction_timer()
200 :     {
201 :     tim.prediction += (read_counter() - tim.current);
202 :     }
203 :    
204 :     void
205 :     stop_coding_timer()
206 :     {
207 :     tim.coding += (read_counter() - tim.current);
208 :     }
209 :    
210 :     void
211 :     stop_interlacing_timer()
212 :     {
213 :     tim.interlacing += (read_counter() - tim.current);
214 :     }
215 :    
216 :     void
217 :     stop_global_timer()
218 :     {
219 :     tim.overall += (read_counter() - tim.global);
220 :     }
221 :    
222 :     /*
223 :     write log file with some timer information
224 :     */
225 :     void
226 :     write_timer()
227 :     {
228 :     float dct_per, quant_per, idct_per, iquant_per, mot_per, comp_per,
229 :     interlacing_per;
230 :     float edges_per, inter_per, conv_per, trans_per, pred_per, cod_per,
231 :     measured;
232 :     int64_t sum_ticks = 0;
233 :    
234 :     count_frames++;
235 :    
236 :     // only write log file every 50 processed frames //
237 :     if (count_frames % 50) {
238 :     FILE *fp;
239 :    
240 :     fp = fopen("encoder.log", "w+");
241 :    
242 :     dct_per =
243 :     (float) (((float) ((float) tim.dct / (float) tim.overall)) *
244 :     100.0);
245 :     quant_per =
246 :     (float) (((float) ((float) tim.quant / (float) tim.overall)) *
247 :     100.0);
248 :     idct_per =
249 :     (float) (((float) ((float) tim.idct / (float) tim.overall)) *
250 :     100.0);
251 :     iquant_per =
252 :     (float) (((float) ((float) tim.iquant / (float) tim.overall)) *
253 :     100.0);
254 :     mot_per =
255 :     (float) (((float) ((float) tim.motion / (float) tim.overall)) *
256 :     100.0);
257 :     comp_per =
258 :     (float) (((float) ((float) tim.comp / (float) tim.overall)) *
259 :     100.0);
260 :     edges_per =
261 :     (float) (((float) ((float) tim.edges / (float) tim.overall)) *
262 :     100.0);
263 :     inter_per =
264 :     (float) (((float) ((float) tim.inter / (float) tim.overall)) *
265 :     100.0);
266 :     conv_per =
267 :     (float) (((float) ((float) tim.conv / (float) tim.overall)) *
268 :     100.0);
269 :     trans_per =
270 :     (float) (((float) ((float) tim.trans / (float) tim.overall)) *
271 :     100.0);
272 :     pred_per =
273 :     (float) (((float) ((float) tim.prediction / (float) tim.overall)) *
274 :     100.0);
275 :     cod_per =
276 :     (float) (((float) ((float) tim.coding / (float) tim.overall)) *
277 :     100.0);
278 :     interlacing_per =
279 :     (float) (((float) ((float) tim.interlacing / (float) tim.overall))
280 :     * 100.0);
281 :    
282 :     sum_ticks =
283 :     tim.coding + tim.conv + tim.dct + tim.idct + tim.interlacing +
284 :     tim.edges + tim.inter + tim.iquant + tim.motion + tim.trans +
285 :     tim.quant + tim.trans;
286 :    
287 :     measured =
288 :     (float) (((float) ((float) sum_ticks / (float) tim.overall)) *
289 :     100.0);
290 :    
291 :     fprintf(fp,
292 :     "DCT:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
293 :     "Quant:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
294 :     "IDCT:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
295 :     "IQuant:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
296 :     "Mot estimation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
297 :     "Mot compensation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
298 :     "Edges:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
299 :     "Interpolation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
300 :     "RGB2YUV:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
301 :     "Transfer:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
302 :     "Prediction:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
303 :     "Coding:\nTotal time: %f ms (%3f percent of total encoding time)\n\n\n"
304 :     "Interlacing:\nTotal time: %f ms (%3f percent of total encoding time)\n\n\n"
305 :     "Overall encoding time: %f ms, we measured %f ms (%3f percent)\n",
306 :     (float) (tim.dct / frequency), dct_per,
307 :     (float) (tim.quant / frequency), quant_per,
308 :     (float) (tim.idct / frequency), idct_per,
309 :     (float) (tim.iquant / frequency), iquant_per,
310 :     (float) (tim.motion / frequency), mot_per,
311 :     (float) (tim.comp / frequency), comp_per,
312 :     (float) (tim.edges / frequency), edges_per,
313 :     (float) (tim.inter / frequency), inter_per,
314 :     (float) (tim.conv / frequency), conv_per,
315 :     (float) (tim.trans / frequency), trans_per,
316 :     (float) (tim.prediction / frequency), pred_per,
317 :     (float) (tim.coding / frequency), cod_per,
318 :     (float) (tim.interlacing / frequency), interlacing_per,
319 :     (float) (tim.overall / frequency),
320 :     (float) (sum_ticks / frequency), measured);
321 :    
322 :     fclose(fp);
323 :     }
324 :     }
325 :    
326 :     #endif

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4