Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SwingSet): Report vat snapshot size delta on save #10935

Merged
merged 9 commits into from
Feb 13, 2025
20 changes: 1 addition & 19 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,7 @@ export function makeVatKeeper(
restartWorker,
);

const {
hash: snapshotID,
uncompressedSize,
dbSaveSeconds,
compressedSize,
compressSeconds,
} = info;
const { hash: snapshotID } = info;

// push a save-snapshot transcript entry
addToTranscript(makeSaveSnapshotItem(snapshotID));
Expand All @@ -695,18 +689,6 @@ export function makeVatKeeper(
// always starts with an initialize-worker or load-snapshot
// pseudo-delivery
addToTranscript(makeLoadSnapshotItem(snapshotID));

kernelSlog.write({
type: 'heap-snapshot-save',
vatID,
snapshotID,
uncompressedSize,
dbSaveSeconds,
compressedSize,
compressSeconds,
endPosition,
restartWorker,
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ export function makeXsSubprocessFactory({

const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
const snapshotInfo = vatKeeper.getSnapshotInfo();
let uncompressedSizeLoaded = null;
if (snapshotInfo) {
kernelSlog.write({ type: 'heap-snapshot-load', vatID, ...snapshotInfo });
uncompressedSizeLoaded = snapshotInfo.uncompressedSize;
}

// `startXSnap` adds `nameDisplayArg` as a dummy argument so that 'ps'
Expand Down Expand Up @@ -240,9 +242,31 @@ export function makeXsSubprocessFactory({
async function makeSnapshot(snapPos, snapStore, restartWorker) {
const snapshotDescription = `${vatID}-${snapPos}`;
const snapshotStream = worker.makeSnapshotStream(snapshotDescription);
const saveSnapshot = async saveStream => {
const results = await snapStore.saveSnapshot(
vatID,
snapPos,
saveStream,
);
const { hash: snapshotID, ...metrics } = results;
const uncompressedSizeDelta =
uncompressedSizeLoaded &&
metrics.uncompressedSize - uncompressedSizeLoaded;
uncompressedSizeLoaded = results.uncompressedSize;
kernelSlog.write({
type: 'heap-snapshot-save',
vatID,
snapshotID,
endPosition: snapPos,
...metrics,
uncompressedSizeDelta,
restartWorker,
siarhei-agoric marked this conversation as resolved.
Show resolved Hide resolved
});
return results;
};

if (!restartWorker) {
return snapStore.saveSnapshot(vatID, snapPos, snapshotStream);
return saveSnapshot(snapshotStream);
}

/** @type {AsyncGenerator<Uint8Array, void, void>[]} */
Expand All @@ -268,7 +292,7 @@ export function makeXsSubprocessFactory({
snapshotDescription,
},
}),
snapStore.saveSnapshot(vatID, snapPos, snapStoreSaveStream),
saveSnapshot(snapStoreSaveStream),
]);
await closeP;

Expand Down
Loading