Skip to content

Commit 31f5188

Browse files
Nancy LiDevtools-frontend LUCI CQ
authored andcommitted
[RPP Insight] Highlight the longest network dependency chain
After: https://screenshot.googleplex.com/BcmczdQCgiFypFJ Bug: 372897712 Change-Id: I064fa34f02b7f4ee455f05c65629d5c7e7d24152 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6298809 Commit-Queue: Nancy Li <[email protected]> Reviewed-by: Andres Olivares <[email protected]>
1 parent f0db244 commit 31f5188

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

front_end/models/trace/insights/NetworkDependencyTree.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import {getFirstOrError, getInsightOrError, processTrace} from '../../../testing
77
import * as Trace from '../trace.js';
88

99
describeWithEnvironment('NetworkDependencyTree', function() {
10-
it('calculates network dependency tree', async () => {
10+
let insight: Trace.Insights.Types.InsightModels['NetworkDependencyTree'];
11+
12+
before(async function() {
1113
const {data, insights} = await processTrace(this, 'lcp-multiple-frames.json.gz');
1214
const firstNav = getFirstOrError(data.Meta.navigationsByNavigationId.values());
13-
const insight = getInsightOrError('NetworkDependencyTree', insights, firstNav);
15+
insight = getInsightOrError('NetworkDependencyTree', insights, firstNav);
16+
});
1417

18+
it('calculates network dependency tree', async () => {
1519
// The network dependency tree in this trace is
1620
// | .../index.html (ts:566777570990, dur:5005590)
1721
// |
@@ -35,9 +39,24 @@ describeWithEnvironment('NetworkDependencyTree', function() {
3539
child1.timeFromInitialRequest,
3640
Trace.Types.Timing.Micro(child1.request.ts + child1.request.dur - root.request.ts));
3741
assert.lengthOf(child1.children, 0);
42+
});
3843

39-
// The chain |index.html -> app.js| is the longest
44+
it('Calculate the max critical path latency', async () => {
45+
// The chain |index.html(root) -> app.js(child1)| is the longest
46+
const root = insight.rootNodes[0];
47+
const child1 = root.children[1];
4048
assert.strictEqual(
4149
insight.maxTime, Trace.Types.Timing.Micro(child1.request.ts + child1.request.dur - root.request.ts));
4250
});
51+
52+
it('Marks the longest network dependency chain', async () => {
53+
const root = insight.rootNodes[0];
54+
const [child0, child1] = root.children;
55+
56+
// The chain |index.html(root) -> app.js(child1)| is the longest
57+
assert.isTrue(root.isLongest);
58+
assert.isTrue(child1.isLongest);
59+
// The |app.css| is not in the longest chain
60+
assert.isNotTrue(child0.isLongest);
61+
});
4362
});

front_end/models/trace/insights/NetworkDependencyTree.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface CriticalRequestNode {
5555
request: Types.Events.SyntheticNetworkRequest;
5656
timeFromInitialRequest: Types.Timing.Micro;
5757
children: CriticalRequestNode[];
58+
isLongest?: boolean;
5859
}
5960

6061
export type NetworkDependencyTreeInsightModel = InsightModel<typeof UIStrings, {
@@ -125,11 +126,20 @@ export function generateInsight(
125126
const rootNodes: CriticalRequestNode[] = [];
126127
let maxTime = Types.Timing.Micro(0);
127128

129+
let longestChain: Types.Events.SyntheticNetworkRequest[] = [];
130+
128131
function addChain(path: Types.Events.SyntheticNetworkRequest[]): void {
129132
if (path.length === 0) {
130133
return;
131134
}
132135
const initialRequest = path[0];
136+
const lastRequest = path[path.length - 1];
137+
const totalChainTime = Types.Timing.Micro(lastRequest.ts + lastRequest.dur - initialRequest.ts);
138+
if (totalChainTime > maxTime) {
139+
maxTime = totalChainTime;
140+
longestChain = path;
141+
}
142+
133143
let currentNodes = rootNodes;
134144

135145
for (const networkRequest of path) {
@@ -138,7 +148,6 @@ export function generateInsight(
138148

139149
if (!found) {
140150
const timeFromInitialRequest = Types.Timing.Micro(networkRequest.ts + networkRequest.dur - initialRequest.ts);
141-
maxTime = Types.Timing.Micro(Math.max(maxTime, timeFromInitialRequest));
142151
found = {
143152
request: networkRequest,
144153
timeFromInitialRequest,
@@ -183,6 +192,20 @@ export function generateInsight(
183192
addChain(networkPath);
184193
}, getNextNodes);
185194

195+
// Mark the longest chain
196+
if (longestChain.length > 0) {
197+
let currentNodes = rootNodes;
198+
for (const request of longestChain) {
199+
const found = currentNodes.find(node => node.request === request);
200+
if (found) {
201+
found.isLongest = true;
202+
currentNodes = found.children;
203+
} else {
204+
console.error('Some request in the longest chain is not found');
205+
}
206+
}
207+
}
208+
186209
return finalize({
187210
rootNodes,
188211
maxTime,

front_end/panels/timeline/components/insights/NetworkDependencyTree.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ export class NetworkDependencyTree extends BaseInsightComponent<NetworkDependenc
5151
// clang-format off
5252
return html`
5353
<ul>
54-
${nodes.map(({request, timeFromInitialRequest, children}) => {
54+
${nodes.map(({request, timeFromInitialRequest, children, isLongest}) => {
5555
const hasChildren = children.length > 0;
5656
57+
const requestClasses = Lit.Directives.classMap({
58+
request: true,
59+
longest: Boolean(isLongest),
60+
});
61+
5762
return html`
5863
<li>
59-
<div class="request">
64+
<div class=${requestClasses}>
6065
<span class="url">${eventRef(request)}</span>
6166
${
6267
// If this is the last request, show the chain time

front_end/panels/timeline/components/insights/baseInsightComponent.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ dd.dl-title {
165165
.timeline-link {
166166
cursor: pointer;
167167
text-decoration: var(--override-timeline-link-text-decoration, underline);
168-
color: var(--sys-color-primary);
168+
color: var(--override-timeline-link-text-color, var(--sys-color-primary));
169169
/* for a11y reasons this is a button, so we have to remove some default
170170
* styling */
171171
background: none;

front_end/panels/timeline/components/insights/networkDependencyTreeInsight.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
.request {
3636
display: flex;
3737

38+
&.longest {
39+
--override-timeline-link-text-color: var(--sys-color-error);
40+
41+
color: var(--sys-color-error);
42+
}
43+
3844
.url {
3945
flex: auto;
4046
}

0 commit comments

Comments
 (0)