Skip to content

Commit 6fe8309

Browse files
wangxianzhuChromium LUCI CQ
authored andcommitted
Add UMA metrics Renderer4.MainThread(Gesture|Wheel)ScrollReason2
They deprecate Renderer4.MainThread(Gesture|Wheel)ScrollReason with which we were unable to calculate the percentage of scrolls without any main-thread reason or with a particular reason because each scroll can have multiple main-thread scrolling reasons. In the new metrics, we report "Scrolling on main (any reason)". With this and "Not scrolling on main (no reason)" we can know the total count of scrolls and calculate the percentage of non-main-thread scrolls and main-thread scrolls for a particular reason. Change-Id: Ide9bfd087b32231ad9e99413e5e14fe7ac1d72a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3583502 Reviewed-by: Robert Flack <flackr@chromium.org> Reviewed-by: Philip Rogers <pdr@chromium.org> Reviewed-by: Stephen Chenney <schenney@chromium.org> Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org> Cr-Commit-Position: refs/heads/main@{#1028419}
1 parent 06de955 commit 6fe8309

File tree

8 files changed

+223
-208
lines changed

8 files changed

+223
-208
lines changed

cc/input/main_thread_scrolling_reason.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,16 @@ void MainThreadScrollingReason::AddToTracedValue(
6060
traced_value.EndArray();
6161
}
6262

63+
int MainThreadScrollingReason::BucketIndexForTesting(uint32_t reason) {
64+
// These two values are already bucket indices.
65+
DCHECK_NE(reason, kNotScrollingOnMain);
66+
DCHECK_NE(reason, kScrollingOnMainForAnyReason);
67+
68+
int index = 0;
69+
while (reason >>= 1)
70+
++index;
71+
DCHECK_NE(index, 0);
72+
return index;
73+
}
74+
6375
} // namespace cc

cc/input/main_thread_scrolling_reason.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,47 @@ struct CC_EXPORT MainThreadScrollingReason {
2828
enum : uint32_t {
2929
kNotScrollingOnMain = 0,
3030

31+
// This is used only to report the histogram of main thread scrolling for
32+
// any reason below. It's a histogram bucket index instead of a bit.
33+
kScrollingOnMainForAnyReason = 1,
34+
3135
// This enum simultaneously defines actual bitmask values and indices into
32-
// the bitmask, but kNotScrollingMain is recorded in the histograms as
33-
// value 0, so the 0th bit should never be used.
36+
// the bitmask (which are the numbers after "1 << " below, used as the
37+
// histogram bucket indices), but value 0 and 1 are used as the histogram
38+
// bucket indices for kNotScrollingMain and kScrollingOnMainForAnyReason,
39+
// respectively, so the 0th bit and the 1st bit should never be used.
3440
// See also blink::RecordScrollReasonsMetric().
3541

3642
// Non-transient scrolling reasons. These are set on the ScrollNode.
37-
kHasBackgroundAttachmentFixedObjects = 1 << 1,
43+
kHasBackgroundAttachmentFixedObjects = 1 << 2,
3844
kThreadedScrollingDisabled = 1 << 3,
39-
kPopupNoThreadedInput = 1 << 26,
45+
kPopupNoThreadedInput = 1 << 4,
4046

4147
// Style-related scrolling on main reasons. Subpixel (LCD) text rendering
4248
// requires blending glyphs with the background at a specific screen
4349
// position; transparency and transforms break this.
4450
// These are only reported by the main-thread scroll gesture event codepath.
4551
// After scroll unification, we report kNoScrollingLayer instead.
46-
kNonCompositedReasonsFirst = 18,
47-
kNotOpaqueForTextAndLCDText = 1 << 19,
48-
kCantPaintScrollingBackgroundAndLCDText = 1 << 20,
49-
kNonCompositedReasonsLast = 23,
52+
kNotOpaqueForTextAndLCDText = 1 << 5,
53+
kCantPaintScrollingBackgroundAndLCDText = 1 << 6,
5054

5155
// Transient scrolling reasons. These are computed for each scroll gesture.
5256
// When computed inside ScrollBegin, these prevent the InputHandler from
5357
// reporting a status with SCROLL_ON_IMPL_THREAD. In other cases, the
5458
// InputHandler is scrolling "on impl", but we report a transient main
5559
// thread scrolling reason to UMA when we determine that some other aspect
5660
// of handling the scroll has been (or will be) blocked on the main thread.
57-
kScrollbarScrolling = 1 << 4,
58-
kNonFastScrollableRegion = 1 << 6,
59-
kFailedHitTest = 1 << 8,
60-
kNoScrollingLayer = 1 << 9,
61-
kNotScrollable = 1 << 10,
61+
kScrollbarScrolling = 1 << 7,
62+
kNonFastScrollableRegion = 1 << 8,
63+
kFailedHitTest = 1 << 9,
64+
kNoScrollingLayer = 1 << 10,
65+
kNotScrollable = 1 << 11,
6266
kNonInvertibleTransform = 1 << 12,
63-
kWheelEventHandlerRegion = 1 << 24,
64-
kTouchEventHandlerRegion = 1 << 25,
67+
kWheelEventHandlerRegion = 1 << 13,
68+
kTouchEventHandlerRegion = 1 << 14,
6569

66-
kMainThreadScrollingReasonLast = 26,
70+
// For blink::RecordScrollReasonsMetric() to know the number of used bits.
71+
kMainThreadScrollingReasonLast = 14,
6772
};
6873

6974
static const uint32_t kNonCompositedReasons =
@@ -94,6 +99,8 @@ struct CC_EXPORT MainThreadScrollingReason {
9499
return (reasons & kNonCompositedReasons) != 0;
95100
}
96101

102+
static int BucketIndexForTesting(uint32_t reason);
103+
97104
static std::string AsText(uint32_t reasons);
98105
static void AddToTracedValue(uint32_t reasons,
99106
base::trace_event::TracedValue&);

third_party/blink/renderer/core/page/scrolling/main_thread_scrolling_reasons_test.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ class MainThreadScrollingReasonsTest : public PaintTestConfigurations,
103103
->GetScrollableArea();
104104
}
105105

106-
base::Bucket BucketForReason(uint32_t reason) {
107-
uint32_t bucket = 0;
108-
while (reason >>= 1)
109-
bucket++;
110-
return base::Bucket(base::HistogramBase::Sample(bucket), 1);
111-
}
112-
113106
protected:
114107
String base_url_;
115108
frame_test_helpers::WebViewHelper helper_;
@@ -286,8 +279,17 @@ TEST_P(MainThreadScrollingReasonsTest, ReportBackgroundAttachmentFixed) {
286279
uint32_t expected_reason =
287280
cc::MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects;
288281
EXPECT_THAT(
289-
histogram_tester.GetAllSamples("Renderer4.MainThreadGestureScrollReason"),
290-
testing::ElementsAre(BucketForReason(expected_reason)));
282+
histogram_tester.GetAllSamples(
283+
"Renderer4.MainThreadGestureScrollReason2"),
284+
testing::ElementsAre(
285+
base::Bucket(
286+
base::HistogramBase::Sample(
287+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason),
288+
1),
289+
base::Bucket(base::HistogramBase::Sample(
290+
cc::MainThreadScrollingReason::BucketIndexForTesting(
291+
expected_reason)),
292+
1)));
291293
}
292294

293295
// Upon resizing the content size, the main thread scrolling reason

third_party/blink/renderer/core/page/scrolling/scroll_metrics_test.cc

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@
1515
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
1616
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
1717

18-
#define EXPECT_WHEEL_BUCKET(reason, count) \
19-
histogram_tester.ExpectBucketCount( \
20-
"Renderer4.MainThreadWheelScrollReason", \
21-
GetBucketIndex(cc::MainThreadScrollingReason::reason), count);
22-
23-
#define EXPECT_TOUCH_BUCKET(reason, count) \
24-
histogram_tester.ExpectBucketCount( \
25-
"Renderer4.MainThreadGestureScrollReason", \
26-
GetBucketIndex(cc::MainThreadScrollingReason::reason), count);
27-
28-
#define EXPECT_WHEEL_TOTAL(count) \
29-
histogram_tester.ExpectTotalCount("Renderer4.MainThreadWheelScrollReason", \
30-
count);
18+
#define EXPECT_WHEEL_BUCKET(index, count) \
19+
histogram_tester.ExpectBucketCount("Renderer4.MainThreadWheelScrollReason2", \
20+
index, count);
21+
22+
#define EXPECT_TOUCH_BUCKET(index, count) \
23+
histogram_tester.ExpectBucketCount( \
24+
"Renderer4.MainThreadGestureScrollReason2", index, count);
3125

32-
#define EXPECT_TOUCH_TOTAL(count) \
33-
histogram_tester.ExpectTotalCount("Renderer4.MainThreadGestureScrollReason", \
26+
#define EXPECT_WHEEL_TOTAL(count) \
27+
histogram_tester.ExpectTotalCount("Renderer4.MainThreadWheelScrollReason2", \
3428
count);
3529

30+
#define EXPECT_TOUCH_TOTAL(count) \
31+
histogram_tester.ExpectTotalCount( \
32+
"Renderer4.MainThreadGestureScrollReason2", count);
33+
3634
namespace blink {
3735

3836
namespace {
@@ -46,12 +44,6 @@ class ScrollMetricsTest : public SimTest {
4644
}
4745
};
4846

49-
class NonCompositedMainThreadScrollingReasonRecordTest
50-
: public ScrollMetricsTest {
51-
protected:
52-
int GetBucketIndex(uint32_t reason);
53-
};
54-
5547
class ScrollBeginEventBuilder : public WebGestureEvent {
5648
public:
5749
ScrollBeginEventBuilder(gfx::PointF position,
@@ -88,13 +80,8 @@ class ScrollEndEventBuilder : public WebGestureEvent {
8880
}
8981
};
9082

91-
int NonCompositedMainThreadScrollingReasonRecordTest::GetBucketIndex(
92-
uint32_t reason) {
93-
int index = 0;
94-
while (reason >>= 1)
95-
++index;
96-
DCHECK_NE(index, 0);
97-
return index;
83+
int BucketIndex(uint32_t reason) {
84+
return cc::MainThreadScrollingReason::BucketIndexForTesting(reason);
9885
}
9986

10087
void ScrollMetricsTest::Scroll(Element* element,
@@ -120,10 +107,13 @@ void ScrollMetricsTest::SetUpHtml(const char* html_content) {
120107
LoadURL("https://example.com/test.html");
121108
request.Complete(html_content);
122109
Compositor().BeginFrame();
110+
111+
GetDocument().View()->SetParentVisible(true);
112+
GetDocument().View()->SetSelfVisible(true);
113+
UpdateAllLifecyclePhases();
123114
}
124115

125-
TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
126-
TouchAndWheelGeneralTest) {
116+
TEST_F(ScrollMetricsTest, TouchAndWheelGeneralTest) {
127117
SetUpHtml(R"HTML(
128118
<style>
129119
.box { overflow:scroll; width: 100px; height: 100px; }
@@ -134,27 +124,37 @@ TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
134124
</div>
135125
)HTML");
136126

137-
UpdateAllLifecyclePhases();
138-
139127
Element* box = GetDocument().getElementById("box");
140128
HistogramTester histogram_tester;
141129

142130
// Test touch scroll.
143131
Scroll(box, WebGestureDevice::kTouchscreen);
144-
EXPECT_TOUCH_BUCKET(kNotOpaqueForTextAndLCDText, 1);
132+
EXPECT_TOUCH_BUCKET(
133+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
134+
1);
135+
EXPECT_TOUCH_BUCKET(
136+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
137+
EXPECT_TOUCH_TOTAL(2);
145138

146139
Scroll(box, WebGestureDevice::kTouchscreen);
147-
EXPECT_TOUCH_BUCKET(kNotOpaqueForTextAndLCDText, 2);
148-
EXPECT_TOUCH_TOTAL(2);
140+
EXPECT_TOUCH_BUCKET(
141+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
142+
2);
143+
EXPECT_TOUCH_BUCKET(
144+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 2);
145+
EXPECT_TOUCH_TOTAL(4);
149146

150147
// Test wheel scroll.
151148
Scroll(box, WebGestureDevice::kTouchpad);
152-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
153-
EXPECT_WHEEL_TOTAL(1);
149+
EXPECT_WHEEL_BUCKET(
150+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
151+
1);
152+
EXPECT_WHEEL_BUCKET(
153+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
154+
EXPECT_WHEEL_TOTAL(2);
154155
}
155156

156-
TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
157-
CompositedScrollableAreaTest) {
157+
TEST_F(ScrollMetricsTest, CompositedScrollableAreaTest) {
158158
SetUpHtml(R"HTML(
159159
<style>
160160
.box { overflow:scroll; width: 100px; height: 100px; }
@@ -166,29 +166,31 @@ TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
166166
</div>
167167
)HTML");
168168

169-
GetDocument().View()->SetParentVisible(true);
170-
GetDocument().View()->SetSelfVisible(true);
171-
UpdateAllLifecyclePhases();
172-
173169
Element* box = GetDocument().getElementById("box");
174170
HistogramTester histogram_tester;
175171

176172
Scroll(box, WebGestureDevice::kTouchpad);
177-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
178-
EXPECT_WHEEL_TOTAL(1);
173+
EXPECT_WHEEL_BUCKET(
174+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
175+
1);
176+
EXPECT_WHEEL_BUCKET(
177+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
178+
EXPECT_WHEEL_TOTAL(2);
179179

180180
box->setAttribute("class", "composited transform box");
181181
UpdateAllLifecyclePhases();
182182
Scroll(box, WebGestureDevice::kTouchpad);
183183
EXPECT_FALSE(To<LayoutBox>(box->GetLayoutObject())
184184
->GetScrollableArea()
185185
->GetNonCompositedMainThreadScrollingReasons());
186-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
187-
EXPECT_WHEEL_TOTAL(1);
186+
EXPECT_WHEEL_BUCKET(
187+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
188+
1);
189+
// EXPECT_WHEEL_BUCKET(cc::MainThreadScrollingReason::kNotScrollingOnMain, 1);
190+
EXPECT_WHEEL_TOTAL(2);
188191
}
189192

190-
TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
191-
NotScrollableAreaTest) {
193+
TEST_F(ScrollMetricsTest, NotScrollableAreaTest) {
192194
SetUpHtml(R"HTML(
193195
<style>.box { overflow:scroll; width: 100px; height: 100px; }
194196
.hidden { overflow: hidden; }
@@ -199,23 +201,29 @@ TEST_F(NonCompositedMainThreadScrollingReasonRecordTest,
199201
</div>
200202
)HTML");
201203

202-
UpdateAllLifecyclePhases();
203-
204204
Element* box = GetDocument().getElementById("box");
205205
HistogramTester histogram_tester;
206206

207207
Scroll(box, WebGestureDevice::kTouchpad);
208-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
209-
EXPECT_WHEEL_TOTAL(1);
208+
EXPECT_WHEEL_BUCKET(
209+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
210+
1);
211+
EXPECT_WHEEL_BUCKET(
212+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
213+
EXPECT_WHEEL_TOTAL(2);
210214

211215
box->setAttribute("class", "hidden transform box");
212216
UpdateAllLifecyclePhases();
213217
Scroll(box, WebGestureDevice::kTouchpad);
214-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
215-
EXPECT_WHEEL_TOTAL(1);
218+
EXPECT_WHEEL_BUCKET(
219+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
220+
1);
221+
EXPECT_WHEEL_BUCKET(
222+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
223+
EXPECT_WHEEL_TOTAL(2);
216224
}
217225

218-
TEST_F(NonCompositedMainThreadScrollingReasonRecordTest, NestedScrollersTest) {
226+
TEST_F(ScrollMetricsTest, NestedScrollersTest) {
219227
SetUpHtml(R"HTML(
220228
<style>
221229
.container { overflow:scroll; width: 200px; height: 200px; }
@@ -236,19 +244,19 @@ TEST_F(NonCompositedMainThreadScrollingReasonRecordTest, NestedScrollersTest) {
236244
</div>
237245
)HTML");
238246

239-
GetDocument().View()->SetParentVisible(true);
240-
GetDocument().View()->SetSelfVisible(true);
241-
UpdateAllLifecyclePhases();
242-
243247
Element* box = GetDocument().getElementById("inner");
244248
HistogramTester histogram_tester;
245249

246250
Scroll(box, WebGestureDevice::kTouchpad);
247251
// Scrolling the inner box will gather reasons from the scrolling chain. The
248252
// inner box itself has no reason because it's composited. Other scrollable
249253
// areas from the chain have corresponding reasons.
250-
EXPECT_WHEEL_BUCKET(kNotOpaqueForTextAndLCDText, 1);
251-
EXPECT_WHEEL_TOTAL(1);
254+
EXPECT_WHEEL_BUCKET(
255+
BucketIndex(cc::MainThreadScrollingReason::kNotOpaqueForTextAndLCDText),
256+
1);
257+
EXPECT_WHEEL_BUCKET(
258+
cc::MainThreadScrollingReason::kScrollingOnMainForAnyReason, 1);
259+
EXPECT_WHEEL_TOTAL(2);
252260
}
253261

254262
} // namespace

0 commit comments

Comments
 (0)