From 2d01b63cfebd212c41f9eea2f2aa30ac70fced59 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 17 Feb 2020 07:19:16 +0100 Subject: [PATCH] app cold and warm start timing --- app | 2 +- .../java/io/lbry/browser/MainActivity.java | 29 ++++++++++++++++++- .../browser/reactmodules/FirebaseModule.java | 20 +++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app b/app index 601c589..04f1537 160000 --- a/app +++ b/app @@ -1 +1 @@ -Subproject commit 601c589f6903a1c33b073b7d72fb4618ecf4a0ef +Subproject commit 04f1537e7650d238208ea5d790ec0fdd3f4fe0ab diff --git a/src/main/java/io/lbry/browser/MainActivity.java b/src/main/java/io/lbry/browser/MainActivity.java index bf4d9d1..2b94a84 100644 --- a/src/main/java/io/lbry/browser/MainActivity.java +++ b/src/main/java/io/lbry/browser/MainActivity.java @@ -66,6 +66,7 @@ import java.net.URISyntaxException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -129,9 +130,12 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac protected String getMainComponentName() { return "LBRYApp"; } - + + public static LaunchTiming CurrentLaunchTiming; + @Override protected void onCreate(Bundle savedInstanceState) { + CurrentLaunchTiming = new LaunchTiming(new Date()); super.onCreate(savedInstanceState); currentActivity = this; @@ -149,6 +153,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac // Start the daemon service if it is not started serviceRunning = isServiceRunning(LbrynetService.class); if (!serviceRunning) { + CurrentLaunchTiming.setColdStart(true); ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice"); } @@ -845,4 +850,26 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac public static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); } + + public static class LaunchTiming { + private Date start; + private boolean coldStart; + + public LaunchTiming(Date start) { + this.start = start; + } + + public Date getStart() { + return start; + } + public void setStart(Date start) { + this.start = start; + } + public boolean isColdStart() { + return coldStart; + } + public void setColdStart(boolean coldStart) { + this.coldStart = coldStart; + } + } } diff --git a/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java b/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java index b16af22..7cf2a65 100644 --- a/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java +++ b/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java @@ -20,6 +20,7 @@ import io.lbry.browser.BuildConfig; import io.lbry.browser.MainActivity; import io.lbry.browser.Utils; +import java.util.Date; import java.util.HashMap; import java.util.Map; import org.json.JSONObject; @@ -108,4 +109,23 @@ public class FirebaseModule extends ReactContextBaseJavaModule { } }); } + + @ReactMethod + public void logLaunchTiming() { + Date end = new Date(); + MainActivity.LaunchTiming currentTiming = MainActivity.CurrentLaunchTiming; + if (currentTiming == null) { + // no start timing data, so skip this + return; + } + + long totalTimeMs = end.getTime() - currentTiming.getStart().getTime(); + String eventName = currentTiming.isColdStart() ? "app_cold_start" : "app_warm_start"; + Bundle bundle = new Bundle(); + bundle.putLong("total_ms", totalTimeMs); + bundle.putLong("total_seconds", new Double(Math.ceil(totalTimeMs / 1000.0)).longValue()); + if (firebaseAnalytics != null) { + firebaseAnalytics.logEvent(eventName, bundle); + } + } } \ No newline at end of file