Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 486
Simon Avatar asked Jul 18 '16 19:07

Simon


People also ask

Where are Android trace files stored?

trace file, and the system saves it to a package-specific directory that's intended for persistent app data on the target device—this is the same directory that is returned by getExternalFilesDir() and is located in the ~/sdcard/ directory on most devices.

Where can I find trace logs?

By default, the trace log is located in the following directories. Console trace logs are saved in the trace log directories of the WebSphere Application Server node where the administration console is installed.

How do I open a Perfetto trace file?

To do so: Open your web browser and go to https://ui.perfetto.dev. Select Open trace file. Navigate to and open your PERFETTO-TRACE file.


2 Answers

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>
like image 54
charlie Avatar answered Oct 19 '22 00:10

charlie


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:

enter image description here

Here are my results:

enter image description here

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.

like image 30
Simon Avatar answered Oct 19 '22 02:10

Simon