-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[No QA] Add React Native Firebase Performance monitoring #4173
Merged
+340
−97
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9526c32
add iOS native module code
marcaaron 94e12d6
Add trace module to Android
marcaaron 14cbd77
Fix up style
marcaaron 73bede6
rename startup timer
marcaaron fe02c21
remove unused
marcaaron 2b80149
Add some better comments
marcaaron 4c76071
Do not trace when in debug
marcaaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
android/app/src/main/java/com/expensify/chat/ExpensifyAppPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.expensify.chat; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ExpensifyAppPackage implements ReactPackage { | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules( | ||
ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new StartupTimer(reactContext)); | ||
|
||
return modules; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
android/app/src/main/java/com/expensify/chat/StartupTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.expensify.chat; | ||
import android.util.Log; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.google.firebase.perf.FirebasePerformance; | ||
import com.google.firebase.perf.metrics.Trace; | ||
|
||
public class StartupTimer extends ReactContextBaseJavaModule { | ||
StartupTimer(ReactApplicationContext context) { | ||
super(context); | ||
} | ||
|
||
private static Trace trace = null; | ||
|
||
@Override | ||
public String getName() { | ||
return "StartupTimer"; | ||
} | ||
|
||
@ReactMethod | ||
public void stop() { | ||
if (trace == null) { | ||
return; | ||
} | ||
|
||
trace.stop(); | ||
} | ||
|
||
public static void start() { | ||
if (BuildConfig.DEBUG) { | ||
Log.d("StartupTimer", "Metric tracing disabled in DEBUG"); | ||
} else { | ||
trace = FirebasePerformance.getInstance().newTrace("js_loaded"); | ||
trace.start(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// RCTStartupTimer.h | ||
// ExpensifyCash | ||
// | ||
// Created by Marc Glasser on 7/21/21. | ||
// | ||
#import <React/RCTBridgeModule.h> | ||
#import <FirebasePerformance/FIRPerformance.h> | ||
|
||
#ifndef RCTStartupTimer_h | ||
#define RCTStartupTimer_h | ||
|
||
|
||
#endif /* RCTStartupTimer_h */ | ||
|
||
@interface RCTStartupTimer : NSObject <RCTBridgeModule> | ||
+ (void)start; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// RCTStartupTimer.m | ||
// ExpensifyCash | ||
// | ||
// Created by Marc Glasser on 7/21/21. | ||
// | ||
|
||
#import "RCTStartupTimer.h" | ||
|
||
@implementation RCTStartupTimer | ||
|
||
static FIRTrace *trace = nil; | ||
|
||
+ (void)start { | ||
#if DEBUG | ||
// We don't want to record this on debug since it will skew the metrics we collect | ||
NSLog(@"[StartupTimer] Metric tracing disabled in DEBUG"); | ||
#else | ||
trace = [FIRPerformance startTraceWithName:@"js_loaded"]; | ||
#endif | ||
} | ||
|
||
RCT_EXPORT_METHOD(stop) | ||
{ | ||
if (trace) { | ||
[trace stop]; | ||
} | ||
} | ||
|
||
// To export a module named StartupTimer | ||
RCT_EXPORT_MODULE(StartupTimer); | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: Actually, my only comment is that maybe this could be made generic, so that each timing trace doesn't require a new Java class. But I'm sure you're aware of this, and it's not necessary until we add the second trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, I guess my thinking here was that we really only need a single timer in the native layer (when the app starts) for now. If we need to do performance traces with firebase we can do that via the JS later and this package
https://rnfirebase.io/perf/usage#custom-tracing