Skip to content

Commit 839b349

Browse files
committed
log checkpoint sizes
1 parent 8f378b2 commit 839b349

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

apps/coordinator/src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createServer } from "node:http";
2+
import fs from "node:fs/promises";
23
import { $, type ExecaChildProcess } from "execa";
34
import { nanoid } from "nanoid";
45
import { Server } from "socket.io";
@@ -62,6 +63,36 @@ function isExecaChildProcess(maybeExeca: unknown): maybeExeca is Awaited<ExecaCh
6263
return typeof maybeExeca === "object" && maybeExeca !== null && "escapedCommand" in maybeExeca;
6364
}
6465

66+
async function getFileSize(filePath: string): Promise<number> {
67+
try {
68+
const stats = await fs.stat(filePath);
69+
return stats.size;
70+
} catch (error) {
71+
console.error("Error getting file size:", error);
72+
return -1;
73+
}
74+
}
75+
76+
async function getParsedFileSize(filePath: string) {
77+
const sizeInBytes = await getFileSize(filePath);
78+
79+
let message = `Size in bytes: ${sizeInBytes}`;
80+
81+
if (sizeInBytes > 1024 * 1024) {
82+
const sizeInMB = (sizeInBytes / 1024 / 1024).toFixed(2);
83+
message = `Size in MB (rounded): ${sizeInMB}`;
84+
} else if (sizeInBytes > 1024) {
85+
const sizeInKB = (sizeInBytes / 1024).toFixed(2);
86+
message = `Size in KB (rounded): ${sizeInKB}`;
87+
}
88+
89+
return {
90+
path: filePath,
91+
sizeInBytes,
92+
message,
93+
};
94+
}
95+
6596
class Checkpointer {
6697
#initialized = false;
6798
#canCheckpoint = false;
@@ -314,6 +345,10 @@ class Checkpointer {
314345
this.#logger.debug(await $$`crictl checkpoint --export=${exportLocation} ${containerId}`);
315346
const postCheckpoint = performance.now();
316347

348+
// Print checkpoint size
349+
const size = await getParsedFileSize(exportLocation);
350+
this.#logger.log("checkpoint archive created", { size, options });
351+
317352
// Create image from checkpoint
318353
const container = this.#logger.debug(await $$`buildah from scratch`);
319354
const postFrom = performance.now();

0 commit comments

Comments
 (0)