Using Strace

Strace enables you to see the system calls a
process makes and what those system calls return. A typical process makes a lot
of system calls, so you'll want to review the
strace man page
to learn how to collect only data you're actually interested in.

Building strace

To build strace, run the following:

mmma -j6 external/strace

Attaching to a running process

The simplest and most common use case for strace is to attach it to a running
process, which you can do with:

adb shell strace -f -p PID

The -f flag tells strace to attach to all the threads in the
process, plus any new threads spawned later.

Getting strace logs during Android boot

To get strace logs during Android boot, make the following changes:

Since the process name changes from zygote to
strace, the given service may fail to start due to the missing
SELinux file_context for strace. The solution is to
add a new line for strace in system/sepolicy/private/file_contexts
and copy the original file context over. Example:

Add kernel command, then boot the device in SELinux permissive mode. You can
do this by adding androidboot.selinux=permissiveto
BOARD_KERNEL_CMDLINE. (This variable becomes read-only in
build/core/Makefile but is always available under
/device/*/BoardConfig.)

Example for the Pixel (sailfish) device in
/device/google/marlin/sailfish/BoardConfig.mk: