Merge pull request #850 from lbryio/app-timing

app cold and warm start timing
This commit is contained in:
Akinwale Ariwodola 2020-02-17 07:32:49 +01:00 committed by GitHub
commit bc8f476ef1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 2 deletions

2
app

@ -1 +1 @@
Subproject commit 601c589f6903a1c33b073b7d72fb4618ecf4a0ef Subproject commit 04f1537e7650d238208ea5d790ec0fdd3f4fe0ab

View file

@ -66,6 +66,7 @@ import java.net.URISyntaxException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -129,9 +130,12 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
protected String getMainComponentName() { protected String getMainComponentName() {
return "LBRYApp"; return "LBRYApp";
} }
public static LaunchTiming CurrentLaunchTiming;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
CurrentLaunchTiming = new LaunchTiming(new Date());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
currentActivity = this; currentActivity = this;
@ -149,6 +153,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
// Start the daemon service if it is not started // Start the daemon service if it is not started
serviceRunning = isServiceRunning(LbrynetService.class); serviceRunning = isServiceRunning(LbrynetService.class);
if (!serviceRunning) { if (!serviceRunning) {
CurrentLaunchTiming.setColdStart(true);
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice"); ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
} }
@ -845,4 +850,26 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
public static boolean isGooglePhotosUri(Uri uri) { public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority()); 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;
}
}
} }

View file

@ -20,6 +20,7 @@ import io.lbry.browser.BuildConfig;
import io.lbry.browser.MainActivity; import io.lbry.browser.MainActivity;
import io.lbry.browser.Utils; import io.lbry.browser.Utils;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.json.JSONObject; 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);
}
}
} }