Skip to content

Commit

Permalink
Unify the timings we write to the log per run (#1277)
Browse files Browse the repository at this point in the history
* Unify the timings we write to the log per run

* moar unify how we output metrics
  • Loading branch information
soulgalore committed May 9, 2020
1 parent d8ae146 commit a062bb1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 16 deletions.
94 changes: 79 additions & 15 deletions lib/core/engine/collector.js
Expand Up @@ -5,6 +5,7 @@ const engineUtils = require('../../support/engineUtils');
const log = require('intel').getLogger('browsertime');
const Statistics = require('../../support/statistics').Statistics;
const pathToFolder = require('../../support/pathToFolder');
const { formatMetric } = require('../../support/util');
const path = require('path');

function getNewResult(url, options) {
Expand Down Expand Up @@ -178,28 +179,91 @@ class Collector {
});
}

if (
data.browserScripts &&
data.browserScripts.timings &&
data.browserScripts.timings.pageTimings &&
this.options.iterations > 1
) {
const pt = data.browserScripts.timings.pageTimings;
if (this.options.iterations > 1) {
const ttfb = get(
data,
'browserScripts.timings.pageTimings.backEndTime'
);
const domContentLoaded = get(
data,
'browserScripts.timings.pageTimings.domContentLoadedTime'
);
const firstPaint = get(data, 'browserScripts.timings.firstPaint');
const fcp = get(
data,
"browserScripts.timings.paintTiming['first-contentful-paint']"
);
const pageLoadTime = get(
data,
'browserScripts.timings.pageTimings.pageLoadTime'
);
const lcp = get(
data,
'browserScripts.timings.largestContentfulPaint.renderTime'
);
const cls = get(data, 'browserScripts.pageinfo.layoutShift');
const tbt = get(data, 'cpu.longTasks.totalBlockingTime');

log.info(
`${url} BackEndTime: ${pt.backEndTime} DomInteractiveTime: ${
pt.domInteractiveTime
} DomContentLoadedTime: ${pt.domContentLoadedTime} FirstPaint: ${
data.browserScripts.timings.firstPaint
? data.browserScripts.timings.firstPaint
: '?'
} PageLoadTime: ${pt.pageLoadTime}`
`${url} ${ttfb ? formatMetric('TTFB', ttfb, false, true) + ' ' : ''}${
domContentLoaded
? formatMetric(
'DOMContentLoaded',
domContentLoaded,
false,
true
) + ' '
: ''
}${
firstPaint
? formatMetric('firstPaint', firstPaint, false, true) + ' '
: ''
}${fcp ? formatMetric('FCP', fcp, false, true) + ' ' : ''}${
lcp ? formatMetric('LCP', lcp, false, true) + ' ' : ''
}${
pageLoadTime
? formatMetric('Load', pageLoadTime, false, true) + ' '
: ''
}${tbt ? formatMetric('TBT', tbt, false, true) + ' ' : ''}${
cls ? 'CLS:' + cls.toFixed(1) + '%' : ''
}`
);
}

if (data.visualMetrics) {
if (this.options.iterations > 1) {
log.info(
`VisualMetrics FirstVisualChange: ${data.visualMetrics.FirstVisualChange} SpeedIndex: ${data.visualMetrics.SpeedIndex} PerceptualSpeedIndex: ${data.visualMetrics.PerceptualSpeedIndex} ContentfulSpeedIndex: ${data.visualMetrics.ContentfulSpeedIndex} VisualComplete85: ${data.visualMetrics.VisualComplete85} LastVisualChange: ${data.visualMetrics.LastVisualChange}`
`VisualMetrics: ${formatMetric(
'FirstVisualChange',
data.visualMetrics.FirstVisualChange,
false,
true
)} ${formatMetric(
'SpeedIndex',
data.visualMetrics.SpeedIndex,
false,
true
)} ${formatMetric(
'PerceptualSpeedIndex',
data.visualMetrics.PerceptualSpeedIndex,
false,
true
)} ${formatMetric(
'ContentfulSpeedIndex',
data.visualMetrics.ContentfulSpeedIndex,
false,
true
)} ${formatMetric(
'VisualComplete85',
data.visualMetrics.VisualComplete85,
false,
true
)} ${formatMetric(
'LastVisualChange',
data.visualMetrics.LastVisualChange,
false,
true
)}`
);
}
for (let key of Object.keys(data.visualMetrics)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/support/util.js
Expand Up @@ -16,7 +16,7 @@ module.exports = {
} else return value;
}

let formatted = `${name}: ${fmt(metric.mean)}`;
let formatted = `${name}: ${fmt(multiple ? metric.mean : metric)}`;
if (multiple) {
formatted += ` (±${fmt(metric.mdev.toFixed(2))})`;
}
Expand Down

0 comments on commit a062bb1

Please sign in to comment.