Skip to content

Commit

Permalink
use navstart as default
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jun 6, 2017
1 parent d4c4605 commit df3c12e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
7 changes: 3 additions & 4 deletions lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EstimatedInputLatency extends Audit {

return {
score: Math.round(score),
optimalValue: this.meta.optimalValue,
optimalValue: EstimatedInputLatency.meta.optimalValue,
rawValue,
displayValue: Util.formatMilliseconds(rawValue, 1),
extendedInfo: {
Expand All @@ -87,9 +87,8 @@ class EstimatedInputLatency extends Audit {
static audit(artifacts) {
const trace = artifacts.traces[this.DEFAULT_PASS];

return artifacts.requestTraceOfTab(trace).then(tabTrace => {
return EstimatedInputLatency.calculate(tabTrace);
});
return artifacts.requestTraceOfTab(trace)
.then(EstimatedInputLatency.calculate);
}
}

Expand Down
19 changes: 18 additions & 1 deletion lighthouse-core/closure/typedefs/ComputedArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,31 @@
* @externs
*/

/** @typedef
* {{
* navigationStart: number,
* firstPaint: number,
* firstContentfulPaint: number,
* firstMeaningfulPaint: number,
* traceEnd: number,
* onLoad: number,
* domContentLoaded: number,
* }}
*/
let TraceTimes;

/** @typedef
{{
timings: !TraceTimes,
timestamps: !TraceTimes,
processEvents: !Array<!TraceEvent>,
mainThreadEvents: !Array<!TraceEvent>,
startedInPageEvt: !TraceEvent,
navigationStartEvt: !TraceEvent,
firstPaintEvt: TraceEvent,
firstContentfulPaintEvt: TraceEvent,
firstMeaningfulPaintEvt: TraceEvent
firstMeaningfulPaintEvt: TraceEvent,
onLoadEvt: TraceEvent,
}} */
let TraceOfTabArtifact;

Expand Down
10 changes: 2 additions & 8 deletions lighthouse-core/gather/computed/trace-of-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ class TraceOfTab extends ComputedArtifact {
const mainThreadEvents = processEvents
.filter(e => e.tid === startedInPageEvt.tid);

const earliestTraceEvt = trace.traceEvents.reduce((min, evt) => {
return evt.ts === 0 || min.ts <= evt.ts ? min : evt;
}, {ts: Infinity});

const latestTraceEvt = trace.traceEvents.reduce((max, evt) => {
const traceEnd = trace.traceEvents.reduce((max, evt) => {
return max.ts > evt.ts ? max : evt;
});

Expand All @@ -114,7 +110,7 @@ class TraceOfTab extends ComputedArtifact {
firstPaint,
firstContentfulPaint,
firstMeaningfulPaint,
traceEnd: latestTraceEvt,
traceEnd: {ts: traceEnd.ts + (traceEnd.dur || 0)},
onLoad,
domContentLoaded,
};
Expand All @@ -132,8 +128,6 @@ class TraceOfTab extends ComputedArtifact {
timestamps,
processEvents,
mainThreadEvents,
earliestTraceEvt,
latestTraceEvt,
startedInPageEvt,
navigationStartEvt: navigationStart,
firstPaintEvt: firstPaint,
Expand Down
42 changes: 17 additions & 25 deletions lighthouse-core/lib/traces/tracing-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,21 @@ class TraceProcessor {
/**
* Calculates the maximum queueing time (in ms) of high priority tasks for
* selected percentiles within a window of the main thread.
* @see https://docs.google.com/document/d/18gvP-CBA2BiBpi3Rz1I1ISciKGhniTSZ9TY0XCnXS7E/preview
* @see https://docs.google.com/document/d/1b9slyaB9yho91YTOkAQfpCdULFkZM9LqsipcX3t7He8/preview
* @param {!TraceOfTabArtifact} tabTrace
* @param {number=} startTime Optional start time (in ms) of range of interest. Defaults to trace start.
* @param {number=} endTime Optional end time (in ms) of range of interest. Defaults to trace end.
* @param {number=} startTime Optional start time (in ms relative to navstart) of range of interest. Defaults to navstart.
* @param {number=} endTime Optional end time (in ms relative to navstart) of range of interest. Defaults to trace end.
* @param {!Array<number>=} percentiles Optional array of percentiles to compute. Defaults to [0.5, 0.75, 0.9, 0.99, 1].
* @return {!Array<{percentile: number, time: number}>}
*/
static getRiskToResponsiveness(tabTrace, startTime, endTime, percentiles) {
const navStart = tabTrace.navigationStartEvt.ts;
const traceStart = tabTrace.earliestTraceEvt.ts;
const traceEnd = tabTrace.latestTraceEvt.ts;

// Range of responsiveness we care about. Default to bounds of model.
startTime = startTime === undefined ? (traceStart - navStart) / 1000 : startTime;
endTime = endTime === undefined ? (traceEnd - navStart) / 1000 : endTime;

static getRiskToResponsiveness(
tabTrace,
startTime = 0,
endTime = tabTrace.timings.traceEnd,
percentiles = [0.5, 0.75, 0.9, 0.99, 1]
) {
const totalTime = endTime - startTime;
if (percentiles) {
percentiles.sort((a, b) => a - b);
} else {
percentiles = [0.5, 0.75, 0.9, 0.99, 1];
}
percentiles.sort((a, b) => a - b);

const ret = TraceProcessor.getMainThreadTopLevelEventDurations(tabTrace, startTime, endTime);
return TraceProcessor._riskPercentiles(ret.durations, totalTime, percentiles,
Expand All @@ -152,11 +145,11 @@ class TraceProcessor {
/**
* Provides durations in ms of all main thread top-level events
* @param {!TraceOfTabArtifact} tabTrace
* @param {number} startTime Optional start time (in ms) of range of interest. Defaults to trace start.
* @param {number} endTime Optional end time (in ms) of range of interest. Defaults to trace end.
* @param {number} startTime Optional start time (in ms relative to navstart) of range of interest. Defaults to navstart.
* @param {number} endTime Optional end time (in ms relative to navstart) of range of interest. Defaults to trace end.
* @return {{durations: !Array<number>, clippedLength: number}}
*/
static getMainThreadTopLevelEventDurations(tabTrace, startTime = -Infinity, endTime = Infinity) {
static getMainThreadTopLevelEventDurations(tabTrace, startTime = 0, endTime = Infinity) {
const topLevelTasks = TraceProcessor.getMainThreadTopLevelEvents(tabTrace, startTime, endTime);

// Find durations of all slices in range of interest.
Expand Down Expand Up @@ -191,13 +184,13 @@ class TraceProcessor {
* Provides the top level events on the main thread with timestamps in ms relative to navigation
* start.
* @param {!TraceOfTabArtifact} tabTrace
* @param {number=} startTime Optional start time (in ms) of range of interest. Defaults to trace start.
* @param {number=} endTime Optional end time (in ms) of range of interest. Defaults to trace end.
* @param {number=} startTime Optional start time (in ms relative to navstart) of range of interest. Defaults to navstart.
* @param {number=} endTime Optional end time (in ms relative to navstart) of range of interest. Defaults to trace end.
* @return {!Array<{start: number, end: number, duration: number}>}
*/
static getMainThreadTopLevelEvents(tabTrace, startTime = -Infinity, endTime = Infinity) {
static getMainThreadTopLevelEvents(tabTrace, startTime = 0, endTime = Infinity) {
const topLevelEvents = [];
// note: processEvents is already sorted by event start
// note: mainThreadEvents is already sorted by event start
for (const event of tabTrace.mainThreadEvents) {
if (event.name !== SCHEDULABLE_TASK_TITLE || !event.dur) continue;

Expand All @@ -209,7 +202,6 @@ class TraceProcessor {
start,
end,
duration: event.dur / 1000,
events: [event],
});
}
return topLevelEvents;
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-core/test/lib/traces/tracing-processor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('TracingProcessor lib', () => {
const tabTrace = new TraceOfTab().compute_(trace);
const ret = TracingProcessor.getMainThreadTopLevelEvents(tabTrace);

assert.equal(ret.length, 651);
assert.equal(ret.length, 645);
});

it('filters events based on start and end times', () => {
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('TracingProcessor lib', () => {
}

assert.equal(durations.filter(dur => isNaN(dur)).length, 0, 'NaN found');
assert.equal(durations.length, 651);
assert.equal(durations.length, 645);

assert.equal(getDurationFromIndex(50), 0.01);
assert.equal(getDurationFromIndex(300), 0.04);
Expand Down Expand Up @@ -272,8 +272,8 @@ describe('TracingProcessor lib', () => {
const trace = {traceEvents: pwaTrace};
const tabTrace = new TraceOfTab().compute_(trace);
const ret = TracingProcessor.getRiskToResponsiveness(tabTrace);
assert.equal(ret.durations.length, 651);
assert.equal(Math.round(ret.totalTime), 2159);
assert.equal(ret.durations.length, 645);
assert.equal(Math.round(ret.totalTime), 2143);
assert.equal(ret.clippedLength, 0);
assert.deepEqual(ret.percentiles, [0.5, 0.75, 0.9, 0.99, 1]);
});
Expand Down

0 comments on commit df3c12e

Please sign in to comment.