Skip to content

Commit

Permalink
Support the case where some visual metrics properties are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Mar 31, 2022
1 parent 8588fcc commit ca65ee1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/profile-logic/tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,17 @@ export function computeGlobalTracks(profile: Profile): GlobalTrack[] {

// Add the visual progress tracks if we have visualMetrics data.
if (profile.meta && profile.meta.visualMetrics) {
globalTracks.push({ type: 'visual-progress' });
globalTracks.push({ type: 'perceptual-visual-progress' });
globalTracks.push({ type: 'contentful-visual-progress' });
const metrics = profile.meta.visualMetrics;
// Some metrics might be missing depending on the options specified to browsertime.
if (metrics.VisualProgress) {
globalTracks.push({ type: 'visual-progress' });
}
if (metrics.PerceptualSpeedIndexProgress) {
globalTracks.push({ type: 'perceptual-visual-progress' });
}
if (metrics.ContentfulSpeedIndexProgress) {
globalTracks.push({ type: 'contentful-visual-progress' });
}
}

// When adding a new track type, this sort ensures that the newer tracks are added
Expand Down
15 changes: 8 additions & 7 deletions src/selectors/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ export const getVisualMetrics: Selector<VisualMetrics> = (state) =>
getVisualMetricsOrNull(state),
'Tried to access the visual metrics when it does not exist.'
);
export const getVisualProgress: Selector<ProgressGraphData[]> = (state) =>
getVisualMetrics(state).VisualProgress;
export const getPerceptualSpeedIndexProgress: Selector<ProgressGraphData[]> = (
export const getVisualProgress: Selector<ProgressGraphData[] | null> = (
state
) => getVisualMetrics(state).PerceptualSpeedIndexProgress;
export const getContentfulSpeedIndexProgress: Selector<ProgressGraphData[]> = (
state
) => getVisualMetrics(state).ContentfulSpeedIndexProgress;
) => getVisualMetrics(state).VisualProgress;
export const getPerceptualSpeedIndexProgress: Selector<
ProgressGraphData[] | null
> = (state) => getVisualMetrics(state).PerceptualSpeedIndexProgress ?? null;
export const getContentfulSpeedIndexProgress: Selector<
ProgressGraphData[] | null
> = (state) => getVisualMetrics(state).ContentfulSpeedIndexProgress ?? null;
export const getProfilerConfiguration: Selector<?ProfilerConfiguration> = (
state
) => getMeta(state).configuration;
Expand Down
17 changes: 9 additions & 8 deletions src/types/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,6 @@ export type ProgressGraphData = {|
* into the geckoprofile. More information about browsertime can be found through https://github.com/mozilla/browsertime.
*/
export type VisualMetrics = {|
// ContentfulSpeedIndex and ContentfulSpeedIndexProgress generated here
// https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1330
ContentfulSpeedIndex: number,
ContentfulSpeedIndexProgress: ProgressGraphData[],
// PerceptualSpeedIndex and PerceptualSpeedIndexProgress generated here
// https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1319
PerceptualSpeedIndex: number,
PerceptualSpeedIndexProgress: ProgressGraphData[],
// FirstVisualChange, LastVisualChange, SpeedIndex generated here
// https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1310
FirstVisualChange: number,
Expand All @@ -712,6 +704,15 @@ export type VisualMetrics = {|
VisualComplete85: number,
VisualComplete95: number,
VisualComplete99: number,
// Contentful and Perceptual values may all be missing
// ContentfulSpeedIndex and ContentfulSpeedIndexProgress generated here
// https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1330
ContentfulSpeedIndex?: number,
ContentfulSpeedIndexProgress?: ProgressGraphData[],
// PerceptualSpeedIndex and PerceptualSpeedIndexProgress generated here
// https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1319
PerceptualSpeedIndex?: number,
PerceptualSpeedIndexProgress?: ProgressGraphData[],
|};

// Units of ThreadCPUDelta values for different platforms.
Expand Down

0 comments on commit ca65ee1

Please # to comment.