Android debug traces do not contain application specific method calls

950 views Asked by At

I am trying to generate trace files for applications using the Debug.startMethodTracing (on the activity onCreate) and Debug.stopMethodTracing (on the activity onDestroy) according to the following documentation http://developer.android.com/tools/debugging/debugging-tracing.html#creatingtracefiles.

I run the application on a physical device and it successfully creates the trace file. Later I run dmtracedump on them to generate a call-stack diagram, but it does not contain any of my application method calls.

To test this, I created a simple Android application, added debbuggable to the manifest:

 <application
    ... 
    android:debuggable="true">

Created two test classes A and B. Class A has two methods b() and c():

public class A {

private int _i;

public A(){_i=0;}

public void b(){c();}
public void c(){for(int k=0;k<20;k++)_i++;}}

Class B has a single method c():

public class B {

public void c(){
    (new A()).b();
    A d = new A();
    d.c();
}}

Finally in the main activity on the onCreate and onDestroy methods I started the tracing:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Debug.startMethodTracing("debugtest");

    A a;
    for (int i = 0; i < 20; i++) {
        a = new A();
        a.b();
        a.c();
    }

    (new B()).c();
}

@Override
public void onDestroy() {
    super.onDestroy();
    Debug.stopMethodTracing();
}

I was hoping to get at least A.b() and A.c() method calls in the call stack diagram but after running:

adb pull sdcard/debugtest.trace . ; dmtracedump debugtest.trace -g tree.png

The generated call graph is as follows:

enter image description here

Is this how it is supposed to work, i.e. just show android calls and not application method calls, or am I missing something?

Please note that i am mostly interested in retrieving the exclusive and inclusive times of method execution.

2

There are 2 answers

0
65537 On BEST ANSWER

It might be because (by default) the -t option of traceview is set to 20%. From AndroidStudio dmtracedump

-t : Minimum threshold for including child nodes in the graph (child's inclusive time as a percentage of parent inclusive time). If this option is not used, the default threshold is 20%.

If you open your trace file with traceview you'll see that your graph is something like:

  • the first node of your graph is the first method call
  • the second of your graph is the first child of the first call in traceview
  • the third of your graph is the first child of the child of the first method call
  • and so on...

Run dmtracedump with -t 0 (as follows) and you should see all the methods.

dmtracedump -t 0 debugtest.trace -g tree.png
1
TheHamstring On

You can get more information by placing e.getStacktrace() or using a Log in your classes. I find it's easier to explicitly ask for the errors than hoping the code will just come to you. Of course there is probably a much better way but that is how I've been doing it for a while and I've been able to get a really consistent and easy to pinpoint result.