blob: cb33915fc9be0cc59ad1e0cfcbf23015c115149f [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkString.h"
14#include "include/core/SkTypes.h"
15#include "src/utils/SkJSONWriter.h"
Joe Gregorio3d808f42021-06-09 12:59:31 -040016#include <cmath>
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000017
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000018/**
Brian Osman8c0a1ca2019-01-28 14:24:29 -050019 NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
jcgregoriobf5e5232014-07-17 13:14:16 -070020
21 {
22 "key": {
23 "arch": "Arm7",
24 "gpu": "SGX540",
25 "os": "Android",
26 "model": "GalaxyNexus",
27 }
jcgregoriobf5e5232014-07-17 13:14:16 -070028 "gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
mtklein1915b622014-08-20 11:45:00 -070029 "build_number": "1234",
jcgregoriobf5e5232014-07-17 13:14:16 -070030 "results" : {
31 "Xfermode_Luminosity_640_480" : {
32 "8888" : {
33 "median_ms" : 143.188128906250,
34 "min_ms" : 143.835957031250,
35 ...
36 },
37 ...
38*/
Brian Osman8c0a1ca2019-01-28 14:24:29 -050039class NanoJSONResultsWriter : public SkJSONWriter {
jcgregoriobf5e5232014-07-17 13:14:16 -070040public:
Brian Osman8c0a1ca2019-01-28 14:24:29 -050041 NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
mtklein1915b622014-08-20 11:45:00 -070042
Brian Osman8c0a1ca2019-01-28 14:24:29 -050043 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());
jcgregoriobf5e5232014-07-17 13:14:16 -070046 }
mtklein1915b622014-08-20 11:45:00 -070047
Brian Osman8c0a1ca2019-01-28 14:24:29 -050048 void endBench() { this->endObject(); }
49
50 void appendMetric(const char* name, double value) {
Joe Gregorio3d808f42021-06-09 12:59:31 -040051 // Don't record if NaN or Inf.
52 if (std::isfinite(value)) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -050053 this->appendDoubleDigits(name, value, 16);
jcgregoriobf5e5232014-07-17 13:14:16 -070054 }
jcgregoriobf5e5232014-07-17 13:14:16 -070055 }
jcgregoriobf5e5232014-07-17 13:14:16 -070056};
57
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000058#endif