[perf][android] Add perf module

This commit is contained in:
Elliot Hesp 2017-05-24 12:37:52 +01:00
parent a0d492ddac
commit 66d7e3c944
4 changed files with 48 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import io.invertase.firebase.database.RNFirebaseDatabase;
import io.invertase.firebase.analytics.RNFirebaseAnalytics; import io.invertase.firebase.analytics.RNFirebaseAnalytics;
import io.invertase.firebase.crash.RNFirebaseCrash; import io.invertase.firebase.crash.RNFirebaseCrash;
import io.invertase.firebase.messaging.RNFirebaseMessaging; import io.invertase.firebase.messaging.RNFirebaseMessaging;
import io.invertase.firebase.perf.RNFirebasePerformance;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class RNFirebasePackage implements ReactPackage { public class RNFirebasePackage implements ReactPackage {
@ -43,6 +44,7 @@ public class RNFirebasePackage implements ReactPackage {
modules.add(new RNFirebaseMessaging(reactContext)); modules.add(new RNFirebaseMessaging(reactContext));
modules.add(new RNFirebaseCrash(reactContext)); modules.add(new RNFirebaseCrash(reactContext));
modules.add(new RNFirebaseRemoteConfig(reactContext)); modules.add(new RNFirebaseRemoteConfig(reactContext));
modules.add(new RNFirebasePerformance(reactContext));
return modules; return modules;
} }

View File

@ -15,6 +15,7 @@ import Messaging, { statics as MessagingStatics } from './modules/messaging';
import Analytics from './modules/analytics'; import Analytics from './modules/analytics';
import Crash from './modules/crash'; import Crash from './modules/crash';
import RemoteConfig from './modules/config'; import RemoteConfig from './modules/config';
import Performance from './modules/perf';
const instances: Object = { default: null }; const instances: Object = { default: null };
const FirebaseModule = NativeModules.RNFirebase; const FirebaseModule = NativeModules.RNFirebase;
@ -34,6 +35,7 @@ export default class Firebase {
_messaging: ?Object; _messaging: ?Object;
_config: ?Object; _config: ?Object;
_crash: ?Object; _crash: ?Object;
_perf: ?Object;
auth: Function; auth: Function;
crash: Function; crash: Function;
@ -42,6 +44,7 @@ export default class Firebase {
analytics: Function; analytics: Function;
messaging: Function; messaging: Function;
config: Function; config: Function;
perf: Function;
eventHandlers: Object; eventHandlers: Object;
debug: boolean; debug: boolean;
@ -86,6 +89,7 @@ export default class Firebase {
this.analytics = this._staticsOrInstance('analytics', {}, Analytics); this.analytics = this._staticsOrInstance('analytics', {}, Analytics);
this.crash = this._staticsOrInstance('crash', {}, Crash); this.crash = this._staticsOrInstance('crash', {}, Crash);
this.config = this._staticsOrInstance('config', {}, RemoteConfig); this.config = this._staticsOrInstance('config', {}, RemoteConfig);
this.perf = this._staticsOrInstance('perf', {}, Performance);
// init auth to start listeners // init auth to start listeners
this.auth(); this.auth();

24
lib/modules/perf/Trace.js Normal file
View File

@ -0,0 +1,24 @@
const FirebasePerformance = NativeModules.RNFirebasePerformance;
export default class Trace {
constructor(perf: Object, identifier: string) {
this.perf = perf;
this.identifier = identifier;
}
start() {
this.perf.log.debug(`Starting trace for ${this.identifier}`);
FirebasePerformance.start(this.identifier);
}
stop() {
this.perf.log.debug(`Stopping trace for ${this.identifier}`);
FirebasePerformance.stop(this.identifier);
}
incrementCounter(event: string) {
this.perf.log.debug(`Incrementing counter event ${event} trace for ${this.identifier}`);
FirebasePerformance.incrementCounter(this.identifier, event);
}
}

18
lib/modules/perf/index.js Normal file
View File

@ -0,0 +1,18 @@
// @flow
import { Base } from './../base';
import Trace from './Trace';
export default class PerformanceMonitoring extends Base {
/**
* Returns a new trace instance
* @param trace
*/
newTrace(trace: string): void {
return new Trace(this, trace);
}
get namespace(): string {
return 'firebase:perf';
}
}