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