Skip to content

Commit db9bf88

Browse files
authored
feat(cli-integ): optionally print memory usage on test start/finish (#419)
To be able to do (basic) memory analysis on different platforms when needed. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent c05e058 commit db9bf88

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/@aws-cdk-testing/cli-integ/lib/integ-test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function integTest(
4343

4444
const now = Date.now();
4545
process.stderr.write(`[INTEG TEST::${name}] Starting (pid ${process.pid})...\n`);
46+
maybePrintMemoryUsage(name);
4647
try {
4748
if (FAIL_FAST && failed) {
4849
throw new Error('FAIL_FAST requested and currently failing. Stopping test early.');
@@ -102,6 +103,7 @@ export function integTest(
102103
} finally {
103104
const duration = Date.now() - now;
104105
process.stderr.write(`[INTEG TEST::${name}] Done (${duration} ms).\n`);
106+
maybePrintMemoryUsage(name);
105107
}
106108
}, timeoutMillis);
107109
}
@@ -110,6 +112,18 @@ function shouldSkip(testName: string) {
110112
return SKIP_TESTS.includes(testName);
111113
}
112114

115+
function maybePrintMemoryUsage(testName: string) {
116+
if (process.env.INTEG_MEMORY_DEBUG !== 'true') {
117+
return;
118+
}
119+
const memoryUsage = process.memoryUsage() as any;
120+
const report: any = {};
121+
for (const [key, value] of Object.entries(memoryUsage)) {
122+
report[key] = `${Math.round(value as number / 1024 / 1024)} MB`;
123+
}
124+
process.stderr.write(`[INTEG TEST::${testName}] Memory Usage: ${JSON.stringify(report)}`);
125+
}
126+
113127
export function randomString() {
114128
// Crazy
115129
return Math.random().toString(36).replace(/[^a-z0-9]+/g, '');

0 commit comments

Comments
 (0)