ResultsWriter.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. */
  9. #ifndef SkResultsWriter_DEFINED
  10. #define SkResultsWriter_DEFINED
  11. #include "include/core/SkString.h"
  12. #include "include/core/SkTypes.h"
  13. #include "src/utils/SkJSONWriter.h"
  14. /**
  15. NanoJSONResultsWriter helps nanobench writes the test results out in the following format:
  16. {
  17. "key": {
  18. "arch": "Arm7",
  19. "gpu": "SGX540",
  20. "os": "Android",
  21. "model": "GalaxyNexus",
  22. }
  23. "gitHash": "d1830323662ae8ae06908b97f15180fd25808894",
  24. "build_number": "1234",
  25. "results" : {
  26. "Xfermode_Luminosity_640_480" : {
  27. "8888" : {
  28. "median_ms" : 143.188128906250,
  29. "min_ms" : 143.835957031250,
  30. ...
  31. },
  32. ...
  33. */
  34. class NanoJSONResultsWriter : public SkJSONWriter {
  35. public:
  36. NanoJSONResultsWriter(SkWStream* stream, Mode mode) : SkJSONWriter(stream, mode) {}
  37. void beginBench(const char* name, int32_t x, int32_t y) {
  38. SkString id = SkStringPrintf("%s_%d_%d", name, x, y);
  39. this->beginObject(id.c_str());
  40. }
  41. void endBench() { this->endObject(); }
  42. void appendMetric(const char* name, double value) {
  43. // Don't record if nan, or -nan.
  44. if (!sk_double_isnan(value)) {
  45. this->appendDoubleDigits(name, value, 16);
  46. }
  47. }
  48. };
  49. #endif