Berkay92
Berkay92

Reputation: 586

Is it possible to see which functions are called in Logcat?

I know, there is a way to see which functions are called in log-cat is to write a log message on top for every function like this

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.d("myTag","onDestroy function is called!");
    // some logic
}

But it becomes irritating when you have more function.

So, I wonder if there is a way to see which functions are called in adb-logcat without writing log messages for every function.

I hope they can be fetched from somewhere in the stack but I couldn't find it.

Upvotes: 2

Views: 1496

Answers (2)

Alexander Mironov
Alexander Mironov

Reputation: 3102

You can try Hugo. In that case you have to annotate your methods with @DebugLog only. Then Hugo will generate logs for you (and will print out arguments and return value!). Example from GitHub:

@DebugLog
public String getName(String first, String last) {
  SystemClock.sleep(15); // Don't ever really do this!
  return first + " " + last;
}

And log output:

V/Example: ⇢ getName(first="Jake", last="Wharton")
V/Example: ⇠ getName [16ms] = "Jake Wharton"

Upvotes: 3

Rishabh Lashkari
Rishabh Lashkari

Reputation: 638

Instead of printing log in every function. I (or most of the people) would suggest you to put debug.

To use debug first create breakpoints inside every function you want to check. To apply breakpoints simply left click in the area to the left of your code (refer image the pink circle represents a break-point).

enter image description here

Then to use Debug you have to press this button after successfully running your application.

enter image description here

As soon as the first method is called your application will pause at the break-point, then you can use F8 (or F6 if you are using eclipse settings) to move to next line, to move to next break-point you can press F9(or F8 if you are using eclipse settings). this way to can check all the functions being called.

This break-point method is really helpful if you just want to make sure that a particular function is being called.

Other than this if you still insist to know the details of all the functions you can store the stacktrace.

  final StackTraceElement[] trace = new Throwable().getStackTrace())
  StackTraceElement   STrace      = trace[1];
  String  className = STrace.getMethodName();

Upvotes: 0

Related Questions