diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-02 09:47:11 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-02 09:47:11 +0200 |
commit | d467888d6aacde1a29c7eebfab6b91a0c586d6ca (patch) | |
tree | d5a11ce92b8f7620d5b33f849f8c53cddba05bc0 /lib | |
parent | eb4631156153c6e656e41761a6330aa0e2beac28 (diff) | |
download | gitbook-d467888d6aacde1a29c7eebfab6b91a0c586d6ca.zip gitbook-d467888d6aacde1a29c7eebfab6b91a0c586d6ca.tar.gz gitbook-d467888d6aacde1a29c7eebfab6b91a0c586d6ca.tar.bz2 |
Improve timing debug
Diffstat (limited to 'lib')
-rw-r--r-- | lib/templating/render.js | 18 | ||||
-rw-r--r-- | lib/utils/timing.js | 11 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/templating/render.js b/lib/templating/render.js index bf21cfe..22c0dc4 100644 --- a/lib/templating/render.js +++ b/lib/templating/render.js @@ -1,4 +1,5 @@ var Promise = require('../utils/promise'); +var timing = require('../utils/timing'); var replaceShortcuts = require('./replaceShortcuts'); @@ -17,13 +18,16 @@ function renderTemplate(engine, filePath, content, context) { content = replaceShortcuts(engine, filePath, content); - return Promise.nfcall( - env.renderString.bind(env), - content, - context, - { - path: filePath - } + return timing.measure( + 'template.render', + Promise.nfcall( + env.renderString.bind(env), + content, + context, + { + path: filePath + } + ) ); } diff --git a/lib/utils/timing.js b/lib/utils/timing.js index 9903af2..e6b0323 100644 --- a/lib/utils/timing.js +++ b/lib/utils/timing.js @@ -75,11 +75,12 @@ function dump(logger) { return timer.total; }) .forEach(function(timer) { - logger.debug.ln('Timer "' + timer.type + '" (' + timer.count + ' times) :'); - logger.debug.ln(prefix + 'Total: ' + time(timer.total)); - logger.debug.ln(prefix + 'Average: ' + time(timer.total / timer.count)); - logger.debug.ln(prefix + 'Min: ' + time(timer.min)); - logger.debug.ln(prefix + 'Max: ' + time(timer.max)); + var percent = (timer.total * 100) / totalDuration; + + + logger.debug.ln((percent.toFixed(1)) + '% of time spent in "' + timer.type + '" (' + timer.count + ' times) :'); + logger.debug.ln(prefix + 'Total: ' + time(timer.total)+ ' | Average: ' + time(timer.total / timer.count)); + logger.debug.ln(prefix + 'Min: ' + time(timer.min) + ' | Max: ' + time(timer.max)); logger.debug.ln('---------------------------'); }); |