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

performance: emit timeOrigin w/ polyfill #26485

Merged
merged 2 commits into from
Jan 27, 2020
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
7 changes: 7 additions & 0 deletions src/service/performance-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ export class Performance {
// Tick the "messaging ready" signal.
this.tickDelta('msr', this.win.Date.now() - this.initTime_);

// Tick timeOrigin so that epoch time can be calculated by consumers.
this.tickDelta(
'timeOrigin',
this.win.performance.timeOrigin ||
this.win.performance.timing.navigationStart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to make all our initTime_'s relative to timeOrigin, too. Or, we can just emit a timeOrigin tick using initTime.

Copy link
Member Author

@samouri samouri Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but it doesn't need to happen in this PR. We are already inconsistent and this PR leaves us at the same level of inconsistency.

  • browser given deltas are all relative to timeOrigin
  • v0 calculated deltas (e.g. 'pc', 'ol', etc.) are relative to initTime_

This PR doesn't change that inconsistency, although I do agree that we should fix it as part of #16042

);

return this.maybeAddStoryExperimentId_();
})
.then(() => {
Expand Down
21 changes: 16 additions & 5 deletions test/unit/test-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,24 @@ describes.realWin('performance', {amp: true}, env => {
expect(perf.isMessagingReady_).to.be.true;
const msrCalls = viewerSendMessageStub.withArgs(
'tick',
env.sandbox.match(arg => arg.label == 'msr')
env.sandbox.match(arg => arg.label === 'msr')
);
expect(msrCalls).to.be.calledOnce;
expect(msrCalls.args[0][1]).to.be.jsonEqual({
label: 'msr',
delta: 1,
});

const timeOriginCall = viewerSendMessageStub.withArgs(
'tick',
env.sandbox.match(arg => arg.label === 'timeOrigin')
);
expect(timeOriginCall).to.be.calledOnce;
expect(timeOriginCall).calledWithMatch('tick', {
label: 'timeOrigin',
delta: env.sandbox.match.number,
});

expect(flushSpy).to.have.callCount(5);
expect(perf.events_.length).to.equal(0);
});
Expand Down Expand Up @@ -650,16 +661,16 @@ describes.realWin('performance', {amp: true}, env => {
() => {
clock.tick(100);
whenFirstVisibleResolve();
expect(tickSpy).to.have.callCount(3);
expect(tickSpy).to.have.callCount(4);
return ampdoc.whenFirstVisible().then(() => {
clock.tick(400);
expect(tickSpy).to.have.callCount(4);
expect(tickSpy).to.have.callCount(5);
whenViewportLayoutCompleteResolve();
return perf.whenViewportLayoutComplete_().then(() => {
expect(tickSpy).to.have.callCount(4);
expect(tickSpy).to.have.callCount(5);
expect(tickSpy.withArgs('ofv')).to.be.calledOnce;
return whenFirstVisiblePromise.then(() => {
expect(tickSpy).to.have.callCount(5);
expect(tickSpy).to.have.callCount(6);
expect(tickSpy.withArgs('pc')).to.be.calledOnce;
expect(Number(tickSpy.withArgs('pc').args[0][1])).to.equal(400);
});
Expand Down