Skip to content

Commit 327062f

Browse files
dckckriskowal
authored andcommitted
feat(xsnap): meter add/remove on map, set
1 parent f649ff7 commit 327062f

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

packages/xsnap/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/** The version identifier for our meter type.
44
* TODO Bump this whenever there's a change to metering semantics.
55
*/
6-
export const METER_TYPE = 'xs-meter-4';
6+
export const METER_TYPE = 'xs-meter-5';
77

88
export const ExitCode = {
99
E_UNKNOWN_ERROR: -1,

packages/xsnap/src/xsnap.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -1400,15 +1400,26 @@ static char* fxReadNetStringError(int code)
14001400

14011401
static int fxWriteOkay(FILE* outStream, xsUnsignedValue meterIndex, txMachine *the, char* buf, size_t length)
14021402
{
1403-
char fmt[] = ".{\"compute\":%u,\"allocate\":%u,\"allocateChunksCalls\":%u,\"allocateSlotsCalls\":%u,\"garbageCollectionCount\":%u}\1";
1403+
char fmt[] = ("." // OK
1404+
"{"
1405+
"\"compute\":%u,"
1406+
"\"allocate\":%u,"
1407+
"\"allocateChunksCalls\":%u,"
1408+
"\"allocateSlotsCalls\":%u,"
1409+
"\"garbageCollectionCount\":%u,"
1410+
"\"mapSetAddCount\":%u,"
1411+
"\"mapSetRemoveCount\":%u}"
1412+
"\1" // separate meter info from result
1413+
);
14041414
char numeral64[] = "12345678901234567890"; // big enough for 64bit numeral
1405-
char prefix[8 + sizeof fmt + 4 * sizeof numeral64];
1415+
char prefix[8 + sizeof fmt + 7 * sizeof numeral64];
14061416
// TODO: fxCollect counter
14071417
// Prepend the meter usage to the reply.
14081418
snprintf(prefix, sizeof(prefix) - 1, fmt,
14091419
meterIndex, the->allocatedSpace,
14101420
the->allocateChunksCallCount, the->allocateSlotsCallCount,
1411-
the->garbageCollectionCount);
1421+
the->garbageCollectionCount,
1422+
the->mapSetAddCount, the->mapSetRemoveCount);
14121423
return fxWriteNetString(outStream, prefix, buf, length);
14131424
}
14141425

packages/xsnap/src/xsnap.h

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
txUnsigned allocateChunksCallCount; \
7373
txUnsigned allocateSlotsCallCount; \
7474
txUnsigned garbageCollectionCount; \
75+
txUnsigned mapSetAddCount; \
76+
txUnsigned mapSetRemoveCount; \
7577
int promiseJobs; \
7678
void* timerJobs; \
7779
void* waiterCondition; \

packages/xsnap/test/test-xsnap.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,21 @@ test('meter details', async t => {
512512
t.teardown(() => vat.terminate());
513513
const result = await vat.evaluate(`
514514
let m = new Map();
515+
let s1 = new Set();
515516
for (ix = 0; ix < 20000; ix++) {
516517
m.set(ix, 'garbage');
517-
// m.delete(m);
518+
s1.add(ix);
519+
}
520+
for (ix = 0; ix < 20000; ix++) {
521+
m.delete(ix);
522+
s1.delete(ix);
518523
}
519524
`);
520525
const {
521526
meterUsage: { meterType, ...meters },
522527
} = result;
523528
t.log(meters);
524-
t.is(meterType, 'xs-meter-4');
529+
t.is(meterType, 'xs-meter-5');
525530
const { entries, fromEntries } = Object;
526531
t.deepEqual(
527532
{
@@ -530,6 +535,8 @@ test('meter details', async t => {
530535
allocateChunksCalls: 'number',
531536
allocateSlotsCalls: 'number',
532537
garbageCollectionCount: 'number',
538+
mapSetAddCount: 'number',
539+
mapSetRemoveCount: 'number',
533540
},
534541
fromEntries(entries(meters).map(([p, v]) => [p, typeof v])),
535542
);

0 commit comments

Comments
 (0)