Launch Time of an app

2020-02-29 11:05发布

What is the best way to launch an app and calculate its launch time in android(if it can be done with some code,then its better)

5条回答
兄弟一词,经得起流年.
2楼-- · 2020-02-29 11:16

There will be an automatic log something like

system_process I/ActivityManager﹕ Displayed com.android.vending/com.google.android.finsky.activities.MainActivity: +549ms

to show the launch time of an app from the user typing on it to the app be ready to interact with user further more. That is from ActivityManager.

Also, using log to measure the time from onCreate() to onResume should be another good way.

查看更多
The star\"
3楼-- · 2020-02-29 11:26

To do it fast I would use logcat, something like:

Log.d("tag", "starting");
/* code goes here */
Log.d("tag", "finished");

If you want to do something bigger, try Traceview.

查看更多
来,给爷笑一个
4楼-- · 2020-02-29 11:33

You could find the answer here -

This information gets logged on Logcat by default for API version 19 or higher. The key is looking for it in the right place -

If you’re tracking logcat output from the command line, or in a terminal, finding the elapsed time is straightforward. To find elapsed time in Android Studio, you must disable filters in your logcat view. Disabling the filters is necessary because the system server, not the app itself, serves this log.

Here is the example from the documentation for completeness.

ActivityManager: Displayed com.android.myexample/.StartupTiming: +3s534ms

The extracts are from the documentation.

查看更多
萌系小妹纸
5楼-- · 2020-02-29 11:38

Hmm - first, to be more precise, I should point out that in Android you start activities, rather than applications!

So, as your entry point to your application is the Activity which handles the LAUNCH intent, one could interpret your question as "how to measure activity start up time".

For this, I suggest to look at an Activities lifecycle here: https://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle.

Looking at the nice graph there, you see that startup time is essentially the time that is spent in onCreate(), onStart() and onResume().

To measure that, I would suggest to use traceview as this will really show you in all its detail where you spent your time! Start tracing using Debug.startMethodTracing("startUp"); in the beginning of onCreate() and end tracing at the end of onResume() with Debug.stopMethodTracing();.

Because onCreate() is only called once per instance, you don't even have to worry about multiple calls to onResume() in case this activity will be put to the background as you will call the stop method twice, which is no harm!

Have fun - I like the possibilities of traceview very much!

查看更多
仙女界的扛把子
6楼-- · 2020-02-29 11:40

In scope of answers above I would like to note, what the Traceview unable to provide the real time, due to JIT is turned off while profiling. The Traceview is the useless tool to monitor the time of executing of source's code. (Traceview is a good tools to check stacktrace only, as mentioned above by using Debug class with startMethodTracing() and stopMethodTracing()).

I suggest to use systrace (via Eclipse plugin, for an example) this is best tool to calculate the real time of executing (and many other features).

For more information take a look at: http://developer.android.com/tools/debugging/systrace.html

Also, I want to note that sometimes systrace will not work (depends from FS mapping).

You need to check 'system\core\rootdir\init.rc' with correct of 'debugfs' mounted. Should be as: 'mount debugfs /sys/kernel/debug /sys/kernel/debug'

查看更多
登录 后发表回答