16645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org/*
26645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org * Copyright 2013 Google Inc.
36645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org *
46645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
56645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org * found in the LICENSE file.
66645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org */
76645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
89ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#include "Timer.h"
9f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "Benchmark.h"
106645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "LazyDecodeBitmap.h"
116645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "PictureBenchmark.h"
126645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "PictureRenderer.h"
13f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "SkCommandLineFlags.h"
146645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "SkForceLinking.h"
156645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "SkGraphics.h"
166645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "SkStream.h"
176645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org#include "SkString.h"
1849a07ad0977fb118fe91f5c908b6703e2d89dec6commit-bot@chromium.org#include "SkTArray.h"
196645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
20cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgtypedef sk_tools::PictureRenderer::BBoxHierarchyType BBoxType;
21cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgstatic const int kBBoxTypeCount = sk_tools::PictureRenderer::kLast_BBoxHierarchyType + 1;
226645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
236645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
24cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgDEFINE_string2(skps, r, "", "The list of SKPs to benchmark.");
25f16d797497aff698e4dfcef0885dce04915a8c36commit-bot@chromium.orgDEFINE_string(bb_types, "", "The set of bbox types to test. If empty, all are tested. "
262a65a238b0e688356aee09d08f3f8a317359b4d2mtklein                       "Should be one or more of none, rtree, tilegrid.");
27cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgDEFINE_int32(record, 100, "Number of times to record each SKP.");
28cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgDEFINE_int32(playback, 1, "Number of times to playback each SKP.");
29cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgDEFINE_int32(tilesize, 256, "The size of a tile.");
302e915b32347aa2c2bcf82aba57c325b8fb81ec53commit-bot@chromium.org
31cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgstruct Measurement {
326645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkString fName;
33cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    double fRecordAverage[kBBoxTypeCount];
34cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    double fPlaybackAverage[kBBoxTypeCount];
356645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org};
366645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
37cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.orgconst char* kBBoxHierarchyTypeNames[kBBoxTypeCount] = {
38cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    "none", // kNone_BBoxHierarchyType
39cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    "rtree", // kRTree_BBoxHierarchyType
40cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    "tilegrid", // kTileGrid_BBoxHierarchyType
416645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org};
426645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
436645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.orgstatic SkPicture* pic_from_path(const char path[]) {
446645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkFILEStream stream(path);
456645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    if (!stream.isValid()) {
466645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        SkDebugf("-- Can't open '%s'\n", path);
476645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        return NULL;
486645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
496645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    return SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap);
506645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org}
516645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
526645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org/**
536645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org * This function is the sink to which all work ends up going.
54cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org * @param renderer The renderer to use to perform the work.
55cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org *                 To measure rendering, use a TiledPictureRenderer.
56cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org *                 To measure recording, use a RecordPictureRenderer.
57cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org * @param bBoxType The bounding box hierarchy type to use.
58cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org * @param pic The picture to draw to the renderer.
59cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org * @param numRepeats The number of times to repeat the draw.
60cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org * @param timer The timer used to benchmark the work.
616645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org */
626645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.orgstatic void do_benchmark_work(sk_tools::PictureRenderer* renderer,
63cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        BBoxType bBoxType,
64cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        SkPicture* pic,
65cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        const int numRepeats,
669ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein        Timer* timer) {
67cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    renderer->setBBoxHierarchyType(bBoxType);
68cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    renderer->setGridSize(FLAGS_tilesize, FLAGS_tilesize);
693f0451772109959fcb79bacf2c9a03e0eb39ff27commit-bot@chromium.org    renderer->init(pic, NULL, NULL, NULL, false);
706645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
71cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    SkDebugf("%s %d times...\n", renderer->getConfigName().c_str(), numRepeats);
726645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    for (int i = 0; i < numRepeats; ++i) {
736645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        renderer->setup();
74cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        // Render once to fill caches
75f5e315ccf1ae2941f7cf53fa53e5c8c4bb665fe1commit-bot@chromium.org        renderer->render();
766645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        // Render again to measure
776645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        timer->start();
78f5e315ccf1ae2941f7cf53fa53e5c8c4bb665fe1commit-bot@chromium.org        renderer->render();
796645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        timer->end();
806645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
816645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org}
826645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
831d38ae9162d9702a8999e1fe872ead3e0a3f1181sglez@google.comint tool_main(int argc, char** argv);
841d38ae9162d9702a8999e1fe872ead3e0a3f1181sglez@google.comint tool_main(int argc, char** argv) {
85cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    SkCommandLineFlags::Parse(argc, argv);
866645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkAutoGraphics ag;
87cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    bool includeBBoxType[kBBoxTypeCount];
88cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
89f16d797497aff698e4dfcef0885dce04915a8c36commit-bot@chromium.org        includeBBoxType[bBoxType] = (FLAGS_bb_types.count() == 0) ||
90f16d797497aff698e4dfcef0885dce04915a8c36commit-bot@chromium.org            FLAGS_bb_types.contains(kBBoxHierarchyTypeNames[bBoxType]);
91cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    }
92cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    // go through all the pictures
93cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    SkTArray<Measurement> measurements;
94cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    for (int index = 0; index < FLAGS_skps.count(); ++index) {
95cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        const char* path = FLAGS_skps[index];
96cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        SkPicture* picture = pic_from_path(path);
97cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        if (NULL == picture) {
98cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            SkDebugf("Couldn't create picture. Ignoring path: %s\n", path);
99cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            continue;
100cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        }
101cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        SkDebugf("Benchmarking path: %s\n", path);
102cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        Measurement& measurement = measurements.push_back();
103cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        measurement.fName = path;
104cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
105cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            if (!includeBBoxType[bBoxType]) { continue; }
106cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            if (FLAGS_playback > 0) {
107b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#if SK_SUPPORT_GPU
108b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski                GrContext::Options grContextOpts;
109b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski                sk_tools::TiledPictureRenderer playbackRenderer(grContextOpts);
110b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#else
111cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                sk_tools::TiledPictureRenderer playbackRenderer;
112b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#endif
1139ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein                Timer playbackTimer;
114cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                do_benchmark_work(&playbackRenderer, (BBoxType)bBoxType,
115cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                                  picture, FLAGS_playback, &playbackTimer);
116cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                measurement.fPlaybackAverage[bBoxType] = playbackTimer.fCpu;
117cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            }
118cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            if (FLAGS_record > 0) {
119b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#if SK_SUPPORT_GPU
120b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski                GrContext::Options grContextOpts;
121b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski                sk_tools::RecordPictureRenderer recordRenderer(grContextOpts);
122b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#else
123cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                sk_tools::RecordPictureRenderer recordRenderer;
124b1aded8edd1d809cded20ff546c6e9218b43cda4krajcevski#endif
1259ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein                Timer recordTimer;
126cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                do_benchmark_work(&recordRenderer, (BBoxType)bBoxType,
127cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                                  picture, FLAGS_record, &recordTimer);
128cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                measurement.fRecordAverage[bBoxType] = recordTimer.fCpu;
129cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            }
130cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        }
1316645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
1326645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
133cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    Measurement globalMeasurement;
134cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
135cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        if (!includeBBoxType[bBoxType]) { continue; }
136cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        globalMeasurement.fPlaybackAverage[bBoxType] = 0;
137cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        globalMeasurement.fRecordAverage[bBoxType] = 0;
138cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        for (int index = 0; index < measurements.count(); ++index) {
139cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            const Measurement& measurement = measurements[index];
140cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            globalMeasurement.fPlaybackAverage[bBoxType] +=
141cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                measurement.fPlaybackAverage[bBoxType];
142cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            globalMeasurement.fRecordAverage[bBoxType] +=
143cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                measurement.fRecordAverage[bBoxType];
144cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        }
145cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        globalMeasurement.fPlaybackAverage[bBoxType] /= measurements.count();
146cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        globalMeasurement.fRecordAverage[bBoxType] /= measurements.count();
1476645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
1486645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
1496645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    // Output gnuplot readable histogram data..
1506645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    const char* pbTitle = "bbh_shootout_playback.dat";
1516645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    const char* recTitle = "bbh_shootout_record.dat";
1526645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkFILEWStream playbackOut(pbTitle);
1536645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkFILEWStream recordOut(recTitle);
1546645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    recordOut.writeText("# ");
1556645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    playbackOut.writeText("# ");
156cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    SkDebugf("---\n");
157cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
158cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        if (!includeBBoxType[bBoxType]) { continue; }
1596645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        SkString out;
160cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        out.printf("%s ", kBBoxHierarchyTypeNames[bBoxType]);
161cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        recordOut.writeText(out.c_str());
162cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        playbackOut.writeText(out.c_str());
163cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org
164cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        if (FLAGS_record > 0) {
165cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            SkDebugf("Average %s recording time: %.3fms\n",
166cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                kBBoxHierarchyTypeNames[bBoxType],
167cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                globalMeasurement.fRecordAverage[bBoxType]);
1686645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        }
169cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        if (FLAGS_playback > 0) {
170cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            SkDebugf("Average %s playback time: %.3fms\n",
171cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                kBBoxHierarchyTypeNames[bBoxType],
172cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org                globalMeasurement.fPlaybackAverage[bBoxType]);
1736645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        }
1746645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
1756645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    recordOut.writeText("\n");
1766645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    playbackOut.writeText("\n");
1772e915b32347aa2c2bcf82aba57c325b8fb81ec53commit-bot@chromium.org    // Write to file, and save recording averages.
178cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org    for (int index = 0; index < measurements.count(); ++index) {
179cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        const Measurement& measurement = measurements[index];
1806645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        SkString pbLine;
1816645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        SkString recLine;
1826645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
183cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        pbLine.printf("%d", index);
184cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        recLine.printf("%d", index);
185cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org        for (int bBoxType = 0; bBoxType < kBBoxTypeCount; ++bBoxType) {
186cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            if (!includeBBoxType[bBoxType]) { continue; }
187cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            pbLine.appendf(" %f", measurement.fPlaybackAverage[bBoxType]);
188cdd0f92b1aca0c2164ac1a24d7f14a6ad3cc10f5commit-bot@chromium.org            recLine.appendf(" %f", measurement.fRecordAverage[bBoxType]);
1896645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        }
1906645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        pbLine.appendf("\n");
1916645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        recLine.appendf("\n");
1926645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        playbackOut.writeText(pbLine.c_str());
1936645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org        recordOut.writeText(recLine.c_str());
1946645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    }
1956645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    SkDebugf("\nWrote data to gnuplot-readable files: %s %s\n", pbTitle, recTitle);
1966645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    return 0;
1976645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org}
1986645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org
1995f3f681db58d613f5b96caa0af45ba15f776fe96sglez@google.com#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2006645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.orgint main(int argc, char** argv) {
2016645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org    return tool_main(argc, argv);
2026645cde43d7dbf0df76dbda2c089d8f58560e3e2commit-bot@chromium.org}
2035f3f681db58d613f5b96caa0af45ba15f776fe96sglez@google.com#endif
204