2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 * Classes for writing out bench results in various formats.
10 #ifndef SkResultsWriter_DEFINED
11 #define SkResultsWriter_DEFINED
13 #include "include/core/SkString.h"
14 #include "include/core/SkTypes.h"
15 #include "src/utils/SkJSONWriter.h"
19 NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
26 "model": "GalaxyNexus",
28 "gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
29 "build_number": "1234",
31 "Xfermode_Luminosity_640_480" : {
33 "median_ms" : 143.188128906250,
34 "min_ms" : 143.835957031250,
39 class NanoJSONResultsWriter : public SkJSONWriter {
41 NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
43 void beginBench(const char* name, int32_t x, int32_t y) {
44 SkString id = SkStringPrintf("%s_%d_%d", name, x, y);
45 this->beginObject(id.c_str());
48 void endBench() { this->endObject(); }
50 void appendMetric(const char* name, double value) {
51 // Don't record if NaN or Inf.
52 if (std::isfinite(value)) {
53 this->appendDoubleDigits(name, value, 16);