From ba3add39bb6169675b58a1261588761c827c3798 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Thu, 27 Feb 2014 22:23:53 +0100 Subject: [PATCH] Emit "milestone" event for certain metrics --- core/modules/requestsMonitor/requestsMonitor.js | 10 +++------- lib/index.js | 13 ++++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/modules/requestsMonitor/requestsMonitor.js b/core/modules/requestsMonitor/requestsMonitor.js index 10033fcb0..afb2b9f20 100644 --- a/core/modules/requestsMonitor/requestsMonitor.js +++ b/core/modules/requestsMonitor/requestsMonitor.js @@ -275,17 +275,13 @@ exports.module = function(phantomas) { }); // TTFB / TTLB metrics - var ttfbMeasured = false, - ipc = new (require('../../ipc'))('milestone'); + var ttfbMeasured = false; phantomas.on('recv', function(entry, res) { // check the first response which is not a redirect (issue #74) if (!ttfbMeasured && !entry.isRedirect) { - phantomas.setMetric('timeToFirstByte', entry.timeToFirstByte); - phantomas.setMetric('timeToLastByte', entry.timeToLastByte); - - ipc.push('timeToFirstByte', entry.timeToFirstByte); - ipc.push('timeToLastByte', entry.timeToLastByte); + phantomas.setMetric('timeToFirstByte', entry.timeToFirstByte, true); + phantomas.setMetric('timeToLastByte', entry.timeToLastByte, true); ttfbMeasured = true; diff --git a/lib/index.js b/lib/index.js index 3f343f553..761e16acb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -115,9 +115,16 @@ function phantomas(url, options, callback) { // handle page loading milestones (#240) var milestoneDebug = require('debug')('phantomas:milestone'); - ipc.on('milestone', function(ev, time) { - milestoneDebug('%s: %d ms', ev, time); - events.emit('milestone', ev, time); + ipc.on('metric', function(metric, value) { + switch(metric) { + case 'timeToFirstByte': + case 'timeToLastByte': + case 'onDOMReadyTime': + case 'windowOnLoadTime': + milestoneDebug('%s: %d ms', metric, value); + events.emit('milestone', metric, value); + break; + } }); // process results