skia2/bench/ResultsWriter.h
Herb Derby efe9df37e0 Revert "Don't keep "outResultsFile" open in nanobench"
This reverts commit 2e1381ec86.

Reason for revert: This causes corrupted JSON output from
                   nanobench

Bug: skia:12078

Original change's description:
> Don't keep "outResultsFile" open in nanobench
>
> There is a bug on Pixel and Pixel2 devices where the program
> eventually terminates with a non-zero exit code. Closing the
> outResultsFile between JSON flushes seems to fix it (for whatever
> reason).
>
> Bug: b/143074513
> Change-Id: I935e982e88758fda19292129c8031f8501cca615
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249821
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Chris Dalton <csmartdalton@google.com>

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: b/143074513
Change-Id: Iad8e4423acbc520f49365859020776110087dacc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419842
Reviewed-by: Herb Derby <herb@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Herb Derby <herb@google.com>
2021-06-19 22:12:48 +00:00

59 lines
1.5 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Classes for writing out bench results in various formats.
*/
#ifndef SkResultsWriter_DEFINED
#define SkResultsWriter_DEFINED
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "src/utils/SkJSONWriter.h"
#include <cmath>
/**
NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
{
"key": {
"arch": "Arm7",
"gpu": "SGX540",
"os": "Android",
"model": "GalaxyNexus",
}
"gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
"build_number": "1234",
"results" : {
"Xfermode_Luminosity_640_480" : {
"8888" : {
"median_ms" : 143.188128906250,
"min_ms" : 143.835957031250,
...
},
...
*/
class NanoJSONResultsWriter : public SkJSONWriter {
public:
NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
void beginBench(const char* name, int32_t x, int32_t y) {
SkString id = SkStringPrintf("%s_%d_%d", name, x, y);
this->beginObject(id.c_str());
}
void endBench() { this->endObject(); }
void appendMetric(const char* name, double value) {
// Don't record if NaN or Inf.
if (std::isfinite(value)) {
this->appendDoubleDigits(name, value, 16);
}
}
};
#endif