简体   繁体   中英

Android: Where is the .trace file when Profiling with Traceview and Genymotion?

I'm reading this article here about running traceview on your android app: https://developer.android.com/studio/profile/traceview.html I assume the emulator they are talking about is the android emulator, not the Genymotion emulator which is the one I'm using.

It says to pull the trace file out of the emulator onto your host machine, you can just run the following commands:

adb pull /sdcard/startup.trace /tmp

I ran it on my Genymotion emulator and the file was not found. I then used the Android Device Monitor to look inside the device for the file but there was no file called startup.trace saved in that location.

I did this in my code:

public class MyApplication extends MultiDexApplication {

    public void onCreate() {
        super.onCreate();
        Debug.startMethodTracing("startup"); 
    }
  }

Then I stoppedTracing in my activity onResume method to measure the startup time of my app:

@Override
protected void onResume() {
    super.onResume();
    Debug.stopMethodTracing();
}

I want the traceview to measure my startup time but don't know where the file is saved on my Genymotion emulator. Can anyone assist me with where the file is saved?

I unable to find .trace file from above sample app (or any app). Because .trace file is not located at:

/sdcard/<myTraceFile>.trace

I did trick using find command to find location of my trace file as follows:-

$adb shell
$cd /sdcard
$find |grep .trace

I got my file location at:

./Android/data/test.com.trackstartuptime/files/startup.trace

For the above sample app. Now use this location for adb pull as :-

$adb pull /sdcard/Android/data/test.com.trackstartuptime/files/startup.trace <my_location>

So after testing this with a simple android app, it actually works out as planned.

I have created a small repo to demonstrate this:

https://github.com/Winghin2517/TraceviewTest.git

You can download it, run it on your genymotion emulator and then type within the "Terminal" tab of Android Studios the following:

adb pull /sdcard/startup.trace /tmp

It will pull the trace file from Genymotion. Then you will need to switch on DDMS and say "File" -> "Open" and and open the startup.trace file.

The android app that I created demonstrate the time it takes to log out 1000 messages into the console. You can see the skin color bars represents the time android used to call my testCount method:

在此处输入图片说明

Here are my results:

在此处输入图片说明

My method testCount took 10ms to complete.

The reclusive call to the Log.e method also makes sense as my loop in my code is for 1000 calls to the log.e method.

Incl CPU time is the inclusive cpu time. It is the sum of the time spent in the function itself, as well as the sum of the times of all functions that it calls.

Excl CPU time is the exclusive cpu time. It is only the time spent in the function itself. You'll notice that it is always the same as the "incl time" of the "self" child.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM