I am trying to log the start up latency of my app. They way I am doing it is setting the start time of the app on Application.onCreate
and provide a public method that returns the time.
MyApplication extends Application {
Date startUpTime;
//Declare variables
@Override
public void onCreate() {
super.onCreate();
setStartupTime();
//other initializations
}
private void setStartUpTime() {
startUpTime = new Date();
}
public Date getStartUpTime() {
return startUpTime;
}
}
MyActivity extends Activity {
.
.
.
@Override
public void onStart(){
logStartUpLatency();
//other onStart stuff
}
private void logStartUpLatency() {
Date currentTime = new Date();
Date startTime = (MyApplication)getApplicationContext().getStartUpTime();
long latency = currentTime.getTime() - startTIme.getTime();
Log.d("Start up Latency is ", Long.toString(latency)):
}
This is how I am testing my start up latency:
Does any one know why that might happen?
Update
So if I install the apk using "adb install -r myapk", the app isn't going through the Myapplication.onCreate()
.
There are two common definitions of latency. Launch latency, sometimes called induction time, is the time between requesting an asynchronous task and beginning to execute it.
There's no reliable way to detect first run, as the shared preferences way is not always safe, the user can delete the shared preferences data from the settings! a better way is to use the answers here Is there a unique Android device ID? to get the device's unique ID and store it somewhere in your server, so whenever ...
An Android process is started whenever it is required. Any time a user or some other system component requests a component (could be a service, an activity or an intent receiver) that belongs to your application be executed, the Android system spins off a new process for your app if it's not already running.
I suggest the use of the TimingLogger
class. As per the documentation, you can easily track the elapsed time and even add splits in the process.
This
TimingLogger timings = new TimingLogger(TAG, "methodA");
// ... do some work A ...
timings.addSplit("work A");
// ... do some work B ...
timings.addSplit("work B");
// ... do some work C ...
timings.addSplit("work C");
timings.dumpToLog();
produces
D/TAG (3459): methodA: begin
D/TAG (3459): methodA: 9 ms, work A
D/TAG (3459): methodA: 1 ms, work B
D/TAG (3459): methodA: 6 ms, work C
D/TAG (3459): methodA: end, 16 ms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With