1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Fix for mv3 performance stats (#15321)

This commit is contained in:
Jyoti Puri 2022-07-22 16:24:14 +05:30 committed by GitHub
parent 2e6f579ee5
commit be47d78475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 144 deletions

View File

@ -11,13 +11,13 @@
"setup:postinstall": "yarn patch-package && yarn allow-scripts",
"start": "yarn build:dev dev --apply-lavamoat=false",
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=true",
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false",
"dist": "yarn build prod",
"build": "yarn lavamoat:build",
"build:dev": "node development/build/index.js",
"start:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn build testDev",
"benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/benchmark.js",
"mv3:stats:chrome": "SELENIUM_BROWSER=chrome ENABLE_MV3=true node test/e2e/mv3/stats.js",
"mv3:stats:chrome": "SELENIUM_BROWSER=chrome ENABLE_MV3=true node test/e2e/mv3-perf-stats/index.js",
"benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js",
"build:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn build test",
"build:test:flask": "yarn build test --build-type flask",

View File

@ -1,142 +0,0 @@
#!/usr/bin/env node
/* eslint-disable node/shebang */
const path = require('path');
const { promises: fs, constants: fsConstants } = require('fs');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const { exitWithError } = require('../../../development/lib/exit-with-error');
const { withFixtures, tinyDelayMs } = require('../helpers');
async function measurePage() {
let metrics;
try {
await withFixtures({ fixtures: 'imported-account' }, async ({ driver }) => {
await driver.delay(tinyDelayMs);
await driver.navigate();
await driver.findElement('#password');
await driver.delay(1000);
const logs = await driver.checkBrowserForLavamoatLogs();
let logString = '';
let inObject = false;
const parsedLogs = [];
logs.forEach((log) => {
if (log.indexOf('"version": 1') >= 0) {
logString += log;
parsedLogs.push(`{${logString}}`);
logString = '';
inObject = false;
} else if (inObject) {
logString += log;
} else if (
log.search(/"name": ".*app\/scripts\/background.js",/u) >= 0 ||
log.search(/"name": ".*app\/scripts\/ui.js",/u) >= 0 ||
log.search(/"name": "Total"/u) >= 0
) {
logString += log;
inObject = true;
}
});
metrics = parsedLogs.map((pl) => JSON.parse(pl));
});
} catch (error) {
// do nothing
}
return metrics;
}
async function profilePageLoad() {
const results = await measurePage();
const metrics = {};
metrics['background.js'] = results[0];
metrics['ui.js'] = results[1];
metrics.loadTime = results[2];
return metrics;
}
async function isWritable(directory) {
try {
await fs.access(directory, fsConstants.W_OK);
return true;
} catch (error) {
if (error.code !== 'EACCES') {
throw error;
}
return false;
}
}
async function getFirstParentDirectoryThatExists(directory) {
let nextDirectory = directory;
for (;;) {
try {
await fs.access(nextDirectory, fsConstants.F_OK);
return nextDirectory;
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
} else if (nextDirectory === path.dirname(nextDirectory)) {
throw new Error('Failed to find parent directory that exists');
}
nextDirectory = path.dirname(nextDirectory);
}
}
}
async function main() {
const { argv } = yargs(hideBin(process.argv)).usage(
'$0 [options]',
'Run a page load benchmark',
(_yargs) =>
_yargs.option('out', {
description:
'Output filename. Output printed to STDOUT of this is omitted.',
type: 'string',
normalize: true,
}),
);
const { out } = argv;
let outputDirectory;
let existingParentDirectory;
if (out) {
outputDirectory = path.dirname(out);
existingParentDirectory = await getFirstParentDirectoryThatExists(
outputDirectory,
);
if (!(await isWritable(existingParentDirectory))) {
throw new Error('Specified output file directory is not writable');
}
}
const results = await profilePageLoad();
if (out) {
if (outputDirectory !== existingParentDirectory) {
await fs.mkdir(outputDirectory, { recursive: true });
}
await fs.writeFile(
path.join(out, 'background.json'),
JSON.stringify(results['background.js'], null, 2),
);
await fs.writeFile(
path.join(out, 'ui.json'),
JSON.stringify(results['ui.js'], null, 2),
);
} else {
console.log(JSON.stringify(results, null, 2));
}
}
main().catch((error) => {
exitWithError(error);
});