Skip to content

Commit 12ddc0d

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
Move insightBounds helper into models/trace/insights
R=cjamcl@chromium.org Bug: 442509324 Change-Id: I1ddc433c2b14087ca6147cf932a02ac77e0e5f1d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6917689 Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Connor Clark <cjamcl@chromium.org> Reviewed-by: Connor Clark <cjamcl@chromium.org>
1 parent 065facb commit 12ddc0d

4 files changed

Lines changed: 73 additions & 20 deletions

File tree

front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class PerformanceTraceFormatter {
9595
continue;
9696
}
9797

98-
const insightBounds = TimelineUtils.InsightAIContext.insightBounds(model, insightSet.bounds);
98+
const insightBounds = Trace.Insights.Common.insightBounds(model, insightSet.bounds);
9999
const insightParts = [
100100
`insight name: ${insightName}`,
101101
`description: ${model.description}`,

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {RecursivePartial} from '../../../core/platform/TypescriptUtilities.
66
import * as Protocol from '../../../generated/protocol.js';
77
import {describeWithEnvironment} from '../../../testing/EnvironmentHelpers.js';
88
import {getFirstOrError, processTrace} from '../../../testing/InsightHelpers.js';
9+
import {microsecondsTraceWindow} from '../../../testing/TraceHelpers.js';
910
import type * as Types from '../types/types.js';
1011

1112
import * as Insights from './insights.js';
@@ -122,4 +123,56 @@ describeWithEnvironment('Common', function() {
122123
assert.strictEqual(result, 33); // uses default compression ratio.
123124
});
124125
});
126+
127+
describe('insightBounds', () => {
128+
const INSIGHT_SET_BOUNDS = microsecondsTraceWindow(0, 1_000);
129+
130+
it('uses the bounds of the overlays', async () => {
131+
const fakeInsight = {
132+
createOverlays(): Types.Overlays.Overlay[] {
133+
return [{
134+
type: 'TIME_RANGE',
135+
bounds: microsecondsTraceWindow(100, 500),
136+
label: 'test',
137+
showDuration: true,
138+
}];
139+
}
140+
} as unknown as Insights.Types.InsightModel;
141+
const bounds = Insights.Common.insightBounds(fakeInsight, INSIGHT_SET_BOUNDS);
142+
assert.deepEqual(bounds, microsecondsTraceWindow(100, 500));
143+
});
144+
145+
it('merges the bounds of two overlays', async () => {
146+
const fakeInsight = {
147+
createOverlays(): Types.Overlays.Overlay[] {
148+
return [
149+
{
150+
type: 'TIME_RANGE',
151+
bounds: microsecondsTraceWindow(100, 500),
152+
label: 'test',
153+
showDuration: true,
154+
},
155+
{
156+
type: 'TIME_RANGE',
157+
bounds: microsecondsTraceWindow(50, 400),
158+
label: 'test',
159+
showDuration: true,
160+
}
161+
];
162+
}
163+
} as unknown as Insights.Types.InsightModel;
164+
const bounds = Insights.Common.insightBounds(fakeInsight, INSIGHT_SET_BOUNDS);
165+
assert.deepEqual(bounds, microsecondsTraceWindow(50, 500));
166+
});
167+
168+
it('falls back to the set bounds if there are no overlays', async () => {
169+
const fakeInsight = {
170+
createOverlays(): Types.Overlays.Overlay[] {
171+
return [];
172+
}
173+
} as unknown as Insights.Types.InsightModel;
174+
const bounds = Insights.Common.insightBounds(fakeInsight, INSIGHT_SET_BOUNDS);
175+
assert.deepEqual(bounds, INSIGHT_SET_BOUNDS);
176+
});
177+
});
125178
});

front_end/models/trace/insights/Common.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as Types from '../types/types.js';
1212
import {getLogNormalScore} from './Statistics.js';
1313
import {
1414
InsightKeys,
15+
type InsightModel,
1516
type InsightModels,
1617
type InsightSet,
1718
type InsightSetContext,
@@ -432,3 +433,21 @@ export function calculateDocFirstByteTs(docRequest: Types.Events.SyntheticNetwor
432433
Helpers.Timing.secondsToMicro(timing.requestTime) +
433434
Helpers.Timing.milliToMicro(timing.receiveHeadersStart ?? timing.receiveHeadersEnd));
434435
}
436+
437+
/**
438+
* Calculates the trace bounds for the given insight that are relevant.
439+
*
440+
* Uses the insight's overlays to determine the relevant trace bounds. If there are
441+
* no overlays, falls back to the insight set's navigation bounds.
442+
*/
443+
export function insightBounds(
444+
insight: InsightModel, insightSetBounds: Types.Timing.TraceWindowMicro): Types.Timing.TraceWindowMicro {
445+
const overlays = insight.createOverlays?.() ?? [];
446+
const windows = overlays.map(Helpers.Timing.traceWindowFromOverlay).filter(bounds => !!bounds);
447+
const overlaysBounds = Helpers.Timing.combineTraceWindowsMicro(windows);
448+
if (overlaysBounds) {
449+
return overlaysBounds;
450+
}
451+
452+
return insightSetBounds;
453+
}

front_end/panels/timeline/utils/InsightAIContext.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,3 @@ export class AIQueries {
126126
.filter(tree => !!tree);
127127
}
128128
}
129-
130-
/**
131-
* Calculates the trace bounds for the given insight that are relevant.
132-
*
133-
* Uses the insight's overlays to determine the relevant trace bounds. If there are
134-
* no overlays, falls back to the insight set's navigation bounds.
135-
*/
136-
export function insightBounds(
137-
insight: Trace.Insights.Types.InsightModel,
138-
insightSetBounds: Trace.Types.Timing.TraceWindowMicro): Trace.Types.Timing.TraceWindowMicro {
139-
const overlays = insight.createOverlays?.() ?? [];
140-
const windows = overlays.map(Trace.Helpers.Timing.traceWindowFromOverlay).filter(bounds => !!bounds);
141-
const overlaysBounds = Trace.Helpers.Timing.combineTraceWindowsMicro(windows);
142-
if (overlaysBounds) {
143-
return overlaysBounds;
144-
}
145-
146-
return insightSetBounds;
147-
}

0 commit comments

Comments
 (0)