Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
deactivateAndFlush() {
if (!this._enabled) {
return;
}
const start = this._samplesStartTime; // const for flow
if (start == null) {
DEBUG &&
console.debug('FillRateHelper: bail on deactivate with no start time');
return;
}
if (this._info.sample_count < _minSampleCount) {
// Don't bother with under-sampled events.
this._resetData();
return;
}
const total_time_spent = performanceNow() - start;
const info: any = {
...this._info,
total_time_spent,
};
if (DEBUG) {
const derived = {
avg_blankness: this._info.pixels_blank / this._info.pixels_sampled,
avg_speed: this._info.pixels_scrolled / (total_time_spent / 1000),
avg_speed_when_any_blank:
this._info.any_blank_speed_sum / this._info.any_blank_count,
any_blank_per_min:
this._info.any_blank_count / (total_time_spent / 1000 / 60),
any_blank_time_frac: this._info.any_blank_ms / total_time_spent,
mostly_blank_per_min:
this._info.mostly_blank_count / (total_time_spent / 1000 / 60),
mostly_blank_time_frac: this._info.mostly_blank_ms / total_time_spent,
props.getItemCount(props.data) === 0 ||
this._samplesStartTime == null
) {
return 0;
}
const {dOffset, offset, velocity, visibleLength} = scrollMetrics;
// Denominator metrics that we track for all events - most of the time there is no blankness and
// we want to capture that.
this._info.sample_count++;
this._info.pixels_sampled += Math.round(visibleLength);
this._info.pixels_scrolled += Math.round(Math.abs(dOffset));
const scrollSpeed = Math.round(Math.abs(velocity) * 1000); // px / sec
// Whether blank now or not, record the elapsed time blank if we were blank last time.
const now = performanceNow();
if (this._anyBlankStartTime != null) {
this._info.any_blank_ms += now - this._anyBlankStartTime;
}
this._anyBlankStartTime = null;
if (this._mostlyBlankStartTime != null) {
this._info.mostly_blank_ms += now - this._mostlyBlankStartTime;
}
this._mostlyBlankStartTime = null;
let blankTop = 0;
let first = state.first;
let firstFrame = this._getFrameMetrics(first);
while (first <= state.last && (!firstFrame || !firstFrame.inLayout)) {
firstFrame = this._getFrameMetrics(first);
first++;
}
activate() {
if (this._enabled && this._samplesStartTime == null) {
DEBUG && console.debug('FillRateHelper: activate');
this._samplesStartTime = performanceNow();
}
}
instance[method] = (...args) => {
const timestamp = Date.now();
const start = performanceNow();
const result = fn.call(instance, ...args);
const context = this.context.getContextPayload();
this.context.resetContext();
if (result && result.then) {
return result.then(res =>
this.processResult({
result: res,
component,
method,
timing: measureTiming(start),
context,
timestamp,
})
);
instance[property] = () => {
const start = performanceNow();
const result = fn.call(instance, arguments);
const context = this.context.getContextPayload();
this.context.resetContext();
if (result && result.then) {
return result.then(res =>
this.send({
result: res,
name,
property,
timing: measureTiming(start),
context,
})
);
}
function iteration() {
const now = performanceNow();
const busyTime = now - lastInterval;
if (busyTime >= thresholdMS) {
const stallTime = busyTime - thresholdMS;
stallCount++;
totalStallTime += stallTime;
longestStall = Math.max(longestStall, stallTime);
let msg =
`JSEventLoopWatchdog: JS thread busy for ${busyTime}ms. ` +
`${totalStallTime}ms in ${stallCount} stalls so far. `;
handlers.forEach(handler => {
msg += handler.onStall({lastInterval, busyTime}) || '';
});
infoLog(msg);
}
handlers.forEach(handler => {
handler.onIterate && handler.onIterate();
install: function({thresholdMS}: {thresholdMS: number}) {
acceptableBusyTime = thresholdMS;
if (installed) {
return;
}
installed = true;
lastInterval = performanceNow();
function iteration() {
const now = performanceNow();
const busyTime = now - lastInterval;
if (busyTime >= thresholdMS) {
const stallTime = busyTime - thresholdMS;
stallCount++;
totalStallTime += stallTime;
longestStall = Math.max(longestStall, stallTime);
let msg =
`JSEventLoopWatchdog: JS thread busy for ${busyTime}ms. ` +
`${totalStallTime}ms in ${stallCount} stalls so far. `;
handlers.forEach(handler => {
msg += handler.onStall({lastInterval, busyTime}) || '';
});
infoLog(msg);
}
reset: function() {
infoLog('JSEventLoopWatchdog: reset');
totalStallTime = 0;
stallCount = 0;
longestStall = 0;
lastInterval = performanceNow();
},
addHandler: function(handler: Handler) {