Skip to content

Commit

Permalink
add computrons to transcript results, when available
Browse files Browse the repository at this point in the history
Any delivery that results in `metering.compute` (i.e. anything to an
xsnap worker) will record that number as `metering.computrons` in the
transcript delivery results.

Our standard replay code doesn't do anything with this:
`replayTranscript` ignores the old results. But it gives us something
to compare against during external/diagnostic replays.
  • Loading branch information
warner committed Apr 26, 2023
1 parent 4b71144 commit 719ee82
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function recordSyscalls(origHandler) {
// TODO add metering computrons to results
/** @type {TranscriptDeliveryResults} */
const tdr = { status: deliveryResult[0] };
if (deliveryResult[0] === 'ok') {
const usage = deliveryResult[2];
if (usage) {
tdr.metering = { computrons: usage.compute };
}
}
const transcriptEntry = { d: vd, sc: syscalls, r: tdr };
return transcriptEntry;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/types-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export {};
* } TranscriptDelivery
* @typedef { { s: VatSyscallObject, r: VatSyscallResult } } TranscriptSyscall
* @typedef { { status: string, snapshotID: string } } TranscriptDeliverySaveSnapshotResults
* @typedef { { status: string } } TranscriptDeliveryGenericResults
* @typedef { { status: string, metering?: { computrons: number } } } TranscriptDeliveryGenericResults
* @typedef { TranscriptDeliverySaveSnapshotResults | TranscriptDeliveryGenericResults } TranscriptDeliveryResults
* @typedef { { d: TranscriptDelivery, sc: TranscriptSyscall[], r: TranscriptDeliveryResults } } TranscriptEntry
*
Expand Down
21 changes: 20 additions & 1 deletion packages/SwingSet/test/transcript/test-transcript-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ test('transcript of new vats', async t => {
},
vats: {
static1: { bundleName: 'bundle' },
static2: { bundleName: 'bundle' },
static2: {
bundleName: 'bundle',
creationOptions: { managerType: 'local' },
},
},
};
const kernelStorage = initSwingStore().kernelStorage;
Expand Down Expand Up @@ -70,6 +73,11 @@ test('transcript of new vats', async t => {
['initialize-worker', 'startVat'],
);

// static2 is always managerType='local', so it should never have 'metering'
// in the transcript results
const teStartVat = t2[1];
t.falsy(teStartVat.r.metering);

const kpid = c.queueToVatRoot('static1', 'create', [], 'panic');
await c.run();
t.is(c.kpStatus(kpid), 'fulfilled');
Expand Down Expand Up @@ -220,6 +228,12 @@ test('transcript spans', async t => {
t.deepEqual(curSummary(), [].concat(load, boot, notify));
t.deepEqual(fullSummary(), expectedFull);

// all delivery events should record computrons
const teStartVat = old(0)[1];
t.is(teStartVat.d[0], 'startVat');
t.truthy(teStartVat.r.metering);
t.is(typeof teStartVat.r.metering.computrons, 'number');

// do some deliveries to trigger an XS heap snapshot event, creating
// a new span
const doSomeNothing = async () => {
Expand All @@ -236,6 +250,11 @@ test('transcript spans', async t => {
t.deepEqual(curSummary(), [].concat(load, boot, notify, msgN(1)));
t.deepEqual(fullSummary(), expectedFull);

const teNothing1 = cur().slice(-1)[0];
t.is(teNothing1.d[0], 'message');
t.truthy(teNothing1.r.metering);
t.is(typeof teNothing1.r.metering.computrons, 'number');

c = await restart();
t.deepEqual(curSummary(), [].concat(load, boot, notify, msgN(1)));

Expand Down

0 comments on commit 719ee82

Please sign in to comment.