137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org/*
237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * Copyright 2014 Google Inc.
337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *
437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * found in the LICENSE file.
637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *
737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * Classes for writing out bench results in various formats.
837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org */
9f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina
1037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#ifndef SkPictureResultsWriter_DEFINED
1137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#define SkPictureResultsWriter_DEFINED
1237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
13f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "BenchLogger.h"
1437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#include "ResultsWriter.h"
1537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#include "SkJSONCPP.h"
1637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#include "SkStream.h"
1737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#include "SkString.h"
1837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#include "SkTArray.h"
19f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "TimerData.h"
2037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
2137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org/**
2237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * Base class for writing picture bench results.
2337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org */
2437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgclass PictureResultsWriter : SkNoncopyable {
2537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgpublic:
2637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    enum TileFlags {kPurging, kAvg};
2737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
2837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    PictureResultsWriter() {}
2937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual ~PictureResultsWriter() {}
3037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
3137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void bench(const char name[], int32_t x, int32_t y) = 0;
3237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileConfig(SkString configName) = 0;
3337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileMeta(int x, int y, int tx, int ty) = 0;
3437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void addTileFlag(PictureResultsWriter::TileFlags flag) = 0;
3537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileData(
369681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            TimerData* data,
379681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            const char format[],
3837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            const TimerData::Result result,
3937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            uint32_t timerTypes,
4037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            int numInnerLoops = 1) = 0;
4137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org   virtual void end() = 0;
4237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org};
4337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
4437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org/**
4537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * This class allows bench data to be piped into multiple
4637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * PictureResultWriter classes. It does not own any classes
4737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * passed to it, so the owner is required to manage any classes
4837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * passed to PictureResultsMultiWriter */
4937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgclass PictureResultsMultiWriter : public PictureResultsWriter {
5037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgpublic:
519681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com    PictureResultsMultiWriter()
5237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        : fWriters() {}
5337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    void add(PictureResultsWriter* newWriter) {
5437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        fWriters.push_back(newWriter);
5537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
5637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual ~PictureResultsMultiWriter() {}
5737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void bench(const char name[], int32_t x, int32_t y) {
5837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
5937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fWriters[i]->bench(name, x, y);
6037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
6137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
6237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileConfig(SkString configName) {
6337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
6437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fWriters[i]->tileConfig(configName);
6537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
6637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
6737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileMeta(int x, int y, int tx, int ty) {
6837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
6937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fWriters[i]->tileMeta(x, y, tx, ty);
7037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
7137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
7237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
7337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
7437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fWriters[i]->addTileFlag(flag);
7537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
7637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
7737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileData(
789681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            TimerData* data,
799681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            const char format[],
8037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            const TimerData::Result result,
8137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            uint32_t timerTypes,
8237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            int numInnerLoops = 1) {
8337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
849681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            fWriters[i]->tileData(data, format, result, timerTypes,
8537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org                                 numInnerLoops);
8637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
8737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
8837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org   virtual void end() {
8937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        for(int i=0; i<fWriters.count(); ++i) {
9037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fWriters[i]->end();
9137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
9237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org   }
9337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgprivate:
9437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    SkTArray<PictureResultsWriter*> fWriters;
9537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org};
9637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
9737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org/**
98f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina * Writes to BenchLogger to mimic original behavior
9937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org */
1009681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.comclass PictureResultsLoggerWriter : public PictureResultsWriter {
10137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgprivate:
10237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    void logProgress(const char str[]) {
10337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        if(fLogger != NULL) {
10437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            fLogger->logProgress(str);
10537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
10637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
10737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgpublic:
108f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina    PictureResultsLoggerWriter(BenchLogger* log)
10937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org          : fLogger(log), currentLine() {}
11037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void bench(const char name[], int32_t x, int32_t y) {
11137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkString result;
11237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        result.printf("running bench [%i %i] %s ", x, y, name);
11337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        this->logProgress(result.c_str());
11437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
11537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileConfig(SkString configName) {
11637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        currentLine = configName;
11737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
11837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileMeta(int x, int y, int tx, int ty) {
11937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        currentLine.appendf(": tile [%i,%i] out of [%i,%i]", x, y, tx, ty);
12037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
12137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
12237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        if(flag == PictureResultsWriter::kPurging) {
12337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            currentLine.append(" <withPurging>");
12437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        } else if(flag == PictureResultsWriter::kAvg) {
12537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            currentLine.append(" <averaged>");
12637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
12737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
12837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileData(
1299681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            TimerData* data,
1309681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            const char format[],
13137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            const TimerData::Result result,
13237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            uint32_t timerTypes,
13337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            int numInnerLoops = 1) {
13437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkString results = data->getResult(format, result,
13537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org                currentLine.c_str(), timerTypes, numInnerLoops);
13637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        results.append("\n");
13737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        this->logProgress(results.c_str());
13837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
13937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void end() {}
14037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgprivate:
141f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina    BenchLogger* fLogger;
14237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    SkString currentLine;
14337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org};
14437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
14537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org/**
14637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * This PictureResultsWriter collects data in a JSON node
14737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *
14837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * The format is something like
14937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * {
15037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *      benches: [
15137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *          {
15237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *              name: "Name_of_test"
15337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *              tilesets: [
15437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                  {
15537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                      name: "Name of the configuration"
15637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                      tiles: [
15737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                          {
15837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                              flags: {
15937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                                  purging: true //Flags for the current tile
16037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                                              // are put here
16137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                              }
16237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                              data: {
16337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                                  wsecs: [....] //Actual data ends up here
16437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                              }
16537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                          }
16637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                      ]
16737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *                  }
16837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *              ]
16937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *          }
17037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org *      ]
17137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org * }*/
17237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
17337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgclass PictureJSONResultsWriter : public PictureResultsWriter {
17437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgpublic:
17537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    PictureJSONResultsWriter(const char filename[])
17637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        : fFilename(filename),
1779681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com          fRoot(),
17837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org          fCurrentBench(NULL),
17937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org          fCurrentTileSet(NULL),
18037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org          fCurrentTile(NULL) {}
18137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
18237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void bench(const char name[], int32_t x, int32_t y) {
18337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkString sk_name(name);
18437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        sk_name.append("_");
18537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        sk_name.appendS32(x);
18637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        sk_name.append("_");
18737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        sk_name.appendS32(y);
18837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        Json::Value* bench_node = SkFindNamedNode(&fRoot["benches"], sk_name.c_str());
18937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        fCurrentBench = &(*bench_node)["tileSets"];
19037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
19137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileConfig(SkString configName) {
19237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkASSERT(fCurrentBench != NULL);
19337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        fCurrentTileSet = SkFindNamedNode(fCurrentBench, configName.c_str());
19437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        fCurrentTile = &(*fCurrentTileSet)["tiles"][0];
19537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
19637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileMeta(int x, int y, int tx, int ty) {
19737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkASSERT(fCurrentTileSet != NULL);
19837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        (*fCurrentTileSet)["tx"] = tx;
19937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        (*fCurrentTileSet)["ty"] = ty;
20037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        fCurrentTile = &(*fCurrentTileSet)["tiles"][x+tx*y];
20137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
20237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void addTileFlag(PictureResultsWriter::TileFlags flag) {
20337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkASSERT(fCurrentTile != NULL);
20437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        if(flag == PictureResultsWriter::kPurging) {
20537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            (*fCurrentTile)["flags"]["purging"] = true;
20637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        } else if(flag == PictureResultsWriter::kAvg) {
20737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            (*fCurrentTile)["flags"]["averaged"] = true;
20837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        }
20937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
21037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void tileData(
2119681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            TimerData* data,
2129681eebb0e441cee25b6faac82c3728512acda27skia.committer@gmail.com            const char format[],
21337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            const TimerData::Result result,
21437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            uint32_t timerTypes,
21537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org            int numInnerLoops = 1) {
21637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        SkASSERT(fCurrentTile != NULL);
21737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org        (*fCurrentTile)["data"] = data->getJSON(timerTypes, result, numInnerLoops);
21837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
21937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    virtual void end() {
22037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org       SkFILEWStream stream(fFilename.c_str());
22137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org       stream.writeText(Json::FastWriter().write(fRoot).c_str());
22237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org       stream.flush();
22337c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    }
22437c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.orgprivate:
22537c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    SkString fFilename;
22637c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    Json::Value fRoot;
22737c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    Json::Value *fCurrentBench;
22837c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    Json::Value *fCurrentTileSet;
22937c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org    Json::Value *fCurrentTile;
23037c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org};
23137c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org
23237c772ae2d96dad9b6e430e9bb6450193a545021commit-bot@chromium.org#endif
233