[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 414 - (view) (download)
Original Path: trunk/xvidcore/src/utils/timer.c

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

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