-
Notifications
You must be signed in to change notification settings - Fork 478
uftrace on Android
Currently uftrace is not running properly under Android.
This document provides a brief introduction to how uftrace can be built and run on Android.
Running uftrace on Android can be done in several ways (context).
-
chroot'ed(?) env. (eg. inside termux app)
- install uftrace package on Termux
- compile uftrace from source on Termux
-
system shell env. (ADB)
- run uftrace binary under chroot'ed env
- build uftace as NDK binary
-
AOSP 10 - Android Q
-
Google Pixel (aarch64)
- Android: aosp_sailfish-eng 10 (android-10.0.0_r1)
- Kernel: 3.18.137 (fixed to 3.18.x)
-
Virtual Device cuttlefish (x86)
- Android: aosp_cf_x86_phone (aosp_master@eef9850)
- Kernel: 5.4.6 (stock kernel. custom kernel available)
To compile AOSP, follow instruction under AOSP Document.
For sudo permission in adb shell, build AOSP with userdebug
or eng
varients.
If you're trying to test on cuttlefish Virtual Device, you don't have to compile it. Jump to Setting up Cuttlefish.
The stock kernel included in Android doesn't support with ftrace function tracer.
In order to use kernel tracing with uftrace, you should compile kernel with FUNCTION_TRACER option enabled.
- CONFIG_FUNCTION_TRACER=y
- CONFIG_DYNAMIC_FTRACE=y
Follow instruction for compiling AOSP kernel
For more information: AOSP Dynamic Ftrace
For every Android phone in the world, there are different procedures for installing AOSP (unlock phone) and there might be even impossible phones. So in this section will only briefly cover the concepts.
- Unlock your phone's bootloader : Search Here
- Get or build AOSP image
- Boot your device with fastboot : adb reboot fastboot
- Flash image to your phone with fastboot : fastboot flash
To find the proper way to prepare AOSP on your device, Google it.
- Build cuttlefish host tool (like emulator)
git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
debuild -i -us -uc -b
sudo dpkg -i ../cuttlefish-common_*_amd64.deb
sudo apt-get install -f
- Get cuttlefish AOSP image from Android CI
- From
aosp-master
branch, click aosp_cf_x86_phoneuserdebug
varient - At Artifacts tab, download below files
aosp_cf_x86_phone-img-xxxxxx.zip
cvd-host_package.tar.gz
- From
- Extract downloaded files
mkdir cf && cd cf
tar xvf /path/to/cvd-host_package.tar.gz
unzip /path/to/aosp_cf_x86_phone-img-xxxxxx.zip
- Run cuttlefish virtual machine
HOME=$PWD ./bin/launch_cvd
# To boot with custom compiled kernel, use -kernel-path option
# HOME=$PWD ./bin/launch_cvd -kernel_path /path/to/kernel/../x86/boot/bzImage
# If the graphic is slow, try below option
# HOME=$PWD ./bin/launch_cvd -gpu_mode=drm_virgl
- Connect cuttlefish with VNC
To view the screen, use VNC client to access localhost 6444 port.
java -jar tightvnc-jviewer.jar -ScalingFactor=50 -Tunneling=no -host=localhost -port=6444
For more information: cuttlefish git
- Download Termux APK: F-droid Store
- Install APK with ADB
adb install com.termux*.apk
- Open termux app
There is already Uftrace Package in the Termux package repo.
pkg update
pkg install uftrace
uftrace --version
# uftrace v0.9.3 ( python tui perf sched dynamic )
For using latest feature of uftrace, compile inside termux.
Since termux doesn't have gcc
, use clang
instead. (gcc available with unofficial repo).
To meet the dependency requirements, install below pacakges.
pkg-config
libelf
python
capstone
libluajit
pkg update
pkg install git make clang
pkg install pkg-config libelf python capstone libluajit
./configure --prefix=$PREFIX
make -j 8
# WILL FAIL! Source code and LDFLAGS modification needed.
# libandroid-spawn, argp, shmem etc..
Thanks to contributor @gonapps, there's a demo for compiling and running uftrace on Android.
(The demo below is different from the environment in this document)
For custom compile, refer to Termux package build script:
https://github.com/termux/termux-packages/tree/master/packages/uftrace
From termux app, run uftrace.
uftrace --version
# uftrace v0.9.3 ( python tui perf sched dynamic )
From the Host side, elevate to root permission and execute uftrace under termux directory.
(su
is allowed only on AOSP phonedebug
, eng
varient.)
# From Host side, type:
adb shell
# Connect into android system shell
# vsoc_x86:/ $
whoami # shell
su
whoami # root
export PREFIX=/data/data/com.termux/files/usr
$PREFIX/bin/uftrace -L $PREFIX/lib --version
# uftrace v0.9.3 ( python tui perf sched dynamic )
Since termux environment doesn't have symbols for mcount
, compile with -pg
option will fail.
When compiling sources inside termux, compile with -lmcount
option.
# clang is binded to gcc
gcc -pg $PREFIX/uftrace/tests/s-abc.c
# ============= Result Truncated =============
# $PREFIX/bin/aarch64-linux-android-ld: $PREFIX/tmp/s-abc-833b6b.o: in function `c':
# s-abc.c:(.text+0xcc): undefined reference to `_mcount'
# clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
gcc -pg -lmcount $PREFIX/uftrace/tests/s-abc.c
uftrace record a.out
uftrace replay
## DURATION TID FUNCTION
# [ 2163] | main() {
# [ 2163] | a() {
# [ 2163] | b() {
# 0.880 us [ 2163] | c();
# 3.475 us [ 2163] | } /* b */
# 4.448 us [ 2163] | } /* a */
# 5.631 us [ 2163] | } /* main */
- Home
- Tutorial
- Development
- Practical Use Cases
- GCC
- Clang/LLVM
- Node.js
- Chromium
- MySQL/InnoDB
- FFmpeg
- CPython
- POCO
- Telegram
- yara
- RustPython
- cURL
- bpftrace
- SpiderMonkey
- Apache HTTP Server
- GStreamer
- Squid
- TCPDUMP
- OpenCV
- Libav
- Wireshark
- LXC
- Git
- Radare2
- uftrace on Android
- deno
- parallel sort algorithm
- LevelDB/RocksDB (YCSB)
- Redis
- libjpeg‐turbo (JPEG)
- JM (H.264/AVC)
- HM (HEVC)
- VTM (VVC)
- CUDA
- Erlang/OTP BEAM
- uftrace on Yocto
- TTCN3