Skip to content

Commit

Permalink
Add profiling option to the benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Mar 30, 2021
1 parent 2e41d06 commit 0431652
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ graph.svg
.history
*.tgz
benchmarks/*.json
benchmarks/*.brs
benchmarks/*.brs
isolate-*
v8*.log
35 changes: 33 additions & 2 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

const fsExtra = require('fs-extra');
const syncRequest = require('sync-request');
const path = require('path');
const { spawnSync, execSync } = require('child_process');
const yargs = require('yargs');
const readline = require('readline');
const rimraf = require('rimraf');
const glob = require('glob');

class Runner {
constructor(options) {
Expand All @@ -13,6 +14,7 @@ class Runner {
this.noprepare = options.noprepare;
this.project = options.project;
this.quick = options.quick;
this.profile = options.profile;
}
run() {
this.downloadFiles();
Expand Down Expand Up @@ -120,17 +122,40 @@ class Runner {
return curr.length > acc ? curr.length : acc;
}, 0);

if (this.profile) {
console.log('Deleting previous profile runs\n');
rimraf.sync(path.join(__dirname, 'isolate-*'));
}

//run one target at a time
for (const target of this.targets) {
//run each of the versions within this target
for (let versionIndex = 0; versionIndex < this.versions.length; versionIndex++) {
const version = this.versions[versionIndex];
process.stdout.write(`Benchmarking ${target}@${version}`);
const alias = `brighterscript${versionIndex + 1}`;

//get the list of current profiler logs
const beforeLogs = glob.sync('isolate-*.log', {
cwd: __dirname
});

execSync(`node target-runner.js "${version}" "${maxVersionLength}" "${target}" "${maxTargetLength}" "brighterscript${versionIndex + 1}" "${this.project}" "${this.quick}"`, {
execSync(`node ${this.profile ? '--prof ' : ''}target-runner.js "${version}" "${maxVersionLength}" "${target}" "${maxTargetLength}" "${alias}" "${this.project}" "${this.quick}"`, {
cwd: path.join(__dirname),
stdio: 'inherit'
});
if (this.profile) {
const logFile = glob.sync('isolate-*.log', {
cwd: __dirname
}).filter(x => !beforeLogs.includes(x))[0];

execSync(`node --prof-process ${logFile} > "${logFile.replace(/\.log$/, '')} (${target} ${version}).txt"`, {
cwd: path.join(__dirname)
});
execSync(`node --prof-process --preprocess -j ${logFile} > "${logFile.replace(/\.log$/, '')} (${target} ${version}).json"`, {
cwd: path.join(__dirname)
});
}
}
//print a newline to separate the targets
console.log('');
Expand Down Expand Up @@ -171,6 +196,12 @@ let options = yargs
description: 'run a quick benchmark rather than the lower more precise version',
default: false
})
.option('profile', {
type: 'boolean',
alias: 'prof',
description: 'Enable nodejs profiling of each benchmark run',
default: false
})
.strict()
.check(argv => {
const idx = argv.versions.indexOf('latest');
Expand Down

0 comments on commit 0431652

Please sign in to comment.