Skip to content

Commit e42845f

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Show throttling and device emulation in trace history dropdown
Also removes the duration and time. https://i.imgur.com/k0otYyv.png Bug: 311438203 Change-Id: I813eddb7e3e77d1e3c387ad8201ffa42d3dd4ca8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6035852 Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Connor Clark <[email protected]> Auto-Submit: Connor Clark <[email protected]>
1 parent 71c991a commit e42845f

File tree

13 files changed

+194
-92
lines changed

13 files changed

+194
-92
lines changed

front_end/models/trace/extras/Metadata.test.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,30 @@ describeWithEnvironment('Trace Metadata', () => {
1313
sinon.stub(cpuThrottlingManager, 'getHardwareConcurrency').returns(Promise.resolve(1));
1414
sinon.stub(cpuThrottlingManager, 'cpuThrottlingRate').returns(2);
1515
const networkManager = SDK.NetworkManager.MultitargetNetworkManager.instance({forceNew: true});
16+
sinon.stub(networkManager, 'isThrottling').returns(true);
1617
sinon.stub(networkManager, 'networkConditions').returns({
1718
title: 'Slow 3G',
1819
download: 1,
19-
upload: 1,
20-
latency: 1,
20+
upload: 2,
21+
latency: 3,
2122
});
2223
const metadata = await Trace.Extras.Metadata.forNewRecording(/* isCpuProfile= */ false);
2324
assert.deepEqual(metadata, {
2425
source: 'DevTools',
2526
startTime: undefined,
2627
cpuThrottling: 2,
2728
networkThrottling: 'Slow 3G',
29+
networkThrottlingConditions: {
30+
download: 1,
31+
latency: 3,
32+
upload: 2,
33+
packetLoss: undefined,
34+
packetQueueLength: undefined,
35+
packetReordering: undefined,
36+
targetLatency: undefined,
37+
},
2838
dataOrigin: Trace.Types.File.DataOrigin.TRACE_EVENTS,
39+
emulatedDeviceTitle: undefined,
2940
hardwareConcurrency: 1,
3041
});
3142
});
@@ -36,6 +47,7 @@ describeWithEnvironment('Trace Metadata', () => {
3647
sinon.stub(cpuThrottlingManager, 'getHardwareConcurrency').returns(Promise.resolve(1));
3748
sinon.stub(cpuThrottlingManager, 'cpuThrottlingRate').returns(2);
3849
const networkManager = SDK.NetworkManager.MultitargetNetworkManager.instance({forceNew: true});
50+
sinon.stub(networkManager, 'isThrottling').returns(true);
3951
sinon.stub(networkManager, 'networkConditions').returns({
4052
title: () => 'Slow 3G',
4153
download: 1,
@@ -48,6 +60,16 @@ describeWithEnvironment('Trace Metadata', () => {
4860
startTime: undefined,
4961
cpuThrottling: 2,
5062
networkThrottling: 'Slow 3G',
63+
networkThrottlingConditions: {
64+
download: 1,
65+
latency: 1,
66+
upload: 1,
67+
packetLoss: undefined,
68+
packetQueueLength: undefined,
69+
packetReordering: undefined,
70+
targetLatency: undefined,
71+
},
72+
emulatedDeviceTitle: undefined,
5173
dataOrigin: Trace.Types.File.DataOrigin.TRACE_EVENTS,
5274
hardwareConcurrency: 1,
5375
});
@@ -59,6 +81,7 @@ describeWithEnvironment('Trace Metadata', () => {
5981
const getHardwareConcurrencyStub = sinon.stub(cpuThrottlingManager, 'getHardwareConcurrency');
6082
sinon.stub(cpuThrottlingManager, 'cpuThrottlingRate').returns(2);
6183
const networkManager = SDK.NetworkManager.MultitargetNetworkManager.instance({forceNew: true});
84+
sinon.stub(networkManager, 'isThrottling').returns(true);
6285
sinon.stub(networkManager, 'networkConditions').returns({
6386
title: () => 'Slow 3G',
6487
download: 1,
@@ -71,7 +94,17 @@ describeWithEnvironment('Trace Metadata', () => {
7194
startTime: undefined,
7295
cpuThrottling: 2,
7396
networkThrottling: 'Slow 3G',
97+
networkThrottlingConditions: {
98+
download: 1,
99+
latency: 1,
100+
upload: 1,
101+
packetLoss: undefined,
102+
packetQueueLength: undefined,
103+
packetReordering: undefined,
104+
targetLatency: undefined,
105+
},
74106
dataOrigin: Trace.Types.File.DataOrigin.TRACE_EVENTS,
107+
emulatedDeviceTitle: undefined,
75108
hardwareConcurrency: undefined,
76109
});
77110
assert.strictEqual(getHardwareConcurrencyStub.callCount, 0);

front_end/models/trace/extras/Metadata.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import * as SDK from '../../../core/sdk/sdk.js';
66
import * as Types from '../types/types.js';
77

8-
export async function forNewRecording(isCpuProfile: boolean, recordStartTime?: number): Promise<Types.File.MetaData> {
8+
export async function forNewRecording(
9+
isCpuProfile: boolean, recordStartTime?: number, emulatedDeviceTitle?: string): Promise<Types.File.MetaData> {
910
try {
1011
if (isCpuProfile) {
1112
// For CPU profile, only specify data origin
@@ -36,15 +37,33 @@ export async function forNewRecording(isCpuProfile: boolean, recordStartTime?: n
3637
const hardwareConcurrency =
3738
cpuThrottlingManager.hasPrimaryPageTargetSet() ? await getConcurrencyOrTimeout() : undefined;
3839
const cpuThrottling = SDK.CPUThrottlingManager.CPUThrottlingManager.instance().cpuThrottlingRate();
39-
const networkConditions = SDK.NetworkManager.MultitargetNetworkManager.instance().networkConditions();
40-
const networkTitle =
41-
typeof networkConditions.title === 'function' ? networkConditions.title() : networkConditions.title;
40+
const networkConditions = SDK.NetworkManager.MultitargetNetworkManager.instance().isThrottling() ?
41+
SDK.NetworkManager.MultitargetNetworkManager.instance().networkConditions() :
42+
undefined;
43+
44+
let networkThrottlingConditions;
45+
let networkTitle;
46+
if (networkConditions) {
47+
networkThrottlingConditions = {
48+
download: networkConditions.download,
49+
upload: networkConditions.upload,
50+
latency: networkConditions.latency,
51+
packetLoss: networkConditions.packetLoss,
52+
packetQueueLength: networkConditions.packetQueueLength,
53+
packetReordering: networkConditions.packetReordering,
54+
targetLatency: networkConditions.targetLatency,
55+
};
56+
networkTitle =
57+
typeof networkConditions.title === 'function' ? networkConditions.title() : networkConditions.title;
58+
}
4259

4360
return {
4461
source: 'DevTools',
4562
startTime: recordStartTime ? new Date(recordStartTime).toJSON() : undefined, // ISO-8601 timestamp
46-
cpuThrottling,
63+
emulatedDeviceTitle,
64+
cpuThrottling: cpuThrottling !== 1 ? cpuThrottling : undefined,
4765
networkThrottling: networkTitle,
66+
networkThrottlingConditions,
4867
hardwareConcurrency,
4968
dataOrigin: Types.File.DataOrigin.TRACE_EVENTS,
5069
};

front_end/models/trace/types/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ devtools_module("types") {
1616
"TraceEvents.ts",
1717
]
1818

19-
deps = [ "../../../generated" ]
19+
deps = [
20+
"../../../core/sdk:bundle",
21+
"../../../generated",
22+
]
2023
}
2124

2225
devtools_entrypoint("bundle") {

front_end/models/trace/types/File.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2023 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4+
5+
import type * as SDK from '../../../core/sdk/sdk.js';
46
import type * as Protocol from '../../../generated/protocol.js';
57

68
import type {TraceWindowMicroSeconds} from './Timing.js';
@@ -177,7 +179,12 @@ export interface Modifications {
177179
export interface MetaData {
178180
source?: 'DevTools';
179181
startTime?: string;
182+
emulatedDeviceTitle?: string;
183+
// Only set if network throttling is active.
180184
networkThrottling?: string;
185+
// Only set if network throttling is active.
186+
networkThrottlingConditions?: Omit<SDK.NetworkManager.Conditions, 'title'>;
187+
// Only set if CPU throttling is active.
181188
cpuThrottling?: number;
182189
hardwareConcurrency?: number;
183190
dataOrigin?: DataOrigin;

front_end/panels/timeline/TimelineHistoryManager.test.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ describeWithEnvironment('TimelineHistoryManager', function() {
2222
afterEach(() => {
2323
UI.ActionRegistry.ActionRegistry.reset();
2424
Root.Runtime.experiments.disableForTest(Root.Runtime.ExperimentName.TIMELINE_OBSERVATIONS);
25+
historyManager.cancelIfShowing();
2526
});
2627

2728
it('shows the dropdown including a landing page link if the observations experiment is enabled', async function() {
2829
Root.Runtime.experiments.enableForTest(Root.Runtime.ExperimentName.TIMELINE_OBSERVATIONS);
29-
const {parsedTrace} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
30+
const {parsedTrace, metadata} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
3031
historyManager.addRecording(
3132
{
3233
data: {
@@ -35,7 +36,7 @@ describeWithEnvironment('TimelineHistoryManager', function() {
3536
},
3637
filmStripForPreview: null,
3738
parsedTrace,
38-
startTime: null,
39+
metadata,
3940
},
4041
);
4142

@@ -48,7 +49,7 @@ describeWithEnvironment('TimelineHistoryManager', function() {
4849
const menuItemText = Array.from(dropdown.querySelectorAll<HTMLDivElement>('[role="menuitem"]'), elem => {
4950
return elem.innerText.replaceAll('\n', '');
5051
});
51-
assert.deepEqual(menuItemText, ['Live metrics', 'web.dev5.39 s']);
52+
assert.deepEqual(menuItemText, ['Live metrics', 'web.dev1× slowdown, No throttling']);
5253

5354
// Cancel the dropdown, which also resolves the show() promise, meaning we
5455
// don't leak it into other tests.
@@ -57,7 +58,7 @@ describeWithEnvironment('TimelineHistoryManager', function() {
5758
});
5859

5960
it('does not show if observations experiment is disabled + the user has not imported 2 traces', async function() {
60-
const {parsedTrace} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
61+
const {parsedTrace, metadata} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
6162
historyManager.addRecording(
6263
{
6364
data: {
@@ -66,7 +67,7 @@ describeWithEnvironment('TimelineHistoryManager', function() {
6667
},
6768
filmStripForPreview: null,
6869
parsedTrace,
69-
startTime: null,
70+
metadata,
7071
},
7172
);
7273

@@ -79,7 +80,8 @@ describeWithEnvironment('TimelineHistoryManager', function() {
7980
});
8081

8182
it('does not show the landing page link if the observations experiment is disabled', async function() {
82-
const {parsedTrace: parsedTrace1} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
83+
const {parsedTrace: parsedTrace1, metadata: metadata1} =
84+
await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
8385
historyManager.addRecording(
8486
{
8587
data: {
@@ -88,10 +90,11 @@ describeWithEnvironment('TimelineHistoryManager', function() {
8890
},
8991
filmStripForPreview: null,
9092
parsedTrace: parsedTrace1,
91-
startTime: null,
93+
metadata: metadata1,
9294
},
9395
);
94-
const {parsedTrace: parsedTrace2} = await TraceLoader.traceEngine(this, 'timings-track.json.gz');
96+
const {parsedTrace: parsedTrace2, metadata: metadata2} =
97+
await TraceLoader.traceEngine(this, 'timings-track.json.gz');
9598
historyManager.addRecording(
9699
{
97100
data: {
@@ -100,7 +103,7 @@ describeWithEnvironment('TimelineHistoryManager', function() {
100103
},
101104
filmStripForPreview: null,
102105
parsedTrace: parsedTrace2,
103-
startTime: null,
106+
metadata: metadata2,
104107
},
105108
);
106109

@@ -114,8 +117,8 @@ describeWithEnvironment('TimelineHistoryManager', function() {
114117
return elem.innerText.replaceAll('\n', '');
115118
});
116119
assert.deepEqual(menuItemText, [
117-
'localhost3.16 s',
118-
'web.dev5.39 s',
120+
'localhost',
121+
'web.dev1× slowdown, No throttling',
119122
]);
120123

121124
// Cancel the dropdown, which also resolves the show() promise, meaning we
@@ -126,7 +129,8 @@ describeWithEnvironment('TimelineHistoryManager', function() {
126129

127130
it('can select from multiple parsed data objects', async function() {
128131
// Add two parsed data objects to the history manager.
129-
const {parsedTrace: trace1Data} = await TraceLoader.traceEngine(this, 'slow-interaction-button-click.json.gz');
132+
const {parsedTrace: trace1Data, metadata: metadata1} =
133+
await TraceLoader.traceEngine(this, 'slow-interaction-button-click.json.gz');
130134
historyManager.addRecording(
131135
{
132136
data: {
@@ -135,19 +139,20 @@ describeWithEnvironment('TimelineHistoryManager', function() {
135139
},
136140
filmStripForPreview: null,
137141
parsedTrace: trace1Data,
138-
startTime: null,
142+
metadata: metadata1,
139143
},
140144
);
141145

142-
const {parsedTrace: trace2Data} = await TraceLoader.traceEngine(this, 'slow-interaction-keydown.json.gz');
146+
const {parsedTrace: trace2Data, metadata: metadata2} =
147+
await TraceLoader.traceEngine(this, 'slow-interaction-keydown.json.gz');
143148
historyManager.addRecording({
144149
data: {
145150
parsedTraceIndex: 2,
146151
type: 'TRACE_INDEX',
147152
},
148153
filmStripForPreview: null,
149154
parsedTrace: trace2Data,
150-
startTime: null,
155+
metadata: metadata2,
151156
});
152157

153158
// Make sure the correct model is returned when

0 commit comments

Comments
 (0)