This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

bench: run GC and dump stats if --expose-gc is set

  • Loading branch information...
1 parent 7063575 commit 4e84dfa6830336131a63993dcf2119b3edcb0f37 @bnoordhuis bnoordhuis committed Apr 27, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 benchmark/http_simple_auto.js
@@ -105,5 +105,24 @@ server.listen(port, function () {
cp.stderr.pipe(process.stderr);
cp.on('exit', function() {
server.close();
+ process.nextTick(dump_mm_stats);
});
});
+
+function dump_mm_stats() {
+ if (typeof gc != 'function') return;
+
+ var before = process.memoryUsage();
+ for (var i = 0; i < 10; ++i) gc();
+ var after = process.memoryUsage();
+ setTimeout(print_stats, 250); // give GC time to settle
+
+ function print_stats() {
+ console.log('\nBEFORE / AFTER GC');
+ ['rss', 'heapTotal', 'heapUsed'].forEach(function(key) {
+ var a = before[key] / (1024 * 1024);
+ var b = after[key] / (1024 * 1024);
+ console.log('%sM / %sM %s', a.toFixed(2), b.toFixed(2), key);
+ });
+ }
+}

0 comments on commit 4e84dfa

Please sign in to comment.