Skip to content

Commit

Permalink
Make the null timestmap checks more generic for the metric markers
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Jan 6, 2023
1 parent 7b58cc0 commit 7fb305d
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/profile-logic/process-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { isArtTraceFormat, convertArtTraceProfile } from './import/art-trace';
import {
PROCESSED_PROFILE_VERSION,
INTERVAL,
INTERVAL_END,
INSTANT,
} from '../app-logic/constants';
import {
Expand Down Expand Up @@ -87,6 +88,7 @@ import type {
PageList,
ThreadIndex,
BrowsertimeMarkerPayload,
MarkerPhase,
} from 'firefox-profiler/types';

type RegExpResult = null | string[];
Expand Down Expand Up @@ -1736,18 +1738,30 @@ export function processVisualMetrics(
(cat) => cat.name === 'Test'
);

function addMetricMarker(
function maybeAddMetricMarker(
thread: Thread,
name: string,
startTime: number,
endTime?: number,
phase: MarkerPhase,
startTime: number | null,
endTime: number | null,
payload?: BrowsertimeMarkerPayload
) {
if (
// All phases except INTERVAL_END should have a start time.
(phase !== INTERVAL_END && startTime === null) ||
// Only INTERVAL and INTERVAL_END should have an end time.
((phase === INTERVAL || phase === INTERVAL_END) && endTime === null)
) {
// Do not add if some timestamps we expect are missing.
// This should ideally never happen but timestamps could be null due to
// browsertime bug here: https://github.com/sitespeedio/browsertime/issues/1746.
return;
}
// Add the marker to the given thread.
thread.markers.name.push(thread.stringTable.indexForString(name));
thread.markers.startTime.push(startTime);
thread.markers.endTime.push(endTime ? endTime : 0);
thread.markers.phase.push(endTime ? INTERVAL : INSTANT);
thread.markers.endTime.push(endTime);
thread.markers.phase.push(phase);
thread.markers.category.push(testingCategoryIdx);
thread.markers.data.push(payload ?? null);
thread.markers.length++;
Expand Down Expand Up @@ -1778,20 +1792,14 @@ export function processVisualMetrics(
continue;
}

if (metric.every((m) => m.timestamp === null)) {
// Skip it if we don't have any timestamps.
// This is due to https://github.com/sitespeedio/browsertime/issues/1746.
continue;
}

const startTime = navigationStartTime ?? metric[0].timestamp;
const endTime = metric[metric.length - 1].timestamp;

// Add the progress marker to the parent process main thread.
const markerName = `${metricName} Progress`;
addMetricMarker(mainThread, markerName, startTime, endTime);
maybeAddMetricMarker(mainThread, markerName, INTERVAL, startTime, endTime);
// Add the progress marker to the tab process main thread.
addMetricMarker(tabThread, markerName, startTime, endTime);
maybeAddMetricMarker(tabThread, markerName, INTERVAL, startTime, endTime);

// Add progress markers for every visual progress change for more fine grained information.
const progressMarkerSchema = {
Expand All @@ -1804,31 +1812,28 @@ export function processVisualMetrics(

const changeMarkerName = `${metricName} Change`;
for (const { timestamp, percent } of metric) {
if (timestamp === null) {
// Skip it if we don't have a timestamp.
// This might be due to https://github.com/sitespeedio/browsertime/issues/1746.
continue;
}
const payload = {
type: 'VisualMetricProgress',
// 'percentage' type expects a value between 0 and 1.
percentage: percent / 100,
};

// Add it to the parent process main thread.
addMetricMarker(
maybeAddMetricMarker(
mainThread,
changeMarkerName,
INSTANT,
timestamp,
undefined, // endTime
null, // endTime
payload
);
// Add it to the tab process main thread.
addMetricMarker(
maybeAddMetricMarker(
tabThread,
changeMarkerName,
INSTANT,
timestamp,
undefined, // endTime
null, // endTime
payload
);
}
Expand Down

0 comments on commit 7fb305d

Please sign in to comment.