Merge pull request #850 from lbryio/app-timing
app cold and warm start timing
This commit is contained in:
commit
bc8f476ef1
3 changed files with 49 additions and 2 deletions
2
app
2
app
|
@ -1 +1 @@
|
|||
Subproject commit 601c589f6903a1c33b073b7d72fb4618ecf4a0ef
|
||||
Subproject commit 04f1537e7650d238208ea5d790ec0fdd3f4fe0ab
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue