Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: testing/perf/scoped_histogram_result_printer.h

Issue 2300323003: Adding performance tests for HQP that represent importance of optimising HistoryItemsForTerms method (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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 #ifndef TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_
6 #define TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/macros.h"
13
14 namespace testing {
15 class UnitTest;
16 } // namespace testing
17
18 namespace base {
19 class HistogramSamples;
20 } // namespace base
21
22 namespace perf_test {
23
24 // This header contains helpers to create binary perf tests based on histograms.
25 //
26 // Example:
27 //
28 // IN_PROC_BROWSER_TEST_F(ObjectWeTest, ActionWeTake) {
29 // perf_test::ScopedHistogramResultPrinter scoped_printer(
30 // perf_test::TestBasedPerfTestPrinter(::testing::UnitTest::GetInstance(),
31 // "units"));
32 // scoped_printer.AddHistogramStrict("ThisHistogramWillDefinitelyBeHere",
33 // "it_measures_THIS");
34 // scoped_printer.AddHistogramNice("ThisHistogramMightNotHaveResults",
35 // "it_measures_this");
36 // ... do ActionWeTake
37 // }
38 //
39 // On a dashboard this will be: ObjectWeTestActionWeTake perf test with
40 // measurements it_measures_THIS and it_measures_this.
41 //
42 // For more examples see omnibox_performance_browsertest.cc
43
44 // Callback to tranform collected results to the desired format.
45 using HistogramPrinter =
46 base::Callback<void(const base::HistogramSamples&, const std::string&)>;
47
48 // Creates HistogramPrinter, base on your test. Use this by default.
49 HistogramPrinter TestBasedPerfTestPrinter(const ::testing::UnitTest* test,
50 std::string units);
51
52 // This is a helper class for binary performance tests based on histograms.
53 class ScopedHistogramResultPrinter {
54 public:
55 explicit ScopedHistogramResultPrinter(HistogramPrinter printer);
56
57 // Adding histograms:
58 // |name| - histogram name (example: "Omnibox.CharTypedToSuggestLatency").
59 // |measurement| - parametr passed to HistogramPrinter. In TestBased
60 // this would be a string, that is displayed on a dashboard.
61 // (example: "CharTypedToSuggestLatency").
62
63 // Use this method for adding histograms, which can not be absent at runtime
64 void AddHistogramStrict(std::string name, std::string measurement);
65
66 // Use this method for adding histograms, which can be absent at runtime
67 void AddHistogramNice(std::string name, std::string measurement);
68
69 ~ScopedHistogramResultPrinter();
70
71 private:
72 class HistogramInfo;
73
74 void AddHistogram(std::string name,
75 std::string measurement,
76 const bool is_nice);
77 HistogramPrinter printer_;
78 std::vector<HistogramInfo> histograms_;
79
80 DISALLOW_COPY_AND_ASSIGN(ScopedHistogramResultPrinter);
81 };
82
83 } // namespace perf_test
84
85 #endif // TESTING_PERF_SCOPED_HISTOGRAM_RESULT_PRINTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698