Skip to content

Commit

Permalink
refactor(trace-of-tab): return timestamps in microseconds (#2454)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jun 8, 2017
1 parent 1bb1cfe commit 7d6ea29
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 44 deletions.
16 changes: 8 additions & 8 deletions lighthouse-core/audits/consistently-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ConsistentlyInteractiveMetric extends Audit {
* @return {!Array<!TimePeriod>}
*/
static _findNetworkQuietPeriods(networkRecords, traceOfTab) {
const traceEnd = traceOfTab.timestamps.traceEnd;
const traceEndTsInMs = traceOfTab.timestamps.traceEnd / 1000;

// First collect the timestamps of when requests start and end
const timeBoundaries = [];
Expand Down Expand Up @@ -95,7 +95,7 @@ class ConsistentlyInteractiveMetric extends Audit {

// Check if the trace ended in a quiet period
if (numInflightRequests <= ALLOWED_CONCURRENT_REQUESTS) {
quietPeriods.push({start: quietPeriodStart, end: traceEnd});
quietPeriods.push({start: quietPeriodStart, end: traceEndTsInMs});
}

return quietPeriods;
Expand All @@ -108,8 +108,8 @@ class ConsistentlyInteractiveMetric extends Audit {
* @return {!Array<!TimePeriod>}
*/
static _findCPUQuietPeriods(longTasks, traceOfTab) {
const navStartTsInMs = traceOfTab.timestamps.navigationStart;
const traceEndTsInMs = traceOfTab.timestamps.traceEnd;
const navStartTsInMs = traceOfTab.timestamps.navigationStart / 1000;
const traceEndTsInMs = traceOfTab.timestamps.traceEnd / 1000;
if (longTasks.length === 0) {
return [{start: 0, end: traceEndTsInMs}];
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class ConsistentlyInteractiveMetric extends Audit {
* cpuQuietPeriods: !Array<!TimePeriod>, networkQuietPeriods: !Array<!TimePeriod>}}
*/
static findOverlappingQuietPeriods(longTasks, networkRecords, traceOfTab) {
const FMPTsInMs = traceOfTab.timestamps.firstMeaningfulPaint;
const FMPTsInMs = traceOfTab.timestamps.firstMeaningfulPaint / 1000;

const isLongEnoughQuietPeriod = period =>
period.end > FMPTsInMs + REQUIRED_QUIET_WINDOW &&
Expand Down Expand Up @@ -229,10 +229,10 @@ class ConsistentlyInteractiveMetric extends Audit {

const timestamp = Math.max(
cpuQuietPeriod.start,
traceOfTab.timestamps.firstMeaningfulPaint,
traceOfTab.timestamps.domContentLoaded
traceOfTab.timestamps.firstMeaningfulPaint / 1000,
traceOfTab.timestamps.domContentLoaded / 1000
) * 1000;
const timeInMs = (timestamp - traceOfTab.timestamps.navigationStart * 1000) / 1000;
const timeInMs = (timestamp - traceOfTab.timestamps.navigationStart) / 1000;
const extendedInfo = Object.assign(quietPeriodInfo, {timestamp, timeInMs});

let score = 100 * distribution.computeComplementaryPercentile(timeInMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class LinkBlockingFirstPaintAudit extends Audit {
static audit(artifacts) {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
return artifacts.requestTraceOfTab(trace).then(traceOfTab => {
const fcp = traceOfTab.timestamps.firstContentfulPaint;
return this.computeAuditResultForTags(artifacts, 'LINK', fcp, LOAD_THRESHOLD_IN_MS);
const fcpTsInMs = traceOfTab.timestamps.firstContentfulPaint / 1000;
return this.computeAuditResultForTags(artifacts, 'LINK', fcpTsInMs, LOAD_THRESHOLD_IN_MS);
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class FirstMeaningfulPaint extends Audit {
// Expose the raw, unchanged monotonic timestamps from the trace, along with timing durations
const extendedInfo = {
timestamps: {
navStart: traceOfTab.timestamps.navigationStart * 1000,
fCP: traceOfTab.timestamps.firstContentfulPaint * 1000,
fMP: traceOfTab.timestamps.firstMeaningfulPaint * 1000,
onLoad: traceOfTab.timestamps.onLoad * 1000,
endOfTrace: traceOfTab.timestamps.traceEnd * 1000,
navStart: traceOfTab.timestamps.navigationStart,
fCP: traceOfTab.timestamps.firstContentfulPaint,
fMP: traceOfTab.timestamps.firstMeaningfulPaint,
onLoad: traceOfTab.timestamps.onLoad,
endOfTrace: traceOfTab.timestamps.traceEnd,
},
timings: {
navStart: 0,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/computed/first-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class FirstInteractive extends ComputedArtifact {
const valueInMs = Math.max(firstInteractive, DCL);
return {
timeInMs: valueInMs,
timestamp: (valueInMs + navStart) * 1000,
timestamp: valueInMs * 1000 + navStart,
};
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/computed/speedline.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Speedline extends ComputedArtifact {
return computedArtifacts.requestTraceOfTab(trace).then(traceOfTab => {
// Force use of nav start as reference point for speedline
// See https://github.com/GoogleChrome/lighthouse/issues/2095
const navStart = traceOfTab.timestamps.navigationStart * 1000;
const navStart = traceOfTab.timestamps.navigationStart;
return speedline(trace.traceEvents, {
timeOrigin: navStart,
fastMode: true,
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/computed/trace-of-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class TraceOfTab extends ComputedArtifact {
const timestamps = {};

Object.keys(metrics).forEach(metric => {
timestamps[metric] = metrics[metric] && metrics[metric].ts / 1000;
timings[metric] = timestamps[metric] - timestamps.navigationStart;
timestamps[metric] = metrics[metric] && metrics[metric].ts;
timings[metric] = (timestamps[metric] - navigationStart.ts) / 1000;
});

return {
Expand Down
43 changes: 25 additions & 18 deletions lighthouse-core/test/audits/consistently-interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const redirectTrace = require('../fixtures/traces/site-with-redirect.json');
const redirectDevToolsLog = require('../fixtures/traces/site-with-redirect.devtools.log.json');

function generateNetworkRecords(records, navStart) {
const navStartInMs = navStart / 1000;
return records.map(item => {
return {
finished: typeof item.finished === 'undefined' ? true : item.finished,
startTime: (item.start + navStart) / 1000,
endTime: item.end === -1 ? -1 : (item.end + navStart) / 1000,
startTime: (item.start + navStartInMs) / 1000,
endTime: item.end === -1 ? -1 : (item.end + navStartInMs) / 1000,
};
});
}
Expand Down Expand Up @@ -64,22 +65,22 @@ describe('Performance: consistently-interactive audit', () => {
describe('#findOverlappingQuietPeriods', () => {
it('should return entire range when no activity is present', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 2500 + navigationStart;
const traceEnd = 10000 + navigationStart;
const firstMeaningfulPaint = 2500 * 1000 + navigationStart;
const traceEnd = 10000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [];
const network = generateNetworkRecords([], navigationStart);

const result = ConsistentlyInteractive.findOverlappingQuietPeriods(cpu, network, traceOfTab);
assert.deepEqual(result.cpuQuietPeriod, {start: 0, end: traceEnd});
assert.deepEqual(result.networkQuietPeriod, {start: 0, end: traceEnd});
assert.deepEqual(result.cpuQuietPeriod, {start: 0, end: traceEnd / 1000});
assert.deepEqual(result.networkQuietPeriod, {start: 0, end: traceEnd / 1000});
});

it('should throw when trace ended too soon after FMP', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 2500 + navigationStart;
const traceEnd = 5000 + navigationStart;
const firstMeaningfulPaint = 2500 * 1000 + navigationStart;
const traceEnd = 5000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [];
Expand All @@ -92,8 +93,8 @@ describe('Performance: consistently-interactive audit', () => {

it('should throw when CPU is quiet but network is not', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 2500 + navigationStart;
const traceEnd = 10000 + navigationStart;
const firstMeaningfulPaint = 2500 * 1000 + navigationStart;
const traceEnd = 10000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [];
Expand All @@ -111,8 +112,8 @@ describe('Performance: consistently-interactive audit', () => {

it('should throw when network is quiet but CPU is not', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 2500 + navigationStart;
const traceEnd = 10000 + navigationStart;
const firstMeaningfulPaint = 2500 * 1000 + navigationStart;
const traceEnd = 10000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [
Expand All @@ -129,8 +130,8 @@ describe('Performance: consistently-interactive audit', () => {

it('should handle unfinished network requests', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 2500 + navigationStart;
const traceEnd = 10000 + navigationStart;
const firstMeaningfulPaint = 2500 * 1000 + navigationStart;
const traceEnd = 10000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [];
Expand All @@ -147,8 +148,8 @@ describe('Performance: consistently-interactive audit', () => {

it('should find first overlapping quiet period', () => {
const navigationStart = 220023532;
const firstMeaningfulPaint = 10000 + navigationStart;
const traceEnd = 45000 + navigationStart;
const firstMeaningfulPaint = 10000 * 1000 + navigationStart;
const traceEnd = 45000 * 1000 + navigationStart;
const traceOfTab = {timestamps: {navigationStart, firstMeaningfulPaint, traceEnd}};

const cpu = [
Expand Down Expand Up @@ -180,8 +181,14 @@ describe('Performance: consistently-interactive audit', () => {
], navigationStart);

const result = ConsistentlyInteractive.findOverlappingQuietPeriods(cpu, network, traceOfTab);
assert.deepEqual(result.cpuQuietPeriod, {start: 34000 + navigationStart, end: traceEnd});
assert.deepEqual(result.networkQuietPeriod, {start: 32000 + navigationStart, end: traceEnd});
assert.deepEqual(result.cpuQuietPeriod, {
start: 34000 + navigationStart / 1000,
end: traceEnd / 1000,
});
assert.deepEqual(result.networkQuietPeriod, {
start: 32000 + navigationStart / 1000,
end: traceEnd / 1000,
});
assert.equal(result.cpuQuietPeriods.length, 3);
assert.equal(result.networkQuietPeriods.length, 2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Link Block First Paint audit', () => {
media: '',
rel: 'stylesheet'
};
const timestamps = {firstContentfulPaint: 5600};
const timestamps = {firstContentfulPaint: 5600 * 1000};
return LinkBlockingFirstPaintAudit.audit({
traces: {},
requestTraceOfTab: () => Promise.resolve({timestamps}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('FirstInteractive computed artifact:', () => {
traceEnd: 12000,
},
timestamps: {
navigationStart: 600,
navigationStart: 600 * 1000,
},
});

Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/test/gather/computed/trace-of-tab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ describe('Trace of Tab computed artifact:', () => {

it('computes timestamps of each event', () => {
const trace = traceOfTab.compute_(lateTracingStartedTrace);
assert.equal(Math.round(trace.timestamps.navigationStart), 29343541);
assert.equal(Math.round(trace.timestamps.firstPaint), 29343621);
assert.equal(Math.round(trace.timestamps.firstContentfulPaint), 29343621);
assert.equal(Math.round(trace.timestamps.firstMeaningfulPaint), 29344071);
assert.equal(Math.round(trace.timestamps.traceEnd), 29344190);
assert.equal(Math.round(trace.timestamps.navigationStart), 29343540951);
assert.equal(Math.round(trace.timestamps.firstPaint), 29343620997);
assert.equal(Math.round(trace.timestamps.firstContentfulPaint), 29343621005);
assert.equal(Math.round(trace.timestamps.firstMeaningfulPaint), 29344070867);
assert.equal(Math.round(trace.timestamps.traceEnd), 29344190223);
});

describe('finds correct FMP', () => {
Expand Down

0 comments on commit 7d6ea29

Please sign in to comment.