Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report(metrics): display metrics in seconds #5914

Merged
merged 5 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lighthouse-core/audits/bootup-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class BootupTime extends Audit {
return {
score,
rawValue: totalBootupTime,
displayValue: totalBootupTime > 0 ? str_(i18n.UIStrings.ms, {timeInMs: totalBootupTime}) : '',
displayValue: totalBootupTime > 0 ?
str_(i18n.UIStrings.seconds, {timeInMs: totalBootupTime}) : '',
details,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/mainthread-work-breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MainThreadWorkBreakdown extends Audit {
return {
score,
rawValue: totalExecutionTime,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: totalExecutionTime}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: totalExecutionTime}),
details: tableDetails,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FirstContentfulPaint extends Audit {
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-cpu-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FirstCPUIdle extends Audit {
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FirstMeaningfulPaint extends Audit {
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class InteractiveMetric extends Audit {
context.options.scoreMedian
),
rawValue: timeInMs,
displayValue: str_(i18n.UIStrings.ms, {timeInMs}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs}),
extendedInfo: {
value: extendedInfo,
},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SpeedIndex extends Audit {
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}
Expand Down
15 changes: 14 additions & 1 deletion lighthouse-core/lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ const MESSAGE_INSTANCE_ID_REGEX = /(.* \| .*) # (\d+)$/;


const UIStrings = {
/** Used to show the duration in milliseconds that something lasted. The `{timeInMs}` placeholder will be replaced with the time duration, shown in milliseconds (e.g. 63 ms) */
/** Used to show the duration in milliseconds that something lasted. The `{timeInMs}` placeholder will be replaced with the time duration, shown in milliseconds (e.g. 63 ms) */
ms: '{timeInMs, number, milliseconds}\xa0ms',
/** Used to show the duration in seconds that something lasted. The {timeInMs} placeholder will be replaced with the time duration, shown in seconds (e.g. 5.2 s) */
seconds: '{timeInMs, number, seconds}\xa0s',
/** Label shown per-audit to show how many bytes smaller the page could be if the user implemented the suggestions. The `{wastedBytes}` placeholder will be replaced with the number of bytes, shown in kilobytes (e.g. 148 KB) */
displayValueByteSavings: 'Potential savings of {wastedBytes, number, bytes}\xa0KB',
/** Label shown per-audit to show how many milliseconds faster the page load could be if the user implemented the suggestions. The `{wastedMs}` placeholder will be replaced with the time duration, shown in milliseconds (e.g. 140 ms) */
Expand All @@ -64,6 +66,11 @@ const formats = {
milliseconds: {
maximumFractionDigits: 0,
},
seconds: {
// Force the seconds to the tenths place for limited output and ease of scanning
minimumFractionDigits: 1,
maximumFractionDigits: 1,
},
},
};

Expand Down Expand Up @@ -109,6 +116,12 @@ function _preprocessMessageValues(icuMessage, values) {
// @ts-ignore - el.id is always defined when el.format is defined
.forEach(el => (clonedValues[el.id] = Math.round(clonedValues[el.id] / 10) * 10));

// Convert all seconds to the correct unit
parsed.elements
.filter(el => el.format && el.format.style === 'seconds' && el.id === 'timeInMs')
// @ts-ignore - el.id is always defined when el.format is defined
.forEach(el => (clonedValues[el.id] = Math.round(clonedValues[el.id] / 100) / 10));

// Replace all the bytes with KB
parsed.elements
.filter(el => el.format && el.format.style === 'bytes')
Expand Down
4 changes: 4 additions & 0 deletions lighthouse-core/lib/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@
"message": "{timeInMs, number, milliseconds} ms",
"description": "Used to show the duration in milliseconds that something lasted. The `{timeInMs}` placeholder will be replaced with the time duration, shown in milliseconds (e.g. 63 ms)"
},
"lighthouse-core/lib/i18n.js | seconds": {
"message": "{timeInMs, number, seconds} s",
"description": "Used to show the duration in seconds that something lasted. The {timeInMs} placeholder will be replaced with the time duration, shown in seconds (e.g. 5.2 s)"
},
"lighthouse-core/report/html/renderer/util.js | auditGroupExpandTooltip": {
"message": "Show audits",
"description": "The tooltip text on an expandable chevron icon. Clicking the icon expands a section to reveal a list of audit results that was hidden by default."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Performance: first-meaningful-paint audit', () => {

assert.equal(fmpResult.score, 1);
assert.equal(fmpResult.rawValue, 783.328);
expect(fmpResult.displayValue).toBeDisplayString('780\xa0ms');
expect(fmpResult.displayValue).toBeDisplayString('0.8\xa0s');
});

it('computes FMP correctly for simulated', async () => {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Performance: interactive audit', () => {
return Interactive.audit(artifacts, {options, settings}).then(output => {
assert.equal(output.score, 1);
assert.equal(Math.round(output.rawValue), 1582);
expect(output.displayValue).toBeDisplayString('1,580\xa0ms');
expect(output.displayValue).toBeDisplayString('1.6\xa0s');
});
});

Expand All @@ -52,7 +52,7 @@ describe('Performance: interactive audit', () => {
return Interactive.audit(artifacts, {options, settings}).then(output => {
assert.equal(output.score, 0.97);
assert.equal(Math.round(output.rawValue), 2712);
expect(output.displayValue).toBeDisplayString('2,710\xa0ms');
expect(output.displayValue).toBeDisplayString('2.7\xa0s');
});
});
});
30 changes: 16 additions & 14 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"score": 0.51,
"scoreDisplayMode": "numeric",
"rawValue": 3969.135,
"displayValue": "3,970 ms"
"displayValue": "4.0 s"
},
"first-meaningful-paint": {
"id": "first-meaningful-paint",
Expand All @@ -93,7 +93,7 @@
"score": 0.51,
"scoreDisplayMode": "numeric",
"rawValue": 3969.136,
"displayValue": "3,970 ms"
"displayValue": "4.0 s"
},
"load-fast-enough-for-pwa": {
"id": "load-fast-enough-for-pwa",
Expand All @@ -110,7 +110,7 @@
"score": 0.74,
"scoreDisplayMode": "numeric",
"rawValue": 4417,
"displayValue": "4,420 ms"
"displayValue": "4.4 s"
},
"screenshot-thumbnails": {
"id": "screenshot-thumbnails",
Expand Down Expand Up @@ -270,7 +270,7 @@
"score": 0.72,
"scoreDisplayMode": "numeric",
"rawValue": 4927.278,
"displayValue": "4,930 ms"
"displayValue": "4.9 s"
},
"interactive": {
"id": "interactive",
Expand All @@ -279,7 +279,7 @@
"score": 0.78,
"scoreDisplayMode": "numeric",
"rawValue": 4927.278,
"displayValue": "4,930 ms"
"displayValue": "4.9 s"
},
"user-timings": {
"id": "user-timings",
Expand Down Expand Up @@ -646,7 +646,7 @@
"score": 0.96,
"scoreDisplayMode": "numeric",
"rawValue": 1548.5690000000002,
"displayValue": "1,550 ms",
"displayValue": "1.5 s",
"details": {
"type": "table",
"headings": [
Expand Down Expand Up @@ -708,7 +708,7 @@
"score": 0.92,
"scoreDisplayMode": "numeric",
"rawValue": 1150.932,
"displayValue": "1,150 ms",
"displayValue": "1.2 s",
"details": {
"type": "table",
"headings": [
Expand Down Expand Up @@ -3429,7 +3429,7 @@
"lighthouse-core/audits/metrics/first-contentful-paint.js | description": [
"audits[first-contentful-paint].description"
],
"lighthouse-core/lib/i18n.js | ms": [
"lighthouse-core/lib/i18n.js | seconds": [
{
"values": {
"timeInMs": 3969.135
Expand All @@ -3448,12 +3448,6 @@
},
"path": "audits[speed-index].displayValue"
},
{
"values": {
"timeInMs": 16
},
"path": "audits[estimated-input-latency].displayValue"
},
{
"values": {
"timeInMs": 4927.278
Expand Down Expand Up @@ -3497,6 +3491,14 @@
"lighthouse-core/audits/metrics/estimated-input-latency.js | description": [
"audits[estimated-input-latency].description"
],
"lighthouse-core/lib/i18n.js | ms": [
{
"values": {
"timeInMs": 16
},
"path": "audits[estimated-input-latency].displayValue"
}
],
"lighthouse-core/audits/time-to-first-byte.js | title": [
"audits[time-to-first-byte].title"
],
Expand Down