How to use the fbjs/lib/performanceNow function in fbjs

To help you get started, we’ve selected a few fbjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / FillRateHelper / index.js View on Github external
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,
github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / FillRateHelper / index.js View on Github external
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++;
    }
github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / FillRateHelper / index.js View on Github external
activate() {
    if (this._enabled && this._samplesStartTime == null) {
      DEBUG && console.debug('FillRateHelper: activate');
      this._samplesStartTime = performanceNow();
    }
  }
github pleak / pleak-react-perf-monitor / src / Pleak.js View on Github external
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,
            })
          );
github pleak / pleak-react-perf-monitor / src / Pleak.js View on Github external
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,
            })
          );
        }
github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / JSEventLoopWatchdog / index.js View on Github external
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();
github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / JSEventLoopWatchdog / index.js View on Github external
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);
      }
github necolas / react-native-web / packages / react-native-web / src / vendor / react-native / JSEventLoopWatchdog / index.js View on Github external
reset: function() {
    infoLog('JSEventLoopWatchdog: reset');
    totalStallTime = 0;
    stallCount = 0;
    longestStall = 0;
    lastInterval = performanceNow();
  },
  addHandler: function(handler: Handler) {