3

In Android OS source code (Path: /drivers/staging/android/binder_trace.h), we have a file named binder_trace.h and also in /drivers/staging/android/binder.c binder_trace is included. As we can see in binder_trace.h file, the binder transactions are traced with TP_printk instruction.

Now my question is that how I can see these kernel logs in my phone with adb shell? Also there isn't any file related to binder tracing in /sys/kernel/debug/tracing directory!

Onik
  • 19,396
  • 14
  • 68
  • 91
Cert
  • 99
  • 1
  • 2
  • 9

3 Answers3

8
$ cd /sys/kernel/debug/tracing
$ echo > set_event  # clear all unrelated events
$ echo 1 > events/binder/enable
$ echo 1 > tracing_on

# .. do your test jobs ..

$ cat trace

refer to https://android.googlesource.com/kernel/common/+/android-3.10.y/Documentation/trace/ftrace.txt for more detail info.

Yingchun
  • 303
  • 4
  • 13
  • That link no longer works. Here is a slightly more recent link that works: https://android.googlesource.com/kernel/common/+/android-3.18/Documentation/trace/ftrace.txt – ThomasW Jun 19 '19 at 06:10
  • I had to change /sys/kernel/debug/tracing to /sys/kernel/tracing in the first command above – matvore Mar 06 '23 at 23:37
1

This is not exactly an answer to the original question, but the Binder Java class implements a tracing mechanism which can be useful for identifying the exact Java method being invoked over a binder connection. This tracing can be enabled globally via Activity Manager using am shell command.

  1. Start tracing: adb shell am trace-ipc start
  2. Perform the scenario you're interested in.
  3. Stop binder tracing: adb shell am trace-ipc stop --dump-file /data/local/tmp/trace-ipc.txt
  4. Copy the dump file off of the device: adb pull /data/local/tmp/trace-ipc.txt

The trace-ipc.txt file contains call stacks for all of the Binder calls made via the Binder class along with the number of times each call was made.

Conveniently, enabling this tracing also emits trace events describing the method being invoked. These events can be viewed with systrace and Perfetto.

-1

To see the kernel log use the dmesg command:

adb shell
# dmesg
Liran Ben Haim
  • 436
  • 3
  • 10
  • So it should be in debugfs. Try mount command to see if it's mounted and where. Should be in /sys/kernel/debug/tracing. Use cat command with the file "trace" – Liran Ben Haim Apr 06 '16 at 20:13
  • I mentioned that " there isn't any file related to binder tracing in /sys/kernel/debug/tracing directory!" – Cert Apr 07 '16 at 06:33
  • Yes. I saw it there should be a file named "trace" and also files named "current_tracer" and "available_traces". Use the cat command to read that files and echo to set. You should see the binder trace in the output of the trace file – Liran Ben Haim Apr 07 '16 at 06:40
  • I monitored the trace file but unfortunately there isn't any binder trace! – Cert Apr 07 '16 at 06:45
  • what is the output of available_trace file? – Liran Ben Haim Apr 07 '16 at 06:46
  • Available Tracers Output: sched_switch nop – Cert Apr 07 '16 at 07:18
  • Try this, Open the kernel configuration (make menuconfig) , go to kernel hacking -> Traces , here you can find all the FTRACE options. – Liran Ben Haim Apr 07 '16 at 07:33
  • For that, do I need to compile the kernel? – Cert Apr 07 '16 at 07:39
  • Yes, you should select everything in that sub menu, compile the kernel and maybe also define the trace constant in the kernel code (i had once situation that i had to hard coded define it) – Liran Ben Haim Apr 07 '16 at 07:43