From b54e39e86a8a2c5a17990eff8682e11fe8be403d Mon Sep 17 00:00:00 2001 From: Steve Krenek Date: Thu, 24 Jul 2014 15:48:14 -0500 Subject: [PATCH] Enable heap dump by sending a USR2 kill signal. --- .gitignore | 1 + lib/feather.js | 49 +++++++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 987bb97..4656f03 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ __restProxy.js *.swp *.lock-wscript *.wafpickle-7 +**/*.gz diff --git a/lib/feather.js b/lib/feather.js index d031230..44b5d21 100755 --- a/lib/feather.js +++ b/lib/feather.js @@ -25,7 +25,8 @@ var simpleId = require("./simple-id"), fs = require("fs"), nodePath = require('path'), Parser = require('./parser'), - Promise = require('./promise').Promise; + Promise = require('./promise').Promise, + heapdump = require('heapdump'); /** * @namespace serves as the root namespace for the entire framework @@ -45,7 +46,7 @@ var feather = module.exports = /** @lends feather */ { /** * Uses ns to get a config value at a path (or null if path not found) - * + * */ config: function(path) { return feather.ns(path, feather.appOptions, true); @@ -61,7 +62,7 @@ var feather = module.exports = /** @lends feather */ { */ mkdirpSync: util.mkdirpSync, - /** + /** * Parse signed cookies the way connect does. Convenience pass-through method. */ parseSignedCookie: util.parseSignedCookie, @@ -72,23 +73,23 @@ var feather = module.exports = /** @lends feather */ { parseSignedSessionId: function(signedSessionId) { return util.parseSignedCookie(cookie, feather.appOptions.connect.session.secret); }, - + /** * Flyweight empty Function * @memberOf feather */ emptyFn: function() {}, - + /** * Flyweight empty Object */ emptyObj: {}, - + /** * Flyweight empty String */ emptyString: "", - + /** * Flyweight empty Array */ @@ -115,12 +116,12 @@ var feather = module.exports = /** @lends feather */ { options.appRoot = options.appRoot || __dirname; options.publicRoot = options.publicRoot || nodePath.join(options.appRoot, "public"); options.port = options.port || 8080; - + //store a read-only copy of options in cache so that other modules //can inspect original options reliably var cacheToken = uuid(); cache.setItemReadOnly("feather-options", options, cacheToken); - //store an unprotected copy for convenience + //store an unprotected copy for convenience feather.appOptions = options; //add a getter that wraps feather.config for cases where we're passing options into modules that don't see feather object... @@ -160,7 +161,7 @@ var feather = module.exports = /** @lends feather */ { this.onceState("ready", function() { process.on('SIGINT', feather.shutdown); process.on('SIGTERM', feather.shutdown); - }); + }); //go right to the "loading state" since that is exactly what we're doing at the time this instance is created return this.states.loading; } @@ -199,7 +200,7 @@ var feather = module.exports = /** @lends feather */ { } cache.setItem("feather-logger", feather.logger); - //handle uncaught exceptions + //handle uncaught exceptions process.on("uncaughtException", function(err) { var message = err; if (err.stack) { @@ -317,12 +318,12 @@ var feather = module.exports = /** @lends feather */ { } } } - }); + }); + + - - }, - + /** * Shuts down the server cleanly, but not before it is ready for requests. */ @@ -358,7 +359,7 @@ var feather = module.exports = /** @lends feather */ { feather.logger.error({message:"feather server cannot shut down. feather.stateMachine is undefined", category:"feather.server", immediately:true}); } }, // end shutdown. - + /** * This function is used to start the feather engine. */ @@ -367,13 +368,17 @@ var feather = module.exports = /** @lends feather */ { if (options.heapdump) { this.heapTimer = setInterval(function() { - require('heapdump').writeSnapshot('logs/' + new Date().toISOString().replace(/[:\.]/g, '-') + '.heapsnapshot'); + heapdump.writeSnapshot('logs/' + new Date().toISOString().replace(/[:\.]/g, '-') + '.heapsnapshot'); }, parseInt(options.heapdump) * 1000); } - + feather.init(options, cb); }, + heapDump: function() { + heapdump.writeSnapshot('logs/' + new Date().toISOString().replace(/[:\.]/g, '-') + '.heapsnapshot'); + }, + /** * @namespace Root namespace for data class definitions and services * @name feather.data @@ -421,15 +426,15 @@ var feather = module.exports = /** @lends feather */ { * @namespace Root namespace for Finite State Machine class definitions and services * @name feather.fsm */ - fsm: { + fsm: { /** * Framework access to {@link FiniteStateMachine} class. - */ + */ FiniteStateMachine: FSM - }, + }, event: { - EventPublisher: EventPublisher, + EventPublisher: EventPublisher, RedisEventPublisher: RedisEventPublisher },