2013-12-03 18:16:48 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
|
2013-12-03 18:16:48 +00:00
|
|
|
#ifndef SkResultsWriter_DEFINED
|
|
|
|
#define SkResultsWriter_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-10-23 20:35:19 +00:00
|
|
|
#include "src/core/SkOSFile.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkJSONWriter.h"
|
2013-12-03 18:16:48 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-28 19:24:29 +00:00
|
|
|
NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
|
2014-07-17 20:14:16 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"key": {
|
|
|
|
"arch": "Arm7",
|
|
|
|
"gpu": "SGX540",
|
|
|
|
"os": "Android",
|
|
|
|
"model": "GalaxyNexus",
|
|
|
|
}
|
|
|
|
"gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
|
2014-08-20 18:45:00 +00:00
|
|
|
"build_number": "1234",
|
2014-07-17 20:14:16 +00:00
|
|
|
"results" : {
|
|
|
|
"Xfermode_Luminosity_640_480" : {
|
|
|
|
"8888" : {
|
|
|
|
"median_ms" : 143.188128906250,
|
|
|
|
"min_ms" : 143.835957031250,
|
|
|
|
...
|
|
|
|
},
|
|
|
|
...
|
|
|
|
*/
|
2019-01-28 19:24:29 +00:00
|
|
|
class NanoJSONResultsWriter : public SkJSONWriter {
|
2014-07-17 20:14:16 +00:00
|
|
|
public:
|
2019-01-28 19:24:29 +00:00
|
|
|
NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
|
2014-08-20 18:45:00 +00:00
|
|
|
|
2019-01-28 19:24:29 +00:00
|
|
|
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());
|
2014-07-17 20:14:16 +00:00
|
|
|
}
|
2014-08-20 18:45:00 +00:00
|
|
|
|
2019-01-28 19:24:29 +00:00
|
|
|
void endBench() { this->endObject(); }
|
2014-05-20 17:35:10 +00:00
|
|
|
|
2019-01-28 19:24:29 +00:00
|
|
|
void appendMetric(const char* name, double value) {
|
|
|
|
// Don't record if nan, or -nan.
|
|
|
|
if (!sk_double_isnan(value)) {
|
|
|
|
this->appendDoubleDigits(name, value, 16);
|
2015-08-20 16:12:39 +00:00
|
|
|
}
|
2014-10-14 15:40:43 +00:00
|
|
|
}
|
2013-12-03 18:16:48 +00:00
|
|
|
};
|
|
|
|
|
2019-10-23 20:35:19 +00:00
|
|
|
/**
|
|
|
|
NanoFILEAppendAndCloseStream: re-open the file, append the data, then close on every write() call.
|
|
|
|
|
|
|
|
The purpose of this class is to not keep the file handle open between JSON flushes. SkJSONWriter
|
|
|
|
uses a 32k in-memory cache already, so it only flushes occasionally and is well equipped for a
|
|
|
|
steam like this.
|
|
|
|
|
|
|
|
See: https://b.corp.google.com/issues/143074513
|
|
|
|
*/
|
|
|
|
class NanoFILEAppendAndCloseStream : public SkWStream {
|
|
|
|
public:
|
|
|
|
NanoFILEAppendAndCloseStream(const char* filePath) : fFilePath(filePath) {
|
|
|
|
// Open the file as "write" to ensure it exists and clear any contents before we begin
|
|
|
|
// appending.
|
|
|
|
FILE* file = sk_fopen(fFilePath.c_str(), kWrite_SkFILE_Flag);
|
|
|
|
if (!file) {
|
|
|
|
SkDebugf("Failed to open file %s for write.\n", fFilePath.c_str());
|
|
|
|
fFilePath.reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sk_fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bytesWritten() const override { return fBytesWritten; }
|
|
|
|
|
|
|
|
bool write(const void* buffer, size_t size) override {
|
|
|
|
if (fFilePath.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* file = sk_fopen(fFilePath.c_str(), kAppend_SkFILE_Flag);
|
|
|
|
if (!file) {
|
|
|
|
SkDebugf("Failed to open file %s for append.\n", fFilePath.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bytesWritten = sk_fwrite(buffer, size, file);
|
|
|
|
fBytesWritten += bytesWritten;
|
|
|
|
sk_fclose(file);
|
|
|
|
|
|
|
|
if (bytesWritten != size) {
|
|
|
|
SkDebugf("NanoFILEAppendAndCloseStream failed writing %d bytes (wrote %d instead)\n",
|
|
|
|
size, bytesWritten);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush() override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fFilePath;
|
|
|
|
size_t fBytesWritten = 0;
|
|
|
|
};
|
|
|
|
|
2013-12-03 18:16:48 +00:00
|
|
|
#endif
|