Skip to content

Commit 4e84dfa

Browse files
committed
bench: run GC and dump stats if --expose-gc is set
1 parent 7063575 commit 4e84dfa

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

benchmark/http_simple_auto.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,24 @@ server.listen(port, function () {
105105
cp.stderr.pipe(process.stderr);
106106
cp.on('exit', function() {
107107
server.close();
108+
process.nextTick(dump_mm_stats);
108109
});
109110
});
111+
112+
function dump_mm_stats() {
113+
if (typeof gc != 'function') return;
114+
115+
var before = process.memoryUsage();
116+
for (var i = 0; i < 10; ++i) gc();
117+
var after = process.memoryUsage();
118+
setTimeout(print_stats, 250); // give GC time to settle
119+
120+
function print_stats() {
121+
console.log('\nBEFORE / AFTER GC');
122+
['rss', 'heapTotal', 'heapUsed'].forEach(function(key) {
123+
var a = before[key] / (1024 * 1024);
124+
var b = after[key] / (1024 * 1024);
125+
console.log('%sM / %sM %s', a.toFixed(2), b.toFixed(2), key);
126+
});
127+
}
128+
}

0 commit comments

Comments
 (0)