Skip to content

Commit

Permalink
chore(es/minifier): Add a script for samply profiler (#9923)
Browse files Browse the repository at this point in the history
**Description:**

I can copy-paste this script to merge needless stack trace items.
  • Loading branch information
kdy1 authored Jan 22, 2025
1 parent e8f23cf commit 8f8dcaa
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions crates/swc_ecma_minifier/scripts/_/samply-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

(async () => {
const treeView = document.querySelector(".treeViewBodyInner.treeViewBodyInner1");

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function triggerMouseEvent(node, eventType) {
var clickEvent = new PointerEvent(eventType, { button: 0, bubbles: true, cancelable: true });
node.dispatchEvent(clickEvent);
}

async function sendKey(node, key, keyCode, code) {
node.dispatchEvent(new KeyboardEvent("keydown", {
key: key,
keyCode: keyCode,
code: code,
which: keyCode,
shiftKey: false,
ctrlKey: false,
metaKey: false,
bubbles: true,
cancelable: true,
}));
node.dispatchEvent(new KeyboardEvent("keyup", {
key: key,
keyCode: keyCode,
code: code,
which: keyCode,
shiftKey: false,
ctrlKey: false,
metaKey: false,
bubbles: true,
cancelable: true,
}));

}

async function handleRow(row) {
const lib = row.querySelector('.lib');
const libText = lib.textContent.trim();
if (libText.endsWith("/swc_ecma_visit/src/generated.rs") ||
libText.endsWith("/swc_ecma_utils/src/parallel.rs") ||
libText.includes('/.rustup/') ||
libText.includes('chili-0.2.0/') ||
libText.includes('scoped-tls-1.0.1/') ||
libText.includes('indexmap-2.5.0/') ||
libText.includes('hashbrown-0.14.5/') ||
libText.includes('/rust/deps/') ||
libText.includes('/better_scoped_tls/') ||
libText.includes('/swc_parallel/')) {
triggerMouseEvent(row, "mouseover");
triggerMouseEvent(row, "mousedown");
triggerMouseEvent(row, "mouseup");
triggerMouseEvent(row, "click");
await sleep(30);

await sendKey(row, 'm', 77, 'KeyM');
await sleep(100);
return true;
}
}


while (true) {
const rows = treeView.querySelectorAll('.treeViewRow');
console.log(`Checking ${rows.length} rows`);


let didWork = false;
for (const row of rows) {
if (await handleRow(row)) {
console.log("Worked");
didWork = true;
break;
}
}

if (!didWork) {
break;
}
}

})();

0 comments on commit 8f8dcaa

Please sign in to comment.