Commit caeb5eda authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Add UMA metric for style invalidation.

We introduce a ScopedHighResUsHistogramTimer which only records samples
if we have a high resolution timer. This is done to avoid a bunch of
samples falling into the 0us bucket when we don't have a high
resolution timer.

Change-Id: Ic57cd34bcd5ceada96fe8f69f9267ce21aef07a7
Reviewed-on: https://chromium-review.googlesource.com/1150020Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarAnders Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578459}
parent 93c5e1d5
...@@ -1923,6 +1923,7 @@ void Document::UpdateStyleInvalidationIfNeeded() { ...@@ -1923,6 +1923,7 @@ void Document::UpdateStyleInvalidationIfNeeded() {
if (!ChildNeedsStyleInvalidation() && !NeedsStyleInvalidation()) if (!ChildNeedsStyleInvalidation() && !NeedsStyleInvalidation())
return; return;
TRACE_EVENT0("blink", "Document::updateStyleInvalidationIfNeeded"); TRACE_EVENT0("blink", "Document::updateStyleInvalidationIfNeeded");
SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES("Style.InvalidationTime");
GetStyleEngine().InvalidateStyle(); GetStyleEngine().InvalidateStyle();
} }
......
...@@ -78,11 +78,32 @@ class PLATFORM_EXPORT ScopedUsHistogramTimer { ...@@ -78,11 +78,32 @@ class PLATFORM_EXPORT ScopedUsHistogramTimer {
CustomCountHistogram& counter_; CustomCountHistogram& counter_;
}; };
class PLATFORM_EXPORT ScopedHighResUsHistogramTimer {
public:
explicit ScopedHighResUsHistogramTimer(CustomCountHistogram& counter)
: start_time_(CurrentTimeTicks()), counter_(counter) {}
~ScopedHighResUsHistogramTimer() {
if (TimeTicks::IsHighResolution())
counter_.CountMicroseconds(CurrentTimeTicks() - start_time_);
}
private:
TimeTicks start_time_;
CustomCountHistogram& counter_;
};
#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_IMPL(name, allow_cross_thread) \ #define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_IMPL(name, allow_cross_thread) \
DEFINE_STATIC_LOCAL_IMPL(CustomCountHistogram, scoped_us_counter, \ DEFINE_STATIC_LOCAL_IMPL(CustomCountHistogram, scoped_us_counter, \
(name, 0, 10000000, 50), allow_cross_thread); \ (name, 0, 10000000, 50), allow_cross_thread); \
ScopedUsHistogramTimer timer(scoped_us_counter); ScopedUsHistogramTimer timer(scoped_us_counter);
#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES_IMPL(name, \
allow_cross_thread) \
DEFINE_STATIC_LOCAL_IMPL(CustomCountHistogram, scoped_us_counter, \
(name, 0, 10000000, 50), allow_cross_thread); \
ScopedHighResUsHistogramTimer timer(scoped_us_counter);
// Use code like this to record time, in microseconds, to execute a block of // Use code like this to record time, in microseconds, to execute a block of
// code: // code:
// //
...@@ -95,6 +116,10 @@ class PLATFORM_EXPORT ScopedUsHistogramTimer { ...@@ -95,6 +116,10 @@ class PLATFORM_EXPORT ScopedUsHistogramTimer {
#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER(name) \ #define SCOPED_BLINK_UMA_HISTOGRAM_TIMER(name) \
SCOPED_BLINK_UMA_HISTOGRAM_TIMER_IMPL(name, false) SCOPED_BLINK_UMA_HISTOGRAM_TIMER_IMPL(name, false)
// Only record samples when we have a high resolution timer
#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES(name) \
SCOPED_BLINK_UMA_HISTOGRAM_TIMER_HIGHRES_IMPL(name, false)
// Thread-safe variant of SCOPED_BLINK_UMA_HISTOGRAM_TIMER. // Thread-safe variant of SCOPED_BLINK_UMA_HISTOGRAM_TIMER.
// Use if the histogram can be accessed by multiple threads. // Use if the histogram can be accessed by multiple threads.
#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_THREAD_SAFE(name) \ #define SCOPED_BLINK_UMA_HISTOGRAM_TIMER_THREAD_SAFE(name) \
......
...@@ -23,7 +23,8 @@ class TestCustomCountHistogram : public CustomCountHistogram { ...@@ -23,7 +23,8 @@ class TestCustomCountHistogram : public CustomCountHistogram {
}; };
TEST(ScopedUsHistogramTimerTest, Basic) { TEST(ScopedUsHistogramTimerTest, Basic) {
TestCustomCountHistogram scoped_us_counter("test", 0, 10000000, 50); TestCustomCountHistogram scoped_us_counter("ScopedUsHistogramTimerTest.Basic",
0, 10000000, 50);
{ {
WTF::ScopedMockClock clock; WTF::ScopedMockClock clock;
ScopedUsHistogramTimer timer(scoped_us_counter); ScopedUsHistogramTimer timer(scoped_us_counter);
...@@ -33,4 +34,16 @@ TEST(ScopedUsHistogramTimerTest, Basic) { ...@@ -33,4 +34,16 @@ TEST(ScopedUsHistogramTimerTest, Basic) {
EXPECT_EQ(500000, scoped_us_counter.Histogram()->SnapshotSamples()->sum()); EXPECT_EQ(500000, scoped_us_counter.Histogram()->SnapshotSamples()->sum());
} }
TEST(ScopedHighResUsHistogramTimerTest, Basic) {
TestCustomCountHistogram scoped_us_counter(
"ScopedHighResUsHistogramTimerTest.Basic", 0, 10000000, 50);
{
WTF::ScopedMockClock clock;
ScopedHighResUsHistogramTimer timer(scoped_us_counter);
clock.Advance(TimeDelta::FromMilliseconds(500));
}
int64_t expected = TimeTicks::IsHighResolution() ? 500000 : 0;
EXPECT_EQ(expected, scoped_us_counter.Histogram()->SnapshotSamples()->sum());
}
} // namespace blink } // namespace blink
...@@ -98288,6 +98288,14 @@ uploading your change for review. ...@@ -98288,6 +98288,14 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Style.InvalidationTime" units="microseconds">
<owner>futhark@chromium.org</owner>
<summary>
Microseconds spent in StyleEngine::InvalidateStyle. Only samples from high
resolution timers are recorded.
</summary>
</histogram>
<histogram name="Style.LazyUsage.Percent" enum="LazyCSSParseUsage"> <histogram name="Style.LazyUsage.Percent" enum="LazyCSSParseUsage">
<obsolete> <obsolete>
Deprecated 07/2018, no longer used. Deprecated 07/2018, no longer used.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment