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 #if !defined(ANGLE_HAS_HISTOGRAMS)
13 # error "Requires ANGLE_HAS_HISTOGRAMS, see angle_maybe_has_histograms"
14 #endif // !defined(ANGLE_HAS_HISTOGRAMS)
15
16 #include <map>
17 #include <memory>
18 #include <string>
19
20 // Include forward delcarations for rapidjson types.
21 #include <rapidjson/fwd.h>
22
23 namespace catapult
24 {
25 class HistogramBuilder;
26 } // namespace catapult
27
28 namespace angle
29 {
30 class HistogramWriter
31 {
32 public:
33 HistogramWriter();
34 ~HistogramWriter();
35
36 void addSample(const std::string &measurement,
37 const std::string &story,
38 double value,
39 const std::string &units);
40
41 void getAsJSON(rapidjson::Document *doc) const;
42
43 private:
44 #if ANGLE_HAS_HISTOGRAMS
45 std::map<std::string, std::unique_ptr<catapult::HistogramBuilder>> mHistograms;
46 #endif // ANGLE_HAS_HISTOGRAMS
47 };
48
49 // Define a stub implementation when histograms are compiled out.
50 #if !ANGLE_HAS_HISTOGRAMS
51 inline HistogramWriter::HistogramWriter() = default;
52 inline HistogramWriter::~HistogramWriter() = default;
addSample(const std::string & measurement,const std::string & story,double value,const std::string & units)53 inline void HistogramWriter::addSample(const std::string &measurement,
54 const std::string &story,
55 double value,
56 const std::string &units)
57 {}
getAsJSON(rapidjson::Document * doc)58 inline void HistogramWriter::getAsJSON(rapidjson::Document *doc) const {}
59 #endif // !ANGLE_HAS_HISTOGRAMS
60
61 } // namespace angle
62
63 #endif // ANGLE_TESTS_TEST_UTILS_HISTOGRAM_WRITER_H_
64