From 9ebda147f8d03238eb5dd296f09fc66b53589f76 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 25 May 2017 08:41:43 +0100 Subject: [PATCH] [perf][android] Add setPerformanceCollectionEnabled method --- .../firebase/perf/RNFirebasePerformance.java | 5 +++++ lib/modules/perf/index.js | 12 ++++++++++++ tests/src/tests/perf/performanceTests.js | 11 +++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java b/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java index f131de96..62026975 100644 --- a/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java +++ b/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java @@ -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); diff --git a/lib/modules/perf/index.js b/lib/modules/perf/index.js index 6062e3f9..48f0ea31 100644 --- a/lib/modules/perf/index.js +++ b/lib/modules/perf/index.js @@ -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 diff --git a/tests/src/tests/perf/performanceTests.js b/tests/src/tests/perf/performanceTests.js index 3325cbec..9f57c83a 100644 --- a/tests/src/tests/perf/performanceTests.js +++ b/tests/src/tests/perf/performanceTests.js @@ -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;