Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: third_party/WebKit/Source/platform/testing/ImageDecodeBench.cpp

Issue 2880953002: Measure frame decodes more accurately from ImageDecodeBench
Patch Set: Remove raster timing Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Provides a minimal wrapping of the Blink image decoders. Used to perform 5 // Provides a minimal wrapping of the Blink image decoders. Used to perform
6 // a non-threaded, memory-to-memory image decode using micro second accuracy 6 // a non-threaded, memory-to-memory image decode using micro second accuracy
7 // clocks to measure image decode time. Optionally applies color correction 7 // clocks to measure image decode time. Optionally applies color correction
8 // during image decoding on supported platforms (default off). Usage: 8 // during image decoding on supported platforms (default off). Usage:
9 // 9 //
10 // % ninja -C out/Release image_decode_bench && 10 // % ninja -C out/Release image_decode_bench &&
11 // ./out/Release/image_decode_bench file [iterations] 11 // ./out/Release/image_decode_bench file [iterations]
12 // 12 //
13 // The output is formatted for use in a csv file (comma-separated variable).
14 // Each row represents suceessive frames in an animated image.
scroggo_chromium 2017/05/22 13:07:40 successive*
cblume 2017/05/23 00:43:56 Done.
15 // Each column represents a successive iteration of decoding the whole animated
scroggo_chromium 2017/05/22 13:07:40 I don't think this is correct. A row shows a singl
cblume 2017/05/23 00:43:56 Hrmmm I think this comment is correct. With the n
scroggo_chromium 2017/05/23 15:42:23 Agreed. This is covered by the comment above. ("Ea
cblume 2017/05/23 19:44:34 That is probably a good idea. I'll add comments af
16 // image.
17 // This means non-animated images will show up as a column.
scroggo_chromium 2017/05/22 13:07:40 nit: Instead of saying "as a column", I think it w
cblume 2017/05/23 00:43:56 Done.
18 // Raster timing also shows up as a column.
scroggo_chromium 2017/05/22 13:07:40 Since you've moved raster timing to its own patch,
cblume 2017/05/23 00:43:56 Done.
19 //
13 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute 20 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute
14 // the decoded image frame md5 and output that value. 21 // the decoded image frame md5 and output that value.
15 // 22 //
16 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz, 23 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz,
17 // using the image corpii used to assess Blink image decode performance. Refer 24 // using the image corpii used to assess Blink image decode performance. Refer
18 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5 25 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5
19 26
20 #include <memory> 27 #include <memory>
28 #include <vector>
21 #include "base/command_line.h" 29 #include "base/command_line.h"
22 #include "platform/SharedBuffer.h" 30 #include "platform/SharedBuffer.h"
23 #include "platform/image-decoders/ImageDecoder.h" 31 #include "platform/image-decoders/ImageDecoder.h"
24 #include "platform/wtf/PassRefPtr.h" 32 #include "platform/wtf/PassRefPtr.h"
25 #include "platform/wtf/PtrUtil.h" 33 #include "platform/wtf/PtrUtil.h"
26 #include "public/platform/Platform.h" 34 #include "public/platform/Platform.h"
27 #include "ui/gfx/test/icc_profiles.h" 35 #include "ui/gfx/test/icc_profiles.h"
28 36
29 #if defined(_WIN32) 37 #if defined(_WIN32)
30 #include <mmsystem.h> 38 #include <mmsystem.h>
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 WrapArrayUnique(new unsigned char[file_size]); 205 WrapArrayUnique(new unsigned char[file_size]);
198 if (file_size != fread(buffer.get(), 1, file_size, fp)) { 206 if (file_size != fread(buffer.get(), 1, file_size, fp)) {
199 fprintf(stderr, "Error reading file %s\n", file_name); 207 fprintf(stderr, "Error reading file %s\n", file_name);
200 exit(2); 208 exit(2);
201 } 209 }
202 210
203 fclose(fp); 211 fclose(fp);
204 return SharedBuffer::Create(buffer.get(), file_size); 212 return SharedBuffer::Create(buffer.get(), file_size);
205 } 213 }
206 214
207 bool DecodeImageData(SharedBuffer* data, 215 using FrameTimings = std::vector<double>;
scroggo_chromium 2017/05/22 13:07:40 The names help, but I think a comment here might b
cblume 2017/05/23 00:43:56 I agree. Your suggested comment is very clear. Tha
208 bool color_correction, 216 using IterationsOfFrameTimings = std::vector<FrameTimings>;
209 size_t packet_size) {
210 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create(
211 data, true, ImageDecoder::kAlphaPremultiplied,
212 color_correction ? ColorBehavior::TransformToTargetForTesting()
213 : ColorBehavior::Ignore());
214 if (!packet_size) {
215 bool all_data_received = true;
216 decoder->SetData(data, all_data_received);
217 217
218 int frame_count = decoder->FrameCount(); 218 void Print2DResults(const IterationsOfFrameTimings& timings) {
219 for (int i = 0; i < frame_count; ++i) { 219 for (const std::vector<double>& iteration : timings) {
220 if (!decoder->FrameBufferAtIndex(i)) 220 for (double frame_time : iteration) {
221 return false; 221 printf("%f,", frame_time);
222 } 222 }
223 printf("\n");
224 }
225 printf("\n");
226 }
223 227
224 return !decoder->Failed(); 228 void TimeDecode(ImageDecoder* decoder,
229 PassRefPtr<SharedBuffer> data,
230 size_t iterations) {
231 bool all_data_received = true;
232 decoder->SetData(data.Get(), all_data_received);
233
234 size_t frame_count = decoder->FrameCount();
235
236 IterationsOfFrameTimings timings(iterations, FrameTimings(frame_count, 0.0));
237
238 for (size_t iteration = 0; iteration < iterations; ++iteration) {
239 for (size_t frame_index = 0; frame_index < frame_count; ++frame_index) {
240 double start_time = GetCurrentTime();
241 ImageFrame* frame = decoder->FrameBufferAtIndex(frame_index);
242 double elapsed_time = GetCurrentTime() - start_time;
243 if (frame->GetStatus() != ImageFrame::kFrameComplete) {
scroggo_chromium 2017/05/22 13:07:40 Should this print an error message?
cblume 2017/05/23 00:43:56 Done. I also am using exit(3); to mirror current b
244 return;
245 }
246 timings[iteration][frame_index] = elapsed_time;
247 }
225 } 248 }
226 249
250 Print2DResults(timings);
251 }
252
253 // This function mimics deferred decoding in Chromium when not all data has been
254 // received yet.
255 void TimePacketedDecode(ImageDecoder* decoder,
256 PassRefPtr<SharedBuffer> data,
257 size_t packet_size,
258 size_t iterations) {
259 // Find total frame count.
260 // Doing this requires a decoder with full data (no packet size).
261 std::unique_ptr<ImageDecoder> frame_count_decoder =
262 ImageDecoder::Create(data.Get(), true, ImageDecoder::kAlphaPremultiplied,
263 ColorBehavior::Ignore());
264
265 constexpr bool total_all_data_received = true;
266 frame_count_decoder->SetData(data.Get(), total_all_data_received);
267 size_t total_frame_count = frame_count_decoder->FrameCount();
268
269 IterationsOfFrameTimings timings(iterations,
270 FrameTimings(total_frame_count, 0.0));
271
227 RefPtr<SharedBuffer> packet_data = SharedBuffer::Create(); 272 RefPtr<SharedBuffer> packet_data = SharedBuffer::Create();
228 size_t position = 0; 273 size_t position = 0;
229 size_t next_frame_to_decode = 0; 274 size_t next_frame_to_decode = 0;
230 while (true) { 275 while (true) {
231 const char* packet; 276 const char* packet;
232 size_t length = data->GetSomeData(packet, position); 277 size_t length = data->GetSomeData(packet, position);
233 278
234 length = std::min(length, packet_size); 279 length = std::min(length, packet_size);
235 packet_data->Append(packet, length); 280 packet_data->Append(packet, length);
236 position += length; 281 position += length;
237 282
238 bool all_data_received = position == data->size(); 283 bool all_data_received = position == data->size();
239 decoder->SetData(packet_data.Get(), all_data_received);
240 284
241 size_t frame_count = decoder->FrameCount(); 285 size_t frame_count = decoder->FrameCount();
242 for (; next_frame_to_decode < frame_count; ++next_frame_to_decode) { 286 for (size_t iteration = 0; iteration < iterations; ++iteration) {
scroggo_chromium 2017/05/22 13:07:40 nit: I think this would be easier to follow if you
cblume 2017/05/23 00:43:56 Done.
243 ImageFrame* frame = decoder->FrameBufferAtIndex(next_frame_to_decode); 287 for (; next_frame_to_decode < frame_count; ++next_frame_to_decode) {
244 if (frame->GetStatus() != ImageFrame::kFrameComplete) 288 decoder->SetData(packet_data.Get(), all_data_received);
245 break; 289 double start_time = GetCurrentTime();
290 ImageFrame* frame = decoder->FrameBufferAtIndex(next_frame_to_decode);
291 double elapsed_time = GetCurrentTime() - start_time;
292 if (frame->GetStatus() != ImageFrame::kFrameComplete)
293 break;
294 timings[iteration][next_frame_to_decode] = elapsed_time;
295 decoder->SetData(PassRefPtr<SegmentReader>(nullptr), false);
296 decoder->ClearCacheExceptFrame(next_frame_to_decode);
scroggo_chromium 2017/05/22 13:07:40 I thought we had agreed to remove this? Was that o
cblume 2017/05/23 00:43:56 Right. I thought I had removed it, too. It looks l
scroggo_chromium 2017/05/23 15:42:23 I don't think rebasing works the way you expect. T
cblume 2017/05/23 19:44:34 Right. I hadn't rebased by the time you saw this l
297 }
246 } 298 }
247 299
248 if (all_data_received || decoder->Failed()) 300 if (all_data_received || decoder->Failed())
scroggo_chromium 2017/05/22 13:07:40 Should this print an error statement?
cblume 2017/05/23 00:43:56 Done.
249 break; 301 return;
250 } 302 }
251 303
252 return !decoder->Failed(); 304 Print2DResults(timings);
253 } 305 }
254 306
255 } // namespace 307 } // namespace
256 308
257 int Main(int argc, char* argv[]) { 309 int Main(int argc, char* argv[]) {
258 base::CommandLine::Init(argc, argv); 310 base::CommandLine::Init(argc, argv);
259 311
260 // If the platform supports color correction, allow it to be controlled. 312 // If the platform supports color correction, allow it to be controlled.
261 313
262 bool apply_color_correction = false; 314 bool apply_color_correction = false;
263
264 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0) { 315 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0) {
265 apply_color_correction = (--argc, ++argv, true); 316 --argc;
317 ++argv;
318 apply_color_correction = true;
266 gfx::ICCProfile profile = gfx::ICCProfileForTestingColorSpin(); 319 gfx::ICCProfile profile = gfx::ICCProfileForTestingColorSpin();
267 ColorBehavior::SetGlobalTargetColorProfile(profile); 320 ColorBehavior::SetGlobalTargetColorProfile(profile);
268 } 321 }
269 322
270 if (argc < 2) { 323 if (argc < 2) {
271 fprintf(stderr, 324 fprintf(stderr,
272 "Usage: %s [--color-correct] file [iterations] [packetSize]\n", 325 "Usage: %s [--color-correct] file [iterations] [packetSize]\n",
273 argv[0]); 326 argv[0]);
274 exit(1); 327 exit(1);
275 } 328 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // segments into one, contiguous block of memory. 367 // segments into one, contiguous block of memory.
315 368
316 RefPtr<SharedBuffer> data = ReadFile(argv[1]); 369 RefPtr<SharedBuffer> data = ReadFile(argv[1]);
317 if (!data.Get() || !data->size()) { 370 if (!data.Get() || !data->size()) {
318 fprintf(stderr, "Error reading image data from [%s]\n", argv[1]); 371 fprintf(stderr, "Error reading image data from [%s]\n", argv[1]);
319 exit(2); 372 exit(2);
320 } 373 }
321 374
322 data->Data(); 375 data->Data();
323 376
324 // Warm-up: throw out the first iteration for more consistent results. 377 // Image decode bench for iterations.
325 378
326 if (!DecodeImageData(data.Get(), apply_color_correction, packet_size)) { 379 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create(
327 fprintf(stderr, "Image decode failed [%s]\n", argv[1]); 380 data, true, ImageDecoder::kAlphaPremultiplied,
328 exit(3); 381 apply_color_correction ? ColorBehavior::TransformToTargetForTesting()
382 : ColorBehavior::Ignore());
383 if (packet_size) {
384 blink::TimePacketedDecode(decoder.get(), data.Get(), packet_size,
scroggo_chromium 2017/05/22 13:07:40 This whole file looks to be inside namespace blink
cblume 2017/05/23 00:43:56 Done.
385 iterations);
386 } else {
387 blink::TimeDecode(decoder.get(), data.Get(), iterations);
329 } 388 }
330 389
331 // Image decode bench for iterations.
332
333 double total_time = 0.0;
334
335 for (size_t i = 0; i < iterations; ++i) {
336 double start_time = GetCurrentTime();
337 bool decoded =
338 DecodeImageData(data.Get(), apply_color_correction, packet_size);
339 double elapsed_time = GetCurrentTime() - start_time;
340 total_time += elapsed_time;
341 if (!decoded) {
342 fprintf(stderr, "Image decode failed [%s]\n", argv[1]);
343 exit(3);
344 }
345 }
346
347 // Results to stdout.
348
349 double average_time = total_time / static_cast<double>(iterations);
350 printf("%f %f\n", total_time, average_time);
351 return 0; 390 return 0;
352 } 391 }
353 392
354 } // namespace blink 393 } // namespace blink
355 394
356 int main(int argc, char* argv[]) { 395 int main(int argc, char* argv[]) {
357 return blink::Main(argc, argv); 396 return blink::Main(argc, argv);
358 } 397 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698