Index: testing/perf/scoped_histogram_result_printer.h |
diff --git a/testing/perf/scoped_histogram_result_printer.h b/testing/perf/scoped_histogram_result_printer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2318702f3f1654bebf242139ed8b762dd2235617 |
--- /dev/null |
+++ b/testing/perf/scoped_histogram_result_printer.h |
@@ -0,0 +1,85 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_ |
+#define TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/bind.h" |
+#include "base/macros.h" |
+ |
+namespace testing { |
+class UnitTest; |
+} // namespace testing |
+ |
+namespace base { |
+class HistogramSamples; |
+} // namespace base |
+ |
+namespace perf_test { |
+ |
+// This header contains helpers to create binary perf tests based on histograms. |
+// |
+// Example: |
+// |
+// IN_PROC_BROWSER_TEST_F(ObjectWeTest, ActionWeTake) { |
+// perf_test::ScopedHistogramResultPrinter scoped_printer( |
+// perf_test::TestBasedPerfTestPrinter(::testing::UnitTest::GetInstance(), |
+// "units")); |
+// scoped_printer.AddHistogramStrict("ThisHistogramWillDefinitelyBeHere", |
+// "it_measures_THIS"); |
+// scoped_printer.AddHistogramNice("ThisHistogramMightNotHaveResults", |
+// "it_measures_this"); |
+// ... do ActionWeTake |
+// } |
+// |
+// On a dashboard this will be: ObjectWeTestActionWeTake perf test with |
+// measurements it_measures_THIS and it_measures_this. |
+// |
+// For more examples see omnibox_performance_browsertest.cc |
+ |
+// Callback to tranform collected results to the desired format. |
+using HistogramPrinter = |
+ base::Callback<void(const base::HistogramSamples&, const std::string&)>; |
+ |
+// Creates HistogramPrinter, base on your test. Use this by default. |
+HistogramPrinter TestBasedPerfTestPrinter(const ::testing::UnitTest* test, |
+ std::string units); |
+ |
+// This is a helper class for binary performance tests based on histograms. |
+class ScopedHistogramResultPrinter { |
+ public: |
+ explicit ScopedHistogramResultPrinter(HistogramPrinter printer); |
+ |
+ // Adding histograms: |
+ // |name| - histogram name (example: "Omnibox.CharTypedToSuggestLatency"). |
+ // |measurement| - parametr passed to HistogramPrinter. In TestBased |
+ // this would be a string, that is displayed on a dashboard. |
+ // (example: "CharTypedToSuggestLatency"). |
+ |
+ // Use this method for adding histograms, which can not be absent at runtime |
+ void AddHistogramStrict(std::string name, std::string measurement); |
+ |
+ // Use this method for adding histograms, which can be absent at runtime |
+ void AddHistogramNice(std::string name, std::string measurement); |
+ |
+ ~ScopedHistogramResultPrinter(); |
+ |
+ private: |
+ class HistogramInfo; |
+ |
+ void AddHistogram(std::string name, |
+ std::string measurement, |
+ const bool is_nice); |
+ HistogramPrinter printer_; |
+ std::vector<HistogramInfo> histograms_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ScopedHistogramResultPrinter); |
+}; |
+ |
+} // namespace perf_test |
+ |
+#endif // TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_ |