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