[svn] / branches / dev-api-4 / xvidcore / src / utils / timer.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/utils/timer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 195 - (view) (download)
Original Path: trunk/xvidcore/src/utils/timer.c

1 : edgomez 195 /******************************************************************************
2 :     * *
3 :     * This file is part of XviD, a free MPEG-4 video encoder/decoder *
4 :     * *
5 :     * XviD is free software; you can redistribute it and/or modify it *
6 :     * under the terms of the GNU General Public License as published by *
7 :     * the Free Software Foundation; either version 2 of the License, or *
8 :     * (at your option) any later version. *
9 :     * *
10 :     * XviD is distributed in the hope that it will be useful, but *
11 :     * WITHOUT ANY WARRANTY; without even the implied warranty of *
12 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 :     * GNU General Public License for more details. *
14 :     * *
15 :     * You should have received a copy of the GNU General Public License *
16 :     * along with this program; if not, write to the Free Software *
17 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
18 :     * *
19 :     ******************************************************************************/
20 :    
21 :     /******************************************************************************
22 :     * *
23 :     * timer.c, some timing functions *
24 :     * *
25 :     * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> *
26 :     * *
27 :     * For more information visit the XviD homepage: http://www.xvid.org *
28 :     * *
29 :     ******************************************************************************/
30 :    
31 :     /******************************************************************************
32 :     * *
33 :     * Revision history: *
34 :     *
35 :     * 26.03.2002 interlacing timer added
36 :     * 21.12.2001 edges error fixed
37 :     * 17.11.2001 small clean up (Isibaar) *
38 :     * 13.11.2001 inlined rdtsc call and moved to portab.h (Isibaar) *
39 :     * 02.11.2001 initial version (Isibaar) *
40 :     * *
41 :     ******************************************************************************/
42 :    
43 :     #include <stdio.h>
44 :     #include <time.h>
45 :     #include "timer.h"
46 :    
47 :     #if defined(_PROFILING_)
48 :    
49 :     struct ts
50 :     {
51 :     int64_t current;
52 :     int64_t global;
53 :     int64_t overall;
54 :     int64_t dct;
55 :     int64_t idct;
56 :     int64_t quant;
57 :     int64_t iquant;
58 :     int64_t motion;
59 :     int64_t comp;
60 :     int64_t edges;
61 :     int64_t inter;
62 :     int64_t conv;
63 :     int64_t trans;
64 :     int64_t prediction;
65 :     int64_t coding;
66 :     int64_t interlacing;
67 :     };
68 :    
69 :     struct ts tim;
70 :    
71 :     double frequency = 0.0;
72 :    
73 :     /*
74 :     determine cpu frequency
75 :     not very precise but sufficient
76 :     */
77 :     double
78 :     get_freq()
79 :     {
80 :     int64_t x, y;
81 :     int32_t i;
82 :    
83 :     i = time(NULL);
84 :    
85 :     while (i == time(NULL));
86 :    
87 :     x = read_counter();
88 :     i++;
89 :    
90 :     while (i == time(NULL));
91 :    
92 :     y = read_counter();
93 :    
94 :     return (double) (y - x) / 1000.;
95 :     }
96 :    
97 :     // set everything to zero //
98 :     void
99 :     init_timer()
100 :     {
101 :     frequency = get_freq();
102 :    
103 :     count_frames = 0;
104 :    
105 :     tim.dct = tim.quant = tim.idct = tim.iquant = tim.motion = tim.conv =
106 :     tim.edges = tim.inter = tim.interlacing = tim.trans = tim.trans =
107 :     tim.coding = tim.global = tim.overall = 0;
108 :     }
109 :    
110 :     void
111 :     start_timer()
112 :     {
113 :     tim.current = read_counter();
114 :     }
115 :    
116 :     void
117 :     start_global_timer()
118 :     {
119 :     tim.global = read_counter();
120 :     }
121 :    
122 :     void
123 :     stop_dct_timer()
124 :     {
125 :     tim.dct += (read_counter() - tim.current);
126 :     }
127 :    
128 :     void
129 :     stop_idct_timer()
130 :     {
131 :     tim.idct += (read_counter() - tim.current);
132 :     }
133 :    
134 :     void
135 :     stop_quant_timer()
136 :     {
137 :     tim.quant += (read_counter() - tim.current);
138 :     }
139 :    
140 :     void
141 :     stop_iquant_timer()
142 :     {
143 :     tim.iquant += (read_counter() - tim.current);
144 :     }
145 :    
146 :     void
147 :     stop_motion_timer()
148 :     {
149 :     tim.motion += (read_counter() - tim.current);
150 :     }
151 :    
152 :     void
153 :     stop_comp_timer()
154 :     {
155 :     tim.comp += (read_counter() - tim.current);
156 :     }
157 :    
158 :     void
159 :     stop_edges_timer()
160 :     {
161 :     tim.edges += (read_counter() - tim.current);
162 :     }
163 :    
164 :     void
165 :     stop_inter_timer()
166 :     {
167 :     tim.inter += (read_counter() - tim.current);
168 :     }
169 :    
170 :     void
171 :     stop_conv_timer()
172 :     {
173 :     tim.conv += (read_counter() - tim.current);
174 :     }
175 :    
176 :     void
177 :     stop_transfer_timer()
178 :     {
179 :     tim.trans += (read_counter() - tim.current);
180 :     }
181 :    
182 :     void
183 :     stop_prediction_timer()
184 :     {
185 :     tim.prediction += (read_counter() - tim.current);
186 :     }
187 :    
188 :     void
189 :     stop_coding_timer()
190 :     {
191 :     tim.coding += (read_counter() - tim.current);
192 :     }
193 :    
194 :     void
195 :     stop_interlacing_timer()
196 :     {
197 :     tim.interlacing += (read_counter() - tim.current);
198 :     }
199 :    
200 :     void
201 :     stop_global_timer()
202 :     {
203 :     tim.overall += (read_counter() - tim.global);
204 :     }
205 :    
206 :     /*
207 :     write log file with some timer information
208 :     */
209 :     void
210 :     write_timer()
211 :     {
212 :     float dct_per, quant_per, idct_per, iquant_per, mot_per, comp_per,
213 :     interlacing_per;
214 :     float edges_per, inter_per, conv_per, trans_per, pred_per, cod_per,
215 :     measured;
216 :     int64_t sum_ticks = 0;
217 :    
218 :     count_frames++;
219 :    
220 :     // only write log file every 50 processed frames //
221 :     if (count_frames % 50) {
222 :     FILE *fp;
223 :    
224 :     fp = fopen("encoder.log", "w+");
225 :    
226 :     dct_per =
227 :     (float) (((float) ((float) tim.dct / (float) tim.overall)) *
228 :     100.0);
229 :     quant_per =
230 :     (float) (((float) ((float) tim.quant / (float) tim.overall)) *
231 :     100.0);
232 :     idct_per =
233 :     (float) (((float) ((float) tim.idct / (float) tim.overall)) *
234 :     100.0);
235 :     iquant_per =
236 :     (float) (((float) ((float) tim.iquant / (float) tim.overall)) *
237 :     100.0);
238 :     mot_per =
239 :     (float) (((float) ((float) tim.motion / (float) tim.overall)) *
240 :     100.0);
241 :     comp_per =
242 :     (float) (((float) ((float) tim.comp / (float) tim.overall)) *
243 :     100.0);
244 :     edges_per =
245 :     (float) (((float) ((float) tim.edges / (float) tim.overall)) *
246 :     100.0);
247 :     inter_per =
248 :     (float) (((float) ((float) tim.inter / (float) tim.overall)) *
249 :     100.0);
250 :     conv_per =
251 :     (float) (((float) ((float) tim.conv / (float) tim.overall)) *
252 :     100.0);
253 :     trans_per =
254 :     (float) (((float) ((float) tim.trans / (float) tim.overall)) *
255 :     100.0);
256 :     pred_per =
257 :     (float) (((float) ((float) tim.prediction / (float) tim.overall)) *
258 :     100.0);
259 :     cod_per =
260 :     (float) (((float) ((float) tim.coding / (float) tim.overall)) *
261 :     100.0);
262 :     interlacing_per =
263 :     (float) (((float) ((float) tim.interlacing / (float) tim.overall))
264 :     * 100.0);
265 :    
266 :     sum_ticks =
267 :     tim.coding + tim.conv + tim.dct + tim.idct + tim.interlacing +
268 :     tim.edges + tim.inter + tim.iquant + tim.motion + tim.trans +
269 :     tim.quant + tim.trans;
270 :    
271 :     measured =
272 :     (float) (((float) ((float) sum_ticks / (float) tim.overall)) *
273 :     100.0);
274 :    
275 :     fprintf(fp,
276 :     "DCT:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
277 :     "Quant:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
278 :     "IDCT:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
279 :     "IQuant:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
280 :     "Mot estimation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
281 :     "Mot compensation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
282 :     "Edges:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
283 :     "Interpolation:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
284 :     "RGB2YUV:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
285 :     "Transfer:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
286 :     "Prediction:\nTotal time: %f ms (%3f percent of total encoding time)\n\n"
287 :     "Coding:\nTotal time: %f ms (%3f percent of total encoding time)\n\n\n"
288 :     "Interlacing:\nTotal time: %f ms (%3f percent of total encoding time)\n\n\n"
289 :     "Overall encoding time: %f ms, we measured %f ms (%3f percent)\n",
290 :     (float) (tim.dct / frequency), dct_per,
291 :     (float) (tim.quant / frequency), quant_per,
292 :     (float) (tim.idct / frequency), idct_per,
293 :     (float) (tim.iquant / frequency), iquant_per,
294 :     (float) (tim.motion / frequency), mot_per,
295 :     (float) (tim.comp / frequency), comp_per,
296 :     (float) (tim.edges / frequency), edges_per,
297 :     (float) (tim.inter / frequency), inter_per,
298 :     (float) (tim.conv / frequency), conv_per,
299 :     (float) (tim.trans / frequency), trans_per,
300 :     (float) (tim.prediction / frequency), pred_per,
301 :     (float) (tim.coding / frequency), cod_per,
302 :     (float) (tim.interlacing / frequency), interlacing_per,
303 :     (float) (tim.overall / frequency),
304 :     (float) (sum_ticks / frequency), measured);
305 :    
306 :     fclose(fp);
307 :     }
308 :     }
309 :    
310 :     #endif

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