Skip to content

Commit

Permalink
feat: add slog file output to benchmark tool
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Oct 12, 2023
1 parent ac08b3e commit 1995bde
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/benchmark/benchmark/benchmark-vault-adjust.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ bench.addBenchmark('adjust vault balance', {
},
});

await bench.run('vault-adjust');
await bench.run();
2 changes: 1 addition & 1 deletion packages/benchmark/benchmark/benchmark-vault-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ bench.addBenchmark('open vault', {
},
});

await bench.run('vault-open');
await bench.run();
18 changes: 9 additions & 9 deletions packages/benchmark/doc/benchmarkerator.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ labelled in Ava), and `benchmark` is an object describing the benchmark itself
After defining one or more benchmarks with `addBenchmark` you must then end by
invoking:

```await bench.run(name);```

where `name` is a string naming the benchmark run for purposes of error and
result reporting.
```await bench.run();```

### The `Benchmark` object

Expand Down Expand Up @@ -146,7 +143,8 @@ The supported command line options are:
| `-v`<br/>`--verbose` | Enable verbose output |
| `--vat-type TYPE` | Use the specified vat manager type rather than the default `xs-worker` |
| `-l`<br/>`--local` | Shorthand for `--vat-type local` (vats run in the same process as the kernel; less realistic than `xs-worker` but much faster and easier to debug) |
| `-d`<br/>`--dump` | Output JSON-formated benchmark data to a file |
| `-d PATH`<br/>`--dump PATH` | Output JSON-formated benchmark data into _PATH_ |
| `-s PATH`<br/>`--slot PATH` | Output a log file into _PATH_ |
| `-h`<br/>`--help` | Output this helpful usage information and then exit |

An optional `--` flag ends the options list. Any remaining command line
Expand All @@ -159,11 +157,13 @@ Timing results and other collected metrics are output to _stdout_. Two batches
of information are provided: one for the setup phase and one for the benchmark
rounds themselves (in aggregate).

In addition, if you specify the `--dump` command line option, a JSON-formatted
(i.e., machine readable) version of this same data will be output to the file
`benchmark-NAME.json` in the current working directory (where _NAME_ is the name
that you provided as the argument to `bench.run`).
If you specify the `--dump FILEPATH` command line option, a JSON-formatted
(i.e., machine readable) version of this same data will be output to the
indicated file.

Output results include execution times (according to Node's nanosecond clock),
crank counts, and the various kernel resource usage data reported by
`controller.getStats()`.

In addition, if you specify the `--slog FILEPATH` command line option, a
SwingSet slog file for the run will be output to the file indicated.
31 changes: 17 additions & 14 deletions packages/benchmark/src/benchmarkerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import { makeWalletFactoryDriver } from '@agoric/boot/tools/drivers.ts';
*
* @typedef {{
* addBenchmark: (title: string, benchmark: Benchmark) => void,
* run: (name?: string) => Promise<void>,
* run: () => Promise<void>,
* }} Benchmarkerator
*/

Expand All @@ -117,7 +117,8 @@ const argv = process.argv.slice(2);
let commandLineRounds;
let verbose = false;
let help = false;
let dump = false;
let dumpFile;
let slogFile;
/** @type ManagerType */
let defaultManagerType = 'xs-worker';
const options = {};
Expand Down Expand Up @@ -148,8 +149,11 @@ FLAGS may be:
--local - shorthand for '--vat-type local'
(less realistic perf numbers but faster and easier to debug)
-d
--dump - output JSON-formatted benchmark data to a file
-s PATH
--slog PATH - output a slog file into PATH
-d PATH
--dump PATH - output JSON-formatted benchmark data into PATH
-h
--help - output this helpful usage information and then exit
Expand Down Expand Up @@ -184,7 +188,7 @@ while (argv[0] && stillScanningArgs) {
break;
case '-d':
case '--dump':
dump = true;
dumpFile = argv.shift();
break;
case '--vat-type': {
const type = argv.shift();
Expand All @@ -209,6 +213,10 @@ while (argv[0] && stillScanningArgs) {
case '--help':
help = true;
break;
case '-s':
case '--slog':
slogFile = argv.shift();
break;
case '-o':
case '--option': {
const optionName = argv.shift();
Expand Down Expand Up @@ -433,6 +441,7 @@ export const makeBenchmarkerator = async () => {
const swingsetTestKit = await makeSwingsetTestKit(console.log, undefined, {
defaultManagerType,
verbose,
slogFile,
});
const {
runUtils,
Expand Down Expand Up @@ -526,11 +535,8 @@ export const makeBenchmarkerator = async () => {

/**
* Execute the benchmarks.
*
* @param {string} [name] - string identifying the set of benchmarks being
* executed. Used for logging and labeling the output data.
*/
const run = async (name = 'benchmark') => {
const run = async () => {
/** @type {object} */
const benchmarkContext = { ...context };
await null;
Expand Down Expand Up @@ -575,11 +581,8 @@ export const makeBenchmarkerator = async () => {
}
await eventLoopIteration();
await shutdown();
if (dump) {
fs.writeFileSync(
`benchmark-${name}.json`,
JSON.stringify(benchmarkReport, null, 2),
);
if (dumpFile) {
fs.writeFileSync(dumpFile, JSON.stringify(benchmarkReport, null, 2));
}
};

Expand Down
1 change: 1 addition & 0 deletions packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@agoric/kmarshal": "^0.1.0",
"@agoric/swing-store": "^0.9.1",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/telemetry": "^0.6.2",
"@agoric/time": "^0.3.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/vats": "^0.15.1",
Expand Down
16 changes: 15 additions & 1 deletion packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { initSwingStore } from '@agoric/swing-store';
import { loadSwingsetConfigFile } from '@agoric/swingset-vat';
import { krefOf } from '@agoric/kmarshal';
import { makeSlogSender } from '@agoric/telemetry';
import { TimeMath, Timestamp } from '@agoric/time';
import '@agoric/vats/exported.js';
import {
Expand Down Expand Up @@ -238,6 +239,7 @@ export const matchIter = (t: AvaT, iter, valueRef) => {
* @param [options.configSpecifier] bootstrap config specifier
* @param [options.storage]
* @param [options.verbose]
* @param [options.slogFile]
* @param [options.defaultManagerType]
*/
export const makeSwingsetTestKit = async (
Expand All @@ -247,6 +249,7 @@ export const makeSwingsetTestKit = async (
configSpecifier = undefined as string | undefined,
storage = makeFakeStorageKit('bootstrapTests'),
verbose = false,
slogFile = undefined as string | undefined,
defaultManagerType = 'local' as ManagerType,
} = {},
) => {
Expand Down Expand Up @@ -338,14 +341,25 @@ export const makeSwingsetTestKit = async (
}
};

let slogSender;
if (slogFile) {
slogSender = await makeSlogSender({
stateDir: '.',
env: {
...process.env,
SLOGFILE: slogFile,
SLOGSENDER: '',
},
});
}
const { controller, timer } = await buildSwingset(
new Map(),
bridgeOutbound,
kernelStorage,
configPath,
[],
{},
{ debugName: 'TESTBOOT', verbose },
{ debugName: 'TESTBOOT', verbose, slogSender },
);
console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset');

Expand Down

0 comments on commit 1995bde

Please sign in to comment.