react-native-firebase/docs/modules/perf.md

1.8 KiB

Performance Monitoring

?> Android: If you plan on using this module in your own application, please ensure the optional setup instructions for Android have been followed.

Out of the box, Firebase Performance Monitoring monitors a number of automatic traces such as app start/background/foreground response times. You can easily trace your own events with RNFirebase:

API

setPerformanceCollectionEnabled(enabled: boolean)

Globally enables or disables performance monitoring capture across the app.

firebase.perf().setPerformanceCollectionEnabled(false); // Disable

newTrace(id: string): Trace

Returns a new instance of Trace (see API below). The id is the unique name of something you'd like to run performance monitoring against.

const trace = firebase.perf().newTrace("test_trace");

Trace

!> Once a trace has been started and stopped, you cannot re-start it in the same app lifecycle.

start()

Initializes the trace to start tracing performance to relay back to Firebase.

trace.start();

incrementCounter(event: string)

Notifies Firebase an event has occured. These events will be visible on Firebase once your trace has stopped.

someCacheService.get('user:123')
  .then((user) => {
    if (user) {
      trace.incrementCounter('user_cache_hit');
    } else {
      trace.incrementCounter('user_cache_missed');
    }
  });

stop()

Stops performance tracing. The completed trace stats are now sent to Firebase.

?> Results are not realtime. They can take a number of hours to appear in the Firebase console.

trace.stop();