commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 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 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 9 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 10 | #ifndef SkResultsWriter_DEFINED |
| 11 | #define SkResultsWriter_DEFINED |
| 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkString.h" |
| 14 | #include "include/core/SkTypes.h" |
| 15 | #include "src/utils/SkJSONWriter.h" |
Joe Gregorio | 3d808f4 | 2021-06-09 12:59:31 -0400 | [diff] [blame] | 16 | #include <cmath> |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 17 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 18 | /** |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 19 | NanoJSONResultsWriter helps nanobench writes the test results out in the following format: |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 20 | |
| 21 | { |
| 22 | "key": { |
| 23 | "arch": "Arm7", |
| 24 | "gpu": "SGX540", |
| 25 | "os": "Android", |
| 26 | "model": "GalaxyNexus", |
| 27 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 28 | "gitHash": "d1830323662ae8ae06908b97f15180fd25808894", |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 29 | "build_number": "1234", |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 30 | "results" : { |
| 31 | "Xfermode_Luminosity_640_480" : { |
| 32 | "8888" : { |
| 33 | "median_ms" : 143.188128906250, |
| 34 | "min_ms" : 143.835957031250, |
| 35 | ... |
| 36 | }, |
| 37 | ... |
| 38 | */ |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 39 | class NanoJSONResultsWriter : public SkJSONWriter { |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 40 | public: |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 41 | NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {} |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 42 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 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()); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 46 | } |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 47 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 48 | void endBench() { this->endObject(); } |
| 49 | |
| 50 | void appendMetric(const char* name, double value) { |
Joe Gregorio | 3d808f4 | 2021-06-09 12:59:31 -0400 | [diff] [blame] | 51 | // Don't record if NaN or Inf. |
| 52 | if (std::isfinite(value)) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 53 | this->appendDoubleDigits(name, value, 16); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 54 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 55 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 58 | #endif |