Skip to content

Commit 52aa986

Browse files
committed
Check size delta before vs. after hierarchical GC for approximate cleanup size
1 parent a7d9b99 commit 52aa986

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/tmp.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,8 @@ function setLogger(logger) {
698698

699699
async function withSubdir(prefix, fn, options) {
700700
const ctx = prefixStackStorage.getStore();
701-
const tmpDir = path.resolve(
702-
ctx ? ctx.value : _getTmpDir(),
703-
prefix
704-
);
701+
const base = ctx ? ctx.value : _getTmpDir();
702+
const tmpDir = path.resolve(base, prefix);
705703
const logTags = {
706704
...(options && options.logTags ? options.logTags : {}),
707705
path: tmpDir
@@ -716,9 +714,18 @@ async function withSubdir(prefix, fn, options) {
716714
const cleanup = async () => {
717715
_logger.info(logTags,"lib-tmp.gc.start");
718716
const t0 = Date.now();
717+
const stat0 = await fsp.statfs(base);
719718
try {
720719
await fsp.rm(tmpDir, { force: true, recursive: true, maxRetries: 5 });
721-
_logger.info({ ...logTags, duration: Date.now() - t0 }, "lib-tmp.gc.end");
720+
const stat1 = await fsp.statfs(base);
721+
_logger.info(
722+
{
723+
...logTags,
724+
duration: Date.now() - t0,
725+
size: (stat1.bavail - stat0.bavail) * stat0.bsize
726+
},
727+
"lib-tmp.gc.end"
728+
);
722729
} catch (error) {
723730
_logger.info({ ...logTags, duration: Date.now() - t0, error }, "lib-tmp.gc.error");
724731
}

0 commit comments

Comments
 (0)