blob: 41f3ae3b1a5b46c88a641053422c2c38b723ac3e [file] [log] [blame]
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +00001/*
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 */
tfarinaf168b862014-06-19 12:32:29 -07009
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000010#ifndef SkResultsWriter_DEFINED
11#define SkResultsWriter_DEFINED
12
Brian Osman8c0a1ca2019-01-28 14:24:29 -050013#include "SkJSONWriter.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000014#include "SkString.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000015#include "SkTypes.h"
16
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000017/**
Brian Osman8c0a1ca2019-01-28 14:24:29 -050018 NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
jcgregoriobf5e5232014-07-17 13:14:16 -070019
20 {
21 "key": {
22 "arch": "Arm7",
23 "gpu": "SGX540",
24 "os": "Android",
25 "model": "GalaxyNexus",
26 }
jcgregoriobf5e5232014-07-17 13:14:16 -070027 "gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
mtklein1915b622014-08-20 11:45:00 -070028 "build_number": "1234",
jcgregoriobf5e5232014-07-17 13:14:16 -070029 "results" : {
30 "Xfermode_Luminosity_640_480" : {
31 "8888" : {
32 "median_ms" : 143.188128906250,
33 "min_ms" : 143.835957031250,
34 ...
35 },
36 ...
37*/
Brian Osman8c0a1ca2019-01-28 14:24:29 -050038class NanoJSONResultsWriter : public SkJSONWriter {
jcgregoriobf5e5232014-07-17 13:14:16 -070039public:
Brian Osman8c0a1ca2019-01-28 14:24:29 -050040 NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
mtklein1915b622014-08-20 11:45:00 -070041
Brian Osman8c0a1ca2019-01-28 14:24:29 -050042 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());
jcgregoriobf5e5232014-07-17 13:14:16 -070045 }
mtklein1915b622014-08-20 11:45:00 -070046
Brian Osman8c0a1ca2019-01-28 14:24:29 -050047 void endBench() { this->endObject(); }
48
49 void appendMetric(const char* name, double value) {
jcgregoriobf5e5232014-07-17 13:14:16 -070050 // Don't record if nan, or -nan.
Brian Osman8c0a1ca2019-01-28 14:24:29 -050051 if (!sk_double_isnan(value)) {
52 this->appendDoubleDigits(name, value, 16);
jcgregoriobf5e5232014-07-17 13:14:16 -070053 }
jcgregoriobf5e5232014-07-17 13:14:16 -070054 }
jcgregoriobf5e5232014-07-17 13:14:16 -070055};
56
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000057#endif