• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "perf_result_reporter.h"
6 #include "anglebase/logging.h"
7 #include "perf_test.h"
8 
9 namespace perf_test
10 {
11 
PerfResultReporter(const std::string & metric_basename,const std::string & story_name)12 PerfResultReporter::PerfResultReporter(const std::string &metric_basename,
13                                        const std::string &story_name)
14     : metric_basename_(metric_basename), story_name_(story_name)
15 {}
16 
17 PerfResultReporter::~PerfResultReporter() = default;
18 
RegisterFyiMetric(const std::string & metric_suffix,const std::string & units)19 void PerfResultReporter::RegisterFyiMetric(const std::string &metric_suffix,
20                                            const std::string &units)
21 {
22     RegisterMetric(metric_suffix, units, false);
23 }
24 
RegisterImportantMetric(const std::string & metric_suffix,const std::string & units)25 void PerfResultReporter::RegisterImportantMetric(const std::string &metric_suffix,
26                                                  const std::string &units)
27 {
28     RegisterMetric(metric_suffix, units, true);
29 }
30 
AddResult(const std::string & metric_suffix,size_t value)31 void PerfResultReporter::AddResult(const std::string &metric_suffix, size_t value)
32 {
33     auto iter = metric_map_.find(metric_suffix);
34     CHECK(iter != metric_map_.end());
35 
36     PrintResult(metric_basename_, metric_suffix, story_name_, value, iter->second.units,
37                 iter->second.important);
38 }
39 
AddResult(const std::string & metric_suffix,double value)40 void PerfResultReporter::AddResult(const std::string &metric_suffix, double value)
41 {
42     auto iter = metric_map_.find(metric_suffix);
43     CHECK(iter != metric_map_.end());
44 
45     PrintResult(metric_basename_, metric_suffix, story_name_, value, iter->second.units,
46                 iter->second.important);
47 }
48 
AddResult(const std::string & metric_suffix,const std::string & value)49 void PerfResultReporter::AddResult(const std::string &metric_suffix, const std::string &value)
50 {
51     auto iter = metric_map_.find(metric_suffix);
52     CHECK(iter != metric_map_.end());
53 
54     PrintResult(metric_basename_, metric_suffix, story_name_, value, iter->second.units,
55                 iter->second.important);
56 }
57 
GetMetricInfo(const std::string & metric_suffix,MetricInfo * out)58 bool PerfResultReporter::GetMetricInfo(const std::string &metric_suffix, MetricInfo *out)
59 {
60     auto iter = metric_map_.find(metric_suffix);
61     if (iter == metric_map_.end())
62     {
63         return false;
64     }
65 
66     *out = iter->second;
67     return true;
68 }
69 
RegisterMetric(const std::string & metric_suffix,const std::string & units,bool important)70 void PerfResultReporter::RegisterMetric(const std::string &metric_suffix,
71                                         const std::string &units,
72                                         bool important)
73 {
74     CHECK(metric_map_.count(metric_suffix) == 0);
75     metric_map_.insert({metric_suffix, {units, important}});
76 }
77 
78 }  // namespace perf_test
79