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

67 lines
1.9 KiB
Markdown
Raw Normal View History

2017-05-24 11:51:44 +00:00
# Performance Monitoring
!> Performance monitoring requires react-native-firebase version 1.2.0.
2017-07-04 14:58:43 +00:00
?> Android: If you plan on using this module in your own application, please ensure the optional setup instructions for
[Android](http://invertase.io/react-native-firebase/#/installation-android?id=_4-performance-monitoring-optional) have been followed.
2017-05-24 11:51:44 +00:00
Out of the box, [Firebase Performance Monitoring](https://firebase.google.com/docs/perf-mon/automatic) monitors a number of
[automatic traces](https://firebase.google.com/docs/perf-mon/automatic) 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.
```js
firebase.perf().setPerformanceCollectionEnabled(false); // Disable
```
2017-05-24 11:51:44 +00:00
#### 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.
```js
const trace = firebase.perf().newTrace("test_trace");
```
### Trace
2017-05-25 09:39:19 +00:00
!> Once a trace has been started and stopped, you cannot re-start it in the same app lifecycle.
2017-05-24 11:51:44 +00:00
#### start()
Initializes the trace to start tracing performance to relay back to Firebase.
```js
trace.start();
```
#### incrementCounter(event: string)
Notifies Firebase an event has occured. These events will be visible on Firebase once your trace has stopped.
```js
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.
2017-05-24 16:01:16 +00:00
?> Results are not realtime. They can take a number of hours to appear in the Firebase console.
2017-05-24 11:51:44 +00:00
```js
trace.stop();
```