Add Module._findPath debug timing and count

This commit is contained in:
Kevin Sawicki
2014-10-08 18:58:40 -07:00
parent f0cffcbd84
commit 086be13ac4

View File

@@ -13,6 +13,7 @@ nativeModules = process.binding('natives')
cache =
debug: false
dependencies: {}
extensions: {}
folders: {}
ranges: {}
registered: false
@@ -106,6 +107,8 @@ getCachedModulePath = (relativePath, parentModule) ->
return
if cache.debug
cache.findPathCount = 0
cache.findPathTime = 0
cache.loadCount = 0
cache.requireTime = 0
global.moduleCache = cache
@@ -122,6 +125,15 @@ if cache.debug
cache.requireTime += Date.now() - startTime
exports
originalFindPath = Module._findPath
Module._findPath = (request, paths) ->
cacheKey = JSON.stringify({request, paths});
cache.findPathCount++ unless Module._pathCache[cacheKey]
startTime = Date.now()
foundPath = originalFindPath.apply(global, arguments)
cache.findPathTime += Date.now() - startTime
foundPath
exports.create = (modulePath) ->
modulePath = fs.realpathSync(modulePath)
metadataPath = path.join(modulePath, 'package.json')