Skip to content

Commit

Permalink
Emit "milestone" event for certain metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Feb 27, 2014
1 parent dff0488 commit ba3add3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 3 additions & 7 deletions core/modules/requestsMonitor/requestsMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 10 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba3add3

Please sign in to comment.