diff --git a/src/profile-logic/tracks.js b/src/profile-logic/tracks.js index c6d16011efd..d6e15bd5a62 100644 --- a/src/profile-logic/tracks.js +++ b/src/profile-logic/tracks.js @@ -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 diff --git a/src/selectors/profile.js b/src/selectors/profile.js index d12485a6752..949b67db031 100644 --- a/src/selectors/profile.js +++ b/src/selectors/profile.js @@ -170,14 +170,15 @@ export const getVisualMetrics: Selector = (state) => getVisualMetricsOrNull(state), 'Tried to access the visual metrics when it does not exist.' ); -export const getVisualProgress: Selector = (state) => - getVisualMetrics(state).VisualProgress; -export const getPerceptualSpeedIndexProgress: Selector = ( +export const getVisualProgress: Selector = ( state -) => getVisualMetrics(state).PerceptualSpeedIndexProgress; -export const getContentfulSpeedIndexProgress: Selector = ( - 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 = ( state ) => getMeta(state).configuration; diff --git a/src/types/profile.js b/src/types/profile.js index f6cc9d49020..0316c10bf81 100644 --- a/src/types/profile.js +++ b/src/types/profile.js @@ -688,27 +688,27 @@ 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 + // Most values from this object are generated by the python script + // https://github.com/sitespeedio/browsertime/blob/6e88284930c1d3ded8d9d95252d2e13c252d361c/browsertime/visualmetrics.py + // Especially look at the function calculate_visual_metrics. + // Then the script is called and the result processed from the JS files in https://github.com/sitespeedio/browsertime/tree/6e88284930c1d3ded8d9d95252d2e13c252d361c/lib/video/postprocessing/visualmetrics + // and https://github.com/sitespeedio/browsertime/blob/6e88284930c1d3ded8d9d95252d2e13c252d361c/lib/core/engine/iteration.js#L261-L264. + // Finally they're inserted into the JSON profile in + // https://github.com/sitespeedio/browsertime/blob/6e88284930c1d3ded8d9d95252d2e13c252d361c/lib/firefox/webdriver/firefox.js#L215-L230 FirstVisualChange: number, LastVisualChange: number, SpeedIndex: number, - // VisualProgress generated here - // https://github.com/mozilla/browsertime/blob/master/vendor/visualmetrics.py#L1390 VisualProgress: ProgressGraphData[], - // VisualReadiness generated here - // https://github.com/mozilla/browsertime/blob/master/lib/video/postprocessing/visualmetrics/extraMetrics.js#L5 + // Contentful and Perceptual values may be missing. They're generated only if + // the user specifies the options --visualMetricsContentful and + // --visualMetricsPerceptual in addition to --visualMetrics. + ContentfulSpeedIndex?: number, + ContentfulSpeedIndexProgress?: ProgressGraphData[], + PerceptualSpeedIndex?: number, + PerceptualSpeedIndexProgress?: ProgressGraphData[], + // VisualReadiness and VisualCompleteXX values are generated in + // https://github.com/sitespeedio/browsertime/blob/main/lib/video/postprocessing/visualmetrics/extraMetrics.js VisualReadiness: number, - // VisualComplete85, VisualComplete95, VisualComplete99 generated here - // https://github.com/mozilla/browsertime/blob/master/lib/video/postprocessing/visualmetrics/extraMetrics.js#L10 VisualComplete85: number, VisualComplete95: number, VisualComplete99: number,