Skip to content

Commit 8acdcd5

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[DrJones] Add computed timings
This data matches the calculations in the timing tab of a network request. Fixed: 370024636 Change-Id: Ifcf44e3a8c209cd96f975654eef521248c403207 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5934527 Commit-Queue: Alex Rudenko <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent a51d9f9 commit 8acdcd5

File tree

7 files changed

+119
-69
lines changed

7 files changed

+119
-69
lines changed

front_end/panels/freestyler/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ devtools_module("freestyler") {
4040
"../../models/logs:bundle",
4141
"../../models/trace:bundle",
4242
"../../models/workspace:bundle",
43-
"../../panels/network/forward:bundle",
43+
"../../panels/network:bundle",
4444
"../../panels/utils:bundle",
4545
"../../third_party/marked:bundle",
4646
"../../ui/components/markdown_view:bundle",

front_end/panels/freestyler/DrJonesNetworkAgent.test.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ import type * as Platform from '../../core/platform/platform.js';
77
import * as SDK from '../../core/sdk/sdk.js';
88
import type * as Protocol from '../../generated/protocol.js';
99
import * as Logs from '../../models/logs/logs.js';
10+
import type * as Network from '../../panels/network/network.js';
1011
import {
11-
describeWithEnvironment,
1212
getGetHostConfigStub,
1313
} from '../../testing/EnvironmentHelpers.js';
14+
import {describeWithMockConnection} from '../../testing/MockConnection.js';
15+
import {createNetworkPanelForMockConnection} from '../../testing/NetworkHelpers.js';
16+
import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
1417

1518
import {DrJonesNetworkAgent, ResponseType} from './freestyler.js';
1619

17-
describeWithEnvironment('DrJonesNetworkAgent', () => {
20+
const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
21+
22+
describeWithMockConnection('DrJonesNetworkAgent', () => {
23+
let networkPanel: Network.NetworkPanel.NetworkPanel;
24+
1825
function mockHostConfig(modelId?: string, temperature?: number) {
1926
getGetHostConfigStub({
2027
devToolsExplainThisResourceDogfood: {
@@ -24,6 +31,15 @@ describeWithEnvironment('DrJonesNetworkAgent', () => {
2431
});
2532
}
2633

34+
beforeEach(async () => {
35+
networkPanel = await createNetworkPanelForMockConnection();
36+
});
37+
38+
afterEach(async () => {
39+
await coordinator.done();
40+
networkPanel.detach();
41+
});
42+
2743
describe('buildRequest', () => {
2844
beforeEach(() => {
2945
sinon.restore();
@@ -222,20 +238,8 @@ describeWithEnvironment('DrJonesNetworkAgent', () => {
222238
},
223239
{
224240
title: 'Timing',
225-
text: `Request start time: 500
226-
Request end time: -1
227-
Receiving response headers start time: 1000
228-
Receiving response headers end time: 0
229-
Proxy negotiation start time: 0
230-
Proxy negotiation end time: 0
231-
DNS lookup start time: 0
232-
DNS lookup end time: 0
233-
TCP start time: 0
234-
TCP end time: 0
235-
SSL start time: 0
236-
SSL end time: 0
237-
Sending start: 800
238-
Sending end: 900`,
241+
text:
242+
'Queued at (timestamp): 0 μs\nStarted at (timestamp): 8.3 min\nQueueing (duration): 8.3 min\nConnection start (stalled) (duration): 800.00 ms\nRequest sent (duration): 100.00 ms\nDuration (duration): 8.3 min',
239243
},
240244
{
241245
title: 'Request Initiator Chain',
@@ -270,20 +274,12 @@ foo3: bar3
270274
271275
Response status: 200 \n
272276
Request Timing:
273-
Request start time: 500
274-
Request end time: -1
275-
Receiving response headers start time: 1000
276-
Receiving response headers end time: 0
277-
Proxy negotiation start time: 0
278-
Proxy negotiation end time: 0
279-
DNS lookup start time: 0
280-
DNS lookup end time: 0
281-
TCP start time: 0
282-
TCP end time: 0
283-
SSL start time: 0
284-
SSL end time: 0
285-
Sending start: 800
286-
Sending end: 900
277+
Queued at (timestamp): 0 μs
278+
Started at (timestamp): 8.3 min
279+
Queueing (duration): 8.3 min
280+
Connection start (stalled) (duration): 800.00 ms
281+
Request sent (duration): 100.00 ms
282+
Duration (duration): 8.3 min
287283
288284
Request Initiator Chain:
289285
- URL: https://www.initiator.com

front_end/panels/freestyler/DrJonesNetworkAgent.ts

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Host from '../../core/host/host.js';
77
import * as i18n from '../../core/i18n/i18n.js';
88
import type * as SDK from '../../core/sdk/sdk.js';
99
import * as Logs from '../../models/logs/logs.js';
10+
import * as Network from '../../panels/network/network.js';
1011

1112
import {
1213
AiAgent,
@@ -180,22 +181,54 @@ export function formatHeaders(title: string, headers: SDK.NetworkRequest.NameVal
180181
}
181182

182183
export function formatNetworkRequestTiming(request: SDK.NetworkRequest.NetworkRequest): string {
183-
const timing = request.timing;
184-
185-
return `Request start time: ${request.startTime}
186-
Request end time: ${request.endTime}
187-
Receiving response headers start time: ${timing?.receiveHeadersStart}
188-
Receiving response headers end time: ${timing?.receiveHeadersEnd}
189-
Proxy negotiation start time: ${timing?.proxyStart}
190-
Proxy negotiation end time: ${timing?.proxyEnd}
191-
DNS lookup start time: ${timing?.dnsStart}
192-
DNS lookup end time: ${timing?.dnsEnd}
193-
TCP start time: ${timing?.connectStart}
194-
TCP end time: ${timing?.connectEnd}
195-
SSL start time: ${timing?.sslStart}
196-
SSL end time: ${timing?.sslEnd}
197-
Sending start: ${timing?.sendStart}
198-
Sending end: ${timing?.sendEnd}`;
184+
const calculator = Network.NetworkPanel.NetworkPanel.instance().networkLogView.timeCalculator();
185+
const results =
186+
Network.RequestTimingView.RequestTimingView.calculateRequestTimeRanges(request, calculator.minimumBoundary());
187+
188+
function getDuration(name: string): string|undefined {
189+
const result = results.find(r => r.name === name);
190+
if (!result) {
191+
return;
192+
}
193+
return i18n.TimeUtilities.secondsToString(result.end - result.start, true);
194+
}
195+
196+
const labels = [
197+
{
198+
label: 'Queued at (timestamp)',
199+
value: calculator.formatValue(request.issueTime(), 2),
200+
},
201+
{
202+
label: 'Started at (timestamp)',
203+
value: calculator.formatValue(request.startTime, 2),
204+
},
205+
{
206+
label: 'Queueing (duration)',
207+
value: getDuration('queueing'),
208+
},
209+
{
210+
label: 'Connection start (stalled) (duration)',
211+
value: getDuration('blocking'),
212+
},
213+
{
214+
label: 'Request sent (duration)',
215+
value: getDuration('sending'),
216+
},
217+
{
218+
label: 'Waiting for server response (duration)',
219+
value: getDuration('waiting'),
220+
},
221+
{
222+
label: 'Content download (duration)',
223+
value: getDuration('receiving'),
224+
},
225+
{
226+
label: 'Duration (duration)',
227+
value: getDuration('total'),
228+
},
229+
];
230+
231+
return labels.filter(label => Boolean(label.value)).map(label => `${label.label}: ${label.value}`).join('\n');
199232
}
200233

201234
function formatRequestInitiated(

front_end/panels/network/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ devtools_entrypoint("bundle") {
112112
visibility = [
113113
":*",
114114
"../../entrypoints/*",
115+
"../../panels/freestyler/*",
115116
"../../ui/components/request_link_icon/*",
116117
"../application/*",
117118
]

front_end/panels/network/NetworkPanel.test.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import * as Common from '../../core/common/common.js';
66
import * as SDK from '../../core/sdk/sdk.js';
77
import * as Logs from '../../models/logs/logs.js';
88
import * as Trace from '../../models/trace/trace.js';
9-
import {createTarget, registerNoopActions} from '../../testing/EnvironmentHelpers.js';
9+
import {createTarget} from '../../testing/EnvironmentHelpers.js';
1010
import {describeWithMockConnection} from '../../testing/MockConnection.js';
11+
import {createNetworkPanelForMockConnection} from '../../testing/NetworkHelpers.js';
1112
import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
1213
import * as UI from '../../ui/legacy/legacy.js';
1314

@@ -20,28 +21,8 @@ describeWithMockConnection('NetworkPanel', () => {
2021
let networkPanel: Network.NetworkPanel.NetworkPanel;
2122

2223
beforeEach(async () => {
23-
registerNoopActions(['network.toggle-recording', 'network.clear']);
24-
2524
target = createTarget();
26-
const dummyStorage = new Common.Settings.SettingsStorage({});
27-
for (const settingName
28-
of ['network-color-code-resource-types', 'network.group-by-frame', 'network-record-film-strip-setting']) {
29-
Common.Settings.registerSettingExtension({
30-
settingName,
31-
settingType: Common.Settings.SettingType.BOOLEAN,
32-
defaultValue: false,
33-
});
34-
}
35-
Common.Settings.Settings.instance({
36-
forceNew: true,
37-
syncedStorage: dummyStorage,
38-
globalStorage: dummyStorage,
39-
localStorage: dummyStorage,
40-
});
41-
networkPanel = Network.NetworkPanel.NetworkPanel.instance({forceNew: true, displayScreenshotDelay: 0});
42-
networkPanel.markAsRoot();
43-
networkPanel.show(document.body);
44-
await coordinator.done();
25+
networkPanel = await createNetworkPanelForMockConnection();
4526
});
4627

4728
afterEach(async () => {

front_end/testing/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ts_library("testing") {
2828
"MockScopeChain.ts",
2929
"MutationHelpers.test.ts",
3030
"MutationHelpers.ts",
31+
"NetworkHelpers.ts",
3132
"OverridesHelpers.ts",
3233
"PersistenceHelpers.ts",
3334
"PropertyParser.ts",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2024 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import * as Common from '../core/common/common.js';
6+
import * as Network from '../panels/network/network.js';
7+
import * as Coordinator from '../ui/components/render_coordinator/render_coordinator.js';
8+
9+
import {
10+
registerNoopActions,
11+
} from './EnvironmentHelpers.js';
12+
13+
const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
14+
15+
export async function createNetworkPanelForMockConnection(): Promise<Network.NetworkPanel.NetworkPanel> {
16+
registerNoopActions(['network.toggle-recording', 'network.clear']);
17+
18+
const dummyStorage = new Common.Settings.SettingsStorage({});
19+
for (const settingName
20+
of ['network-color-code-resource-types', 'network.group-by-frame', 'network-record-film-strip-setting']) {
21+
Common.Settings.registerSettingExtension({
22+
settingName,
23+
settingType: Common.Settings.SettingType.BOOLEAN,
24+
defaultValue: false,
25+
});
26+
}
27+
Common.Settings.Settings.instance({
28+
forceNew: true,
29+
syncedStorage: dummyStorage,
30+
globalStorage: dummyStorage,
31+
localStorage: dummyStorage,
32+
});
33+
const networkPanel = Network.NetworkPanel.NetworkPanel.instance({forceNew: true, displayScreenshotDelay: 0});
34+
networkPanel.markAsRoot();
35+
networkPanel.show(document.body);
36+
await coordinator.done();
37+
return networkPanel;
38+
}

0 commit comments

Comments
 (0)