Skip to content

Instantly share code, notes, and snippets.

@bgrins
Last active March 27, 2023 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrins/7af0c5883c4c31b88a8b45f82aa593af to your computer and use it in GitHub Desktop.
Save bgrins/7af0c5883c4c31b88a8b45f82aa593af to your computer and use it in GitHub Desktop.
for use in webconsole on https://profiler.firefox.com/
function zoomOnMarkers(marker1, marker2) {
const zeroAt = selectors.profile.getZeroAt(getState());
dispatch(actions.commitRange(marker1.start - zeroAt, marker2.start - zeroAt));
}
function resetRange() {
dispatch(actions.popCommittedRanges(0));
}
function findRanges(suiteName) {
const startMarkers = new Map();
const ranges = [];
for (const marker of filteredMarkers) {
if (
marker.name !== "UserTiming" ||
!marker.data ||
!marker.data.name ||
(suiteName && !marker.data.name.includes(`-${suiteName}`))
) {
continue;
}
const markerName = marker.data.name;
if (markerName.startsWith("start-suite-")) {
startMarkers.set(markerName.slice("start-suite-".length), marker);
}
if (markerName.startsWith("end-suite-")) {
const baseName = markerName.slice("end-suite-".length);
const startMarker = startMarkers.get(baseName);
startMarkers.delete(baseName);
if (startMarker) {
ranges.push([baseName, [startMarker, marker]]);
}
}
}
return ranges;
}
function gatherUrlsForRanges(ranges) {
return ranges.map(([baseName, [marker1, marker2]]) => {
zoomOnMarkers(marker1, marker2);
const location = window.location.href;
resetRange();
return [baseName, location];
});
}
async function prettyPrint(suiteName) {
let results = await run(suiteName);
let strs = [];
for (const [baseName, url] of results) {
strs.push(`${baseName} ${url}`);
}
console.log("\n" + strs.join("\n"));
}
// Run with await run()
async function run(suiteName) {
const dataSource = selectors.urlState.getDataSource(getState());
if (dataSource === "from-browser") {
console.error(
"This snippet works with an uploaded profile only, but this profile hasn't been yet. Please upload this profile and try again"
);
}
return Promise.all(
gatherUrlsForRanges(findRanges(suiteName)).map(async ([baseName, url]) => [
baseName,
await shortenUrl(url),
])
);
}
await prettyPrint()
@mstange
Copy link

mstange commented Mar 21, 2023

It would be cool to change the profile title, too, so that the subtest name is shown in the tab label

@bgrins
Copy link
Author

bgrins commented Mar 27, 2023

for reference, here's how we'd change the name dispatch(actions.changeProfileName("New name"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment