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

Unified Diff: third_party/WebKit/Source/platform/HistogramTest.cpp

Issue 1852633002: Add UMA stats for time in paint+layout, compositing, paint invalidation and paint. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/HistogramTest.cpp
diff --git a/third_party/WebKit/Source/platform/HistogramTest.cpp b/third_party/WebKit/Source/platform/HistogramTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8b575b6c8ea741ea81b13d0dc28bd2bbdf2a218f
--- /dev/null
+++ b/third_party/WebKit/Source/platform/HistogramTest.cpp
@@ -0,0 +1,62 @@
+// 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 "platform/Histogram.h"
+
+#include "base/metrics/histogram_samples.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class ScopedUsHistogramTimerTest : public ::testing::Test {
+public:
+ static void advanceClock(double microseconds)
+ {
+ s_timeElapsed += microseconds;
+ }
+
+protected:
+ static double returnMockTime()
+ {
+ return s_timeElapsed;
+ }
+
+ virtual void SetUp()
+ {
+ s_timeElapsed = 0.0;
+ m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime);
+ }
+
+ virtual void TearDown()
+ {
+ setTimeFunctionsForTesting(m_originalTimeFunction);
+ }
+
+private:
+ static double s_timeElapsed;
+ TimeFunction m_originalTimeFunction;
+};
+
+double ScopedUsHistogramTimerTest::s_timeElapsed;
+
+class TestCustomCountHistogram : public CustomCountHistogram {
+public:
+ TestCustomCountHistogram(const char* name, base::HistogramBase::Sample min, base::HistogramBase::Sample max, int32_t bucketCount)
+ : CustomCountHistogram(name, min, max, bucketCount) {}
+
+ base::HistogramBase* histogram() { return m_histogram; }
+};
+
+TEST_F(ScopedUsHistogramTimerTest, Basic)
+{
+ TestCustomCountHistogram scopedUsCounter("test", 0, 10000000, 50);
+ {
+ ScopedUsHistogramTimer timer(scopedUsCounter);
+ advanceClock(0.5);
+ }
+ // 0.5s == 500000us
+ EXPECT_EQ(500000, scopedUsCounter.histogram()->SnapshotSamples()->sum());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/Histogram.h ('k') | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698