[perf][android] Add setPerformanceCollectionEnabled method

This commit is contained in:
Elliot Hesp 2017-05-25 08:41:43 +01:00
parent 4882123912
commit 9ebda147f8
3 changed files with 26 additions and 2 deletions

View File

@ -29,6 +29,11 @@ public class RNFirebasePerformance extends ReactContextBaseJavaModule {
return TAG;
}
@ReactMethod
public void setPerformanceCollectionEnabled(Boolean enabled) {
FirebasePerformance.getInstance().setPerformanceCollectionEnabled(enabled);
}
@ReactMethod
public void start(String identifier) {
Trace trace = getOrCreateTrace(identifier);

View File

@ -1,9 +1,21 @@
// @flow
import { NativeModules } from 'react-native';
import { Base } from './../base';
import Trace from './Trace';
const FirebasePerformance = NativeModules.RNFirebasePerformance;
export default class PerformanceMonitoring extends Base {
/**
* Globally enable or disable performance monitoring
* @param enabled
* @returns {*}
*/
setPerformanceCollectionEnabled(enabled: boolean) {
return FirebasePerformance.setPerformanceCollectionEnabled(enabled);
}
/**
* Returns a new trace instance
* @param trace

View File

@ -1,4 +1,4 @@
function messagingTests({ fdescribe, it, firebase }) {
function performanceTests({ fdescribe, it, firebase }) {
fdescribe('Performance Monitoring', () => {
it('it should return a new Task instance', () => {
const trace = firebase.native.perf().newTrace('foo');
@ -19,7 +19,14 @@ function messagingTests({ fdescribe, it, firebase }) {
return Promise.resolve();
});
it('it should disable and enable performance monitoring', () => {
firebase.native.perf().setPerformanceCollectionEnabled(false);
firebase.native.perf().setPerformanceCollectionEnabled(true);
return Promise.resolve();
});
});
}
export default messagingTests;
export default performanceTests;