Created
December 6, 2012 18:47
-
-
Save isaacs/4227004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/module.js b/lib/module.js | |
index 6130394..80559f4 100644 | |
--- a/lib/module.js | |
+++ b/lib/module.js | |
@@ -25,6 +25,7 @@ var runInThisContext = Script.runInThisContext; | |
var runInNewContext = Script.runInNewContext; | |
var assert = require('assert').ok; | |
+var timeRequire = +process.env.NODE_TIME_REQUIRE; | |
// If obj.hasOwnProperty has been overridden, then calling | |
// obj.hasOwnProperty(prop) will break. | |
@@ -359,7 +360,15 @@ Module.prototype.load = function(filename) { | |
Module.prototype.require = function(path) { | |
- return Module._load(path, this); | |
+ if (timeRequire) { | |
+ var start = process.hrtime(); | |
+ } | |
+ var ret = Module._load(path, this); | |
+ if (timeRequire) { | |
+ var end = process.hrtime(start); | |
+ console.error(this.filename, path, end); | |
+ } | |
+ return ret; | |
}; | |
would be pretty cool if you could enable this or similar with NODE_DEBUG
@visionmedia Agreed. My only hesitation in landing a patch like this is that people get all excited and want to put a bunch of bullshit into the module system, and it's easier to say no if I also deny my own feature requests. But maybe something like NODE_DEBUG=module
and match the pattern that we have in most of the other internal modules, that'd be nice.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or monkey-patch:
but of course that'll only print stats for modules that have not been loaded yet.