[perf][android] Add perf module
This commit is contained in:
parent
a0d492ddac
commit
66d7e3c944
|
@ -20,6 +20,7 @@ import io.invertase.firebase.database.RNFirebaseDatabase;
|
|||
import io.invertase.firebase.analytics.RNFirebaseAnalytics;
|
||||
import io.invertase.firebase.crash.RNFirebaseCrash;
|
||||
import io.invertase.firebase.messaging.RNFirebaseMessaging;
|
||||
import io.invertase.firebase.perf.RNFirebasePerformance;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RNFirebasePackage implements ReactPackage {
|
||||
|
@ -43,6 +44,7 @@ public class RNFirebasePackage implements ReactPackage {
|
|||
modules.add(new RNFirebaseMessaging(reactContext));
|
||||
modules.add(new RNFirebaseCrash(reactContext));
|
||||
modules.add(new RNFirebaseRemoteConfig(reactContext));
|
||||
modules.add(new RNFirebasePerformance(reactContext));
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
|||
import Analytics from './modules/analytics';
|
||||
import Crash from './modules/crash';
|
||||
import RemoteConfig from './modules/config';
|
||||
import Performance from './modules/perf';
|
||||
|
||||
const instances: Object = { default: null };
|
||||
const FirebaseModule = NativeModules.RNFirebase;
|
||||
|
@ -34,6 +35,7 @@ export default class Firebase {
|
|||
_messaging: ?Object;
|
||||
_config: ?Object;
|
||||
_crash: ?Object;
|
||||
_perf: ?Object;
|
||||
|
||||
auth: Function;
|
||||
crash: Function;
|
||||
|
@ -42,6 +44,7 @@ export default class Firebase {
|
|||
analytics: Function;
|
||||
messaging: Function;
|
||||
config: Function;
|
||||
perf: Function;
|
||||
|
||||
eventHandlers: Object;
|
||||
debug: boolean;
|
||||
|
@ -86,6 +89,7 @@ export default class Firebase {
|
|||
this.analytics = this._staticsOrInstance('analytics', {}, Analytics);
|
||||
this.crash = this._staticsOrInstance('crash', {}, Crash);
|
||||
this.config = this._staticsOrInstance('config', {}, RemoteConfig);
|
||||
this.perf = this._staticsOrInstance('perf', {}, Performance);
|
||||
|
||||
// init auth to start listeners
|
||||
this.auth();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue