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.
5
#ifndef TESTING_PERF_PERF_RESULT_REPORTER_H_
6
#define TESTING_PERF_PERF_RESULT_REPORTER_H_
9
#include <unordered_map>
20
// A helper class for using the perf test printing functions safely, as
21
// otherwise it's easy to accidentally mix up arguments to produce usable but
22
// malformed perf data. See https://crbug.com/923564.
25
// auto reporter = PerfResultReporter("TextRendering", "100_chars");
26
// reporter.RegisterImportantMetric(".wall_time", "ms");
27
// reporter.RegisterImportantMetric(".cpu_time", "ms");
29
// reporter.AddResult(".wall_time", GetWallTime());
30
// reporter.AddResult(".cpu_time", GetCpuTime());
32
// This would end up reporting "TextRendering.wall_time" and
33
// "TextRendering.cpu_time" metrics on the dashboard, made up of results from
34
// a single "100_chars" story. If an additional story run is added, e.g.
35
// "200_chars", then the metrics will be averaged over both runs with the
36
// ability to drill down into results for specific stories.
37
class PerfResultReporter
40
PerfResultReporter(const std::string &metric_basename, const std::string &story_name);
41
~PerfResultReporter();
43
void RegisterFyiMetric(const std::string &metric_suffix, const std::string &units);
44
void RegisterImportantMetric(const std::string &metric_suffix, const std::string &units);
45
void AddResult(const std::string &metric_suffix, size_t value);
46
void AddResult(const std::string &metric_suffix, double value);
47
void AddResult(const std::string &metric_suffix, const std::string &value);
49
// Returns true and fills the pointer if the metric is registered, otherwise
51
bool GetMetricInfo(const std::string &metric_suffix, MetricInfo *out);
54
void RegisterMetric(const std::string &metric_suffix, const std::string &units, bool important);
56
std::string metric_basename_;
57
std::string story_name_;
58
std::unordered_map<std::string, MetricInfo> metric_map_;
61
} // namespace perf_test
63
#endif // TESTING_PERF_PERF_RESULT_REPORTER_H_