* Ticks a timing event. * * @param {TickLabel_Enum} label The variable name as it will be reported. * See TICKEVENTS.md for available metrics, and edit this file * when adding a new metric. * @param {number=} opt_delta The delta. Call tickDelta instead of setting * this
(label, opt_delta, opt_value)
| 797 | * @param {number=} opt_value The value to use. Overrides default calculation. |
| 798 | */ |
| 799 | tick(label, opt_delta, opt_value) { |
| 800 | devAssert( |
| 801 | opt_delta == undefined || opt_value == undefined, |
| 802 | 'You may not set both opt_delta and opt_value.' |
| 803 | ); |
| 804 | |
| 805 | const data = {'label': label}; |
| 806 | let delta; |
| 807 | |
| 808 | if (opt_delta != undefined) { |
| 809 | data['delta'] = delta = Math.max(opt_delta, 0); |
| 810 | } else if (opt_value != undefined) { |
| 811 | data['value'] = opt_value; |
| 812 | } else { |
| 813 | // Marking only makes sense for non-overridden values (and no deltas). |
| 814 | this.mark(label); |
| 815 | delta = this.win.performance.now(); |
| 816 | data['value'] = this.timeOrigin_ + delta; |
| 817 | } |
| 818 | |
| 819 | // Emit events. Used by `amp performance`. |
| 820 | this.win.dispatchEvent( |
| 821 | createCustomEvent( |
| 822 | this.win, |
| 823 | 'perf', |
| 824 | /** @type {JsonObject} */ ({label, delta}) |
| 825 | ) |
| 826 | ); |
| 827 | |
| 828 | if (this.isMessagingReady_ && this.isPerformanceTrackingOn_) { |
| 829 | this.viewer_.sendMessage('tick', data); |
| 830 | } else { |
| 831 | this.queueTick_(data); |
| 832 | } |
| 833 | |
| 834 | this.metrics_.signal(label, delta); |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Add browser performance timeline entries for simple ticks. |
no test coverage detected