1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // HistogramWriter:
7 // Helper class for writing histogram-json-set-format files to JSON.
8
9 #ifndef ANGLE_TESTS_TEST_UTILS_HISTOGRAM_WRITER_H_
10 #define ANGLE_TESTS_TEST_UTILS_HISTOGRAM_WRITER_H_
11
12 #include <map>
13 #include <memory>
14 #include <string>
15
16 // Include forward delcarations for rapidjson types.
17 #include <rapidjson/fwd.h>
18
19 namespace catapult
20 {
21 class HistogramBuilder;
22 } // namespace catapult
23
24 namespace angle
25 {
26 class HistogramWriter
27 {
28 public:
29 HistogramWriter();
30 ~HistogramWriter();
31
32 void addSample(const std::string &measurement,
33 const std::string &story,
34 double value,
35 const std::string &units);
36
37 void getAsJSON(rapidjson::Document *doc) const;
38
39 private:
40 #if defined(ANGLE_HAS_HISTOGRAMS)
41 std::map<std::string, std::unique_ptr<catapult::HistogramBuilder>> mHistograms;
42 #endif // defined(ANGLE_HAS_HISTOGRAMS)
43 };
44
45 // Define a stub implementation when histograms are compiled out.
46 #if !defined(ANGLE_HAS_HISTOGRAMS)
47 inline HistogramWriter::HistogramWriter() = default;
48 inline HistogramWriter::~HistogramWriter() = default;
addSample(const std::string & measurement,const std::string & story,double value,const std::string & units)49 inline void HistogramWriter::addSample(const std::string &measurement,
50 const std::string &story,
51 double value,
52 const std::string &units)
53 {}
getAsJSON(rapidjson::Document * doc)54 inline void HistogramWriter::getAsJSON(rapidjson::Document *doc) const {}
55 #endif // !defined(ANGLE_HAS_HISTOGRAMS)
56
57 } // namespace angle
58
59 #endif // ANGLE_TESTS_TEST_UTILS_HISTOGRAM_WRITER_H_
60