Skip to content

Commit

Permalink
Add trace module to Android
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Jul 22, 2021
1 parent 9526c32 commit 94e12d6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
3 changes: 3 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ dependencies {
implementation jscFlavor
}

implementation platform("com.google.firebase:firebase-bom:20.0.2")
implementation "com.google.firebase:firebase-perf"

// GIF support
implementation 'com.facebook.fresco:fresco:2.3.0'
implementation 'com.facebook.fresco:animated-gif:2.3.0'
Expand Down
7 changes: 6 additions & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true"
/>
</application>
</manifest>
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected List<ReactPackage> getPackages() {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new PlaidPackage());
packages.add(new ExpensifyAppPackage());

// Add unimodules
List<ReactPackage> unimodules = Arrays.<ReactPackage>asList(
Expand Down Expand Up @@ -76,6 +77,9 @@ public void onCreate() {
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
}

// Start the startup timer
StartupTimer.start();

// Increase SQLite DB write size
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
Expand Down
33 changes: 33 additions & 0 deletions android/app/src/main/java/com/expensify/chat/StartupTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.expensify.chat;
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() {
trace = FirebasePerformance.getInstance().newTrace("js_loaded");
trace.start();
}
}

0 comments on commit 94e12d6

Please sign in to comment.