Skip to content

Commit 12820ef

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Use Live Metrics page/device scope options for trace view
Instead of doing URL (w/ fallback to origin) + "ALL" devices, utilize the user configuration set on the Live Metrics view. Bug: 368135130 Change-Id: I49042a2e4e77a1577ffccffc196d572fd0ceb770 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6217306 Auto-Submit: Connor Clark <[email protected]> Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Connor Clark <[email protected]> Commit-Queue: Paul Irish <[email protected]>
1 parent 9532135 commit 12820ef

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

front_end/models/crux-manager/CrUXManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export type FormFactor = 'DESKTOP'|'PHONE'|'TABLET';
2929
export type DeviceScope = FormFactor|'ALL';
3030
export type DeviceOption = DeviceScope|'AUTO';
3131
export type PageScope = 'url'|'origin';
32+
export interface Scope {
33+
pageScope: PageScope;
34+
deviceScope: DeviceScope;
35+
}
3236
export type ConnectionType = 'offline'|'slow-2G'|'2G'|'3G'|'4G';
3337

3438
export interface CrUXRequest {
@@ -384,6 +388,10 @@ export class CrUXManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
384388
return this.fieldDeviceOption === 'AUTO' ? this.#getAutoDeviceScope() : this.fieldDeviceOption;
385389
}
386390

391+
getSelectedScope(): Scope {
392+
return {pageScope: this.fieldPageScope, deviceScope: this.getSelectedDeviceScope()};
393+
}
394+
387395
getSelectedFieldResponse(): CrUXResponse|null|undefined {
388396
const pageScope = this.fieldPageScope;
389397
const deviceScope = this.getSelectedDeviceScope();

front_end/models/trace/insights/Common.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,38 +99,45 @@ export interface CrUXFieldMetricResults {
9999
cls: CrUXFieldMetricNumberResult|null;
100100
}
101101

102-
function getPageResult(cruxFieldData: CrUXManager.PageResult[], url: string, origin: string): CrUXManager.PageResult|
103-
undefined {
102+
function getPageResult(
103+
cruxFieldData: CrUXManager.PageResult[], url: string, origin: string,
104+
scope: CrUXManager.Scope|null = null): CrUXManager.PageResult|undefined {
104105
return cruxFieldData.find(result => {
105-
const key = (result['url-ALL'] || result['origin-ALL'])?.record.key;
106+
const key = scope ? result[`${scope.pageScope}-${scope.deviceScope}`]?.record.key :
107+
(result['url-ALL'] || result['origin-ALL'])?.record.key;
106108
return (key?.url && key.url === url) || (key?.origin && key.origin === origin);
107109
});
108110
}
109111

110112
function getMetricResult(
111-
pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames): CrUXFieldMetricNumberResult|null {
112-
let value = pageResult['url-ALL']?.record.metrics[name]?.percentiles?.p75;
113-
if (typeof value === 'string') {
114-
value = Number(value);
115-
}
116-
if (typeof value === 'number' && Number.isFinite(value)) {
117-
return {value, pageScope: 'url'};
118-
}
119-
120-
value = pageResult['origin-ALL']?.record.metrics[name]?.percentiles?.p75;
121-
if (typeof value === 'string') {
122-
value = Number(value);
123-
}
124-
if (typeof value === 'number' && Number.isFinite(value)) {
125-
return {value, pageScope: 'origin'};
113+
pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,
114+
scope: CrUXManager.Scope|null = null): CrUXFieldMetricNumberResult|null {
115+
const scopes: Array<{pageScope: CrUXManager.PageScope, deviceScope: CrUXManager.DeviceScope}> = [];
116+
if (scope) {
117+
scopes.push(scope);
118+
} else {
119+
scopes.push({pageScope: 'url', deviceScope: 'ALL'});
120+
scopes.push({pageScope: 'origin', deviceScope: 'ALL'});
121+
}
122+
123+
for (const scope of scopes) {
124+
const key = `${scope.pageScope}-${scope.deviceScope}` as const;
125+
let value = pageResult[key]?.record.metrics[name]?.percentiles?.p75;
126+
if (typeof value === 'string') {
127+
value = Number(value);
128+
}
129+
if (typeof value === 'number' && Number.isFinite(value)) {
130+
return {value, pageScope: scope.pageScope};
131+
}
126132
}
127133

128134
return null;
129135
}
130136

131137
function getMetricTimingResult(
132-
pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames): CrUXFieldMetricTimingResult|null {
133-
const result = getMetricResult(pageResult, name);
138+
pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,
139+
scope: CrUXManager.Scope|null = null): CrUXFieldMetricTimingResult|null {
140+
const result = getMetricResult(pageResult, name, scope);
134141
if (result) {
135142
const valueMs = result.value as Types.Timing.Milli;
136143
return {value: Helpers.Timing.milliToMicro(valueMs), pageScope: result.pageScope};
@@ -140,22 +147,23 @@ function getMetricTimingResult(
140147
}
141148

142149
export function getFieldMetricsForInsightSet(
143-
insightSet: InsightSet, metadata: Types.File.MetaData|null): CrUXFieldMetricResults|null {
150+
insightSet: InsightSet, metadata: Types.File.MetaData|null,
151+
scope: CrUXManager.Scope|null = null): CrUXFieldMetricResults|null {
144152
const cruxFieldData = metadata?.cruxFieldData;
145153
if (!cruxFieldData) {
146154
return null;
147155
}
148156

149-
const pageResult = getPageResult(cruxFieldData, insightSet.url.href, insightSet.url.origin);
157+
const pageResult = getPageResult(cruxFieldData, insightSet.url.href, insightSet.url.origin, scope);
150158
if (!pageResult) {
151159
return null;
152160
}
153161

154162
return {
155-
fcp: getMetricTimingResult(pageResult, 'first_contentful_paint'),
156-
lcp: getMetricTimingResult(pageResult, 'largest_contentful_paint'),
157-
inp: getMetricTimingResult(pageResult, 'interaction_to_next_paint'),
158-
cls: getMetricResult(pageResult, 'cumulative_layout_shift'),
163+
fcp: getMetricTimingResult(pageResult, 'first_contentful_paint', scope),
164+
lcp: getMetricTimingResult(pageResult, 'largest_contentful_paint', scope),
165+
inp: getMetricTimingResult(pageResult, 'interaction_to_next_paint', scope),
166+
cls: getMetricResult(pageResult, 'cumulative_layout_shift', scope),
159167
};
160168
}
161169

front_end/panels/timeline/TimelineFlameChartView.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as Platform from '../../core/platform/platform.js';
88
import * as Root from '../../core/root/root.js';
99
import * as SDK from '../../core/sdk/sdk.js';
1010
import * as Bindings from '../../models/bindings/bindings.js';
11+
import * as CrUXManager from '../../models/crux-manager/crux-manager.js';
1112
import * as Trace from '../../models/trace/trace.js';
1213
import * as TraceBounds from '../../services/trace_bounds/trace_bounds.js';
1314
import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
@@ -567,7 +568,9 @@ export class TimelineFlameChartView extends Common.ObjectWrapper.eventMixin<Even
567568
for (const [key, insightSet] of this.#traceInsightSets) {
568569
if (insightSet.navigation) {
569570
fieldMetricResultsByNavigationId.set(
570-
key, Trace.Insights.Common.getFieldMetricsForInsightSet(insightSet, this.#traceMetadata));
571+
key,
572+
Trace.Insights.Common.getFieldMetricsForInsightSet(
573+
insightSet, this.#traceMetadata, CrUXManager.CrUXManager.instance().getSelectedScope()));
571574
}
572575
}
573576

front_end/panels/timeline/components/SidebarSingleInsightSet.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as i18n from '../../../core/i18n/i18n.js';
66
import * as Platform from '../../../core/platform/platform.js';
77
import * as Root from '../../../core/root/root.js';
8+
import * as CrUXManager from '../../../models/crux-manager/crux-manager.js';
89
import * as Trace from '../../../models/trace/trace.js';
910
import * as Buttons from '../../../ui/components/buttons/buttons.js';
1011
import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js';
@@ -211,32 +212,17 @@ export class SidebarSingleInsightSet extends HTMLElement {
211212

212213
#getFieldMetrics(insightSetKey: string): Omit<Trace.Insights.Common.CrUXFieldMetricResults, 'fcp'>|null {
213214
const insightSet = this.#data.insights?.get(insightSetKey);
214-
const fieldMetricsResults =
215-
insightSet && Trace.Insights.Common.getFieldMetricsForInsightSet(insightSet, this.#data.traceMetadata);
216-
if (!fieldMetricsResults) {
215+
if (!insightSet) {
217216
return null;
218217
}
219218

220-
let {lcp, inp, cls} = fieldMetricsResults;
221-
222-
// Only show field data from the Origin or URL datasets, but never a mix.
223-
if (lcp?.pageScope === 'url' || inp?.pageScope === 'url' || cls?.pageScope === 'url') {
224-
if (lcp?.pageScope === 'origin') {
225-
lcp = null;
226-
}
227-
if (inp?.pageScope === 'origin') {
228-
inp = null;
229-
}
230-
if (cls?.pageScope === 'origin') {
231-
cls = null;
232-
}
233-
}
234-
235-
if (!(lcp || cls || inp)) {
219+
const fieldMetricsResults = Trace.Insights.Common.getFieldMetricsForInsightSet(
220+
insightSet, this.#data.traceMetadata, CrUXManager.CrUXManager.instance().getSelectedScope());
221+
if (!fieldMetricsResults) {
236222
return null;
237223
}
238224

239-
return {lcp, cls, inp};
225+
return fieldMetricsResults;
240226
}
241227

242228
/**

0 commit comments

Comments
 (0)