• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  *
7  * Classes for writing out bench results in various formats.
8  */
9 
10 #ifndef SkResultsWriter_DEFINED
11 #define SkResultsWriter_DEFINED
12 
13 #include "SkJSONWriter.h"
14 #include "SkString.h"
15 #include "SkTypes.h"
16 
17 /**
18  NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
19 
20  {
21     "key": {
22       "arch": "Arm7",
23       "gpu": "SGX540",
24       "os": "Android",
25       "model": "GalaxyNexus",
26     }
27     "gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
28     "build_number": "1234",
29     "results" : {
30         "Xfermode_Luminosity_640_480" : {
31            "8888" : {
32                  "median_ms" : 143.188128906250,
33                  "min_ms" : 143.835957031250,
34                  ...
35               },
36           ...
37 */
38 class NanoJSONResultsWriter : public SkJSONWriter {
39 public:
NanoJSONResultsWriter(SkWStream * stream,Mode mode)40     NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
41 
beginBench(const char * name,int32_t x,int32_t y)42     void beginBench(const char* name, int32_t x, int32_t y) {
43         SkString id = SkStringPrintf("%s_%d_%d", name, x, y);
44         this->beginObject(id.c_str());
45     }
46 
endBench()47     void endBench() { this->endObject(); }
48 
appendMetric(const char * name,double value)49     void appendMetric(const char* name, double value) {
50         // Don't record if nan, or -nan.
51         if (!sk_double_isnan(value)) {
52             this->appendDoubleDigits(name, value, 16);
53         }
54     }
55 };
56 
57 #endif
58