xref: /aosp_15_r20/external/cronet/base/test/metrics/histogram_enum_reader.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_METRICS_HISTOGRAM_ENUM_READER_H_
6 #define BASE_TEST_METRICS_HISTOGRAM_ENUM_READER_H_
7 
8 #include <map>
9 #include <optional>
10 #include <string>
11 
12 #include "base/metrics/histogram_base.h"
13 
14 namespace base {
15 
16 using HistogramEnumEntryMap = std::map<HistogramBase::Sample, std::string>;
17 
18 // Find and read the enum with the given |enum_name| (with integer values) from
19 // tools/metrics/histograms/enums.xml, or from enums.xml in the given
20 // |subdirectory| of tools/metrics/histograms/metadata.
21 //
22 // Returns map { value => label } so that:
23 //   <int value="9" label="enable-pinch-virtual-viewport"/>
24 // becomes:
25 //   { 9 => "enable-pinch-virtual-viewport" }
26 // Returns empty std::nullopt on failure.
27 std::optional<HistogramEnumEntryMap> ReadEnumFromEnumsXml(
28     const std::string& enum_name,
29     const std::optional<std::string>& subdirectory = std::nullopt);
30 
31 }  // namespace base
32 
33 #endif  // BASE_TEST_METRICS_HISTOGRAM_ENUM_READER_H_
34