Skip to content

Commit

Permalink
add perf test script
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Apr 19, 2023
1 parent 7a2c119 commit ad8947e
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 12 deletions.
21 changes: 9 additions & 12 deletions vuu-ui/scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,18 @@ export const assertFolderExists = (folderName, exitIfFalse) => {
return true;
};

export const writeMetaFile = async (meta, outdir) =>
export const writeJsonFileFile = async (json, path) =>
new Promise((resolve, reject) => {
console.log(`write bundle metafile`);
fs.writeFile(
`${outdir}/meta.json`,
JSON.stringify(meta, null, 2),
(err) => {
if (err) {
reject(err);
} else {
resolve();
}
fs.writeFile(path, JSON.stringify(json, null, 2), (err) => {
if (err) {
reject(err);
} else {
resolve();
}
);
});
});
export const writeMetaFile = async (meta, outdir) =>
writeJsonFileFile(meta, `${outdir}/meta.json`);

export const padRight = (str, length) => {
return (str + Array(length).fill(" ").join("")).slice(0, length);
Expand Down
120 changes: 120 additions & 0 deletions vuu-ui/tools/chrome-devtools-protocol/launch-headless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import chromeLauncher from "chrome-launcher";
import CDP from "chrome-remote-interface";
import { writeJsonFileFile } from "../../scripts/utils.mjs";

// Optional: set logging level of launcher to see its output.
// Install it using: npm i --save lighthouse-logger
// const log = require('lighthouse-logger');
// log.setLevel('info');

/**
* Launches a debugging instance of Chrome.
* @param {boolean=} headless True (default) launches Chrome in headless mode.
* False launches a full version of Chrome.
* @return {Promise<ChromeLauncher>}
*/
function launchChrome(headless = false) {
return chromeLauncher.launch({
// port: 9222, // Uncomment to force a specific port of your choice.
chromeFlags: [
"--window-size=412,732",
"--disable-gpu",
headless ? "--headless" : "",
],
});
}

// launchChrome().then(async (chrome) => {
// console.log(`Chrome debuggable on port: ${chrome.port}`);
// const version = await CDP.Version({ port: chrome.port });
// console.log(version["User-Agent"]);
// const protocol = await CDP({port: chrome.port});

// chrome.kill();
// });

(async function () {
const chrome = await launchChrome();
const protocol = await CDP({ port: chrome.port });

// Extract the DevTools protocol domains we need and enable them.
// See API docs: https://chromedevtools.github.io/devtools-protocol/
const { Page, Tracing } = protocol;
await Page.enable();

// const manifest = await Page.getAppManifest();

// if (manifest.url) {
// console.log("Manifest: " + manifest.url);
// console.log(manifest.data);
// } else {
// console.log("Site has no app manifest");
// }

// const categories = await Tracing.getCategories();
// console.log({ categories });

const config = {
tracing: {
traceConfig: {
includedCategories: [
"-*",
"devtools.timeline",
"v8.execute",
"disabled-by-default-devtools.timeline",
"disabled-by-default-devtools.timeline.frame",
"toplevel",
"blink.console",
"blink.user_timing",
"latencyInfo",
"disabled-by-default-devtools.timeline",
"disabled-by-default-devtools.timeline.frame",
"disabled-by-default-devtools.timeline.stack",
"disabled-by-default-devtools.screenshot",
"disabled-by-default-v8.cpu_profiler",
],
// excludedCategories: ["-*"],
},
},
cdpPort: 9222,
maxTimeout: 50000,
};

let data = [];

Tracing.dataCollected((evt) => {
data = data.concat(evt.value);
});

Tracing.tracingComplete((evt) => {
console.log({ evt });
});

// await Tracing.start(config.tracing);
await Tracing.start({
traceConfig: {
includedCategories: [
"disabled-by-default-devtools.timeline",
"disabled-by-default-devtools.timeline.frame",
],
excludedCategories: ["__metadata"],
},
});

Page.navigate({
url: "http://127.0.0.1:5173/Table/Table/DefaultTable?standalone",
});

Page.loadEventFired(async () => {
console.log("page loaded");
});

setTimeout(async () => {
console.log("timed out");
await Tracing.end();
await Tracing.tracingComplete();
protocol.close();
chrome.kill();
writeJsonFileFile(data, "./trace.json");
}, 1000);
})();
18 changes: 18 additions & 0 deletions vuu-ui/tools/chrome-devtools-protocol/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "chrome-devtools-protocol",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"chrome-launcher": "^0.15.2",
"chrome-remote-interface": "^0.32.2",
"devtools-protocol": "^0.0.1132318"
}
}
83 changes: 83 additions & 0 deletions vuu-ui/tools/chrome-devtools-protocol/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@types/node@*":
version "18.15.11"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f"
integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==

chrome-launcher@^0.15.2:
version "0.15.2"
resolved "https://registry.yarnpkg.com/chrome-launcher/-/chrome-launcher-0.15.2.tgz#4e6404e32200095fdce7f6a1e1004f9bd36fa5da"
integrity sha512-zdLEwNo3aUVzIhKhTtXfxhdvZhUghrnmkvcAq2NoDd+LeOHKf03H5jwZ8T/STsAlzyALkBVK552iaG1fGf1xVQ==
dependencies:
"@types/node" "*"
escape-string-regexp "^4.0.0"
is-wsl "^2.2.0"
lighthouse-logger "^1.0.0"

chrome-remote-interface@^0.32.2:
version "0.32.2"
resolved "https://registry.yarnpkg.com/chrome-remote-interface/-/chrome-remote-interface-0.32.2.tgz#4c494b9d074997b45d49137232df48a355189278"
integrity sha512-3UbFKtEmqApehPQnqdblcggx7KveQphEMKQmdJZsOguE9ylw2N2/9Z7arO7xS55+DBJ/hyP8RrayLt4MMdJvQg==
dependencies:
commander "2.11.x"
ws "^7.2.0"

commander@2.11.x:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
integrity sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==

debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
ms "2.0.0"

devtools-protocol@^0.0.1132318:
version "0.0.1132318"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.1132318.tgz#6754ce518f5787c16acb75cbce3d88e0928ac987"
integrity sha512-FcKBgop6cFQHCqotvp5ll5uul5q38yYcxrI6RIR5FXwiKuWGnxysLHg4jpPgvuJt4k5HaPmvnDS6F0PBTizKYA==

escape-string-regexp@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==

is-docker@^2.0.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==

is-wsl@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271"
integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==
dependencies:
is-docker "^2.0.0"

lighthouse-logger@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/lighthouse-logger/-/lighthouse-logger-1.3.0.tgz#ba6303e739307c4eee18f08249524e7dafd510db"
integrity sha512-BbqAKApLb9ywUli+0a+PcV04SyJ/N1q/8qgCNe6U97KbPCS1BTksEuHFLYdvc8DltuhfxIUBqDZsC0bBGtl3lA==
dependencies:
debug "^2.6.9"
marky "^1.2.2"

marky@^1.2.2:
version "1.2.5"
resolved "https://registry.yarnpkg.com/marky/-/marky-1.2.5.tgz#55796b688cbd72390d2d399eaaf1832c9413e3c0"
integrity sha512-q9JtQJKjpsVxCRVgQ+WapguSbKC3SQ5HEzFGPAJMStgh3QjCawp00UKv3MTTAArTmGmmPUvllHZoNbZ3gs0I+Q==

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==

ws@^7.2.0:
version "7.5.9"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==

0 comments on commit ad8947e

Please sign in to comment.