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

Unified Diff: components/subresource_filter/core/common/scoped_timers_unittest.cc

Issue 2503283003: Add high-precision timing histograms. (Closed)
Patch Set: Use product name instead of project name. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/core/common/scoped_timers_unittest.cc
diff --git a/components/subresource_filter/core/common/scoped_timers_unittest.cc b/components/subresource_filter/core/common/scoped_timers_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3dd0912b6f3ff60a4cad749075f495bb37a7b09
--- /dev/null
+++ b/components/subresource_filter/core/common/scoped_timers_unittest.cc
@@ -0,0 +1,109 @@
+// Copyright 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.
+
+#include "components/subresource_filter/core/common/scoped_timers.h"
+
+#include "base/test/histogram_tester.h"
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class ExportFunctorForTests {
+ public:
+ int number_of_calls() const { return number_of_calls_; }
+ void operator()(base::TimeDelta) { ++number_of_calls_; }
+
+ private:
+ int number_of_calls_ = 0;
+};
+
+} // namespace
+
+namespace subresource_filter {
+
+TEST(ScopedTimersTest, ScopedTimerCallsFunctor) {
+ ExportFunctorForTests export_functor;
+ {
+ SCOPED_TIMER(std::ref(export_functor));
+ EXPECT_EQ(0, export_functor.number_of_calls());
+ }
+ EXPECT_EQ(1, export_functor.number_of_calls());
+}
+
+TEST(ScopedTimersTest, ScopedThreadTimerCallsFunctor) {
+ ExportFunctorForTests export_functor;
+ {
+ SCOPED_THREAD_TIMER(std::ref(export_functor));
+ EXPECT_EQ(0, export_functor.number_of_calls());
+ }
+ EXPECT_EQ(1, export_functor.number_of_calls());
+}
+
+TEST(ScopedTimersTest, ScopedTimersCopyFunctor) {
+ ExportFunctorForTests export_functor;
+ {
+ SCOPED_TIMER(export_functor);
+ SCOPED_THREAD_TIMER(export_functor);
+ EXPECT_EQ(0, export_functor.number_of_calls());
+ }
+ EXPECT_EQ(0, export_functor.number_of_calls());
+}
+
+TEST(ScopedTimersTest, ScopedThreadTimerCallsStoredLambdaFunctor) {
+ bool export_is_called = false;
+ auto export_functor = [&export_is_called](base::TimeDelta) {
+ export_is_called = true;
+ };
+
+ {
+ SCOPED_THREAD_TIMER(export_functor);
+ EXPECT_FALSE(export_is_called);
+ }
+ EXPECT_TRUE(export_is_called);
+}
+
+TEST(ScopedTimersTest, ScopedTimerCallsStoredLambdaFunctor) {
+ bool export_is_called = false;
+ auto export_functor = [&export_is_called](base::TimeDelta) {
+ export_is_called = true;
+ };
+
+ {
+ SCOPED_TIMER(export_functor);
+ EXPECT_FALSE(export_is_called);
+ }
+ EXPECT_TRUE(export_is_called);
+}
+
+TEST(ScopedTimersTest, ScopedUmaHistogramMacros) {
+ base::HistogramTester tester;
+ {
+ SCOPED_UMA_HISTOGRAM_THREAD_TIMER("ScopedTimers.ThreadTimer");
+ SCOPED_UMA_HISTOGRAM_MICRO_THREAD_TIMER("ScopedTimers.MicroThreadTimer");
+ SCOPED_UMA_HISTOGRAM_MICRO_TIMER("ScopedTimers.MicroTimer");
pkalinnikov 2016/11/28 13:58:36 Should I do something to suppress the following wa
+
+ tester.ExpectTotalCount("ScopedTimers.ThreadTimer", 0);
+ tester.ExpectTotalCount("ScopedTimers.MicroThreadTimer", 0);
+ tester.ExpectTotalCount("ScopedTimers.MicroTimer", 0);
+ }
+
+ tester.ExpectTotalCount("ScopedTimers.ThreadTimer", 1);
+ tester.ExpectTotalCount("ScopedTimers.MicroThreadTimer", 1);
+ tester.ExpectTotalCount("ScopedTimers.MicroTimer", 1);
+}
+
+TEST(ScopedTimersTest, UmaHistogramMicroTimesFromExportFunctor) {
+ base::HistogramTester tester;
+ auto export_functor = [](base::TimeDelta delta) {
+ UMA_HISTOGRAM_MICRO_TIMES("ScopedTimers.MicroTimes", delta);
+ };
+ {
+ SCOPED_TIMER(export_functor);
+ tester.ExpectTotalCount("ScopedTimers.MicroTimes", 0);
+ }
+ tester.ExpectTotalCount("ScopedTimers.MicroTimes", 1);
+}
+
+} // namespace subresource_filter

Powered by Google App Engine
This is Rietveld 408576698