Introduction
Introduction
Yabin Cui
android-llvm-dev
Outline
● What is simpleperf
● How simpleperf works
● Simpleperf commands
What is simpleperf
● A replacement for linux/tools/perf in Android
● A cpu-profiler using linux kernel support and PMU (performance monitor unit)
hardware support
● Source code is in
https://android.googlesource.com/platform/system/extras/+/master/simpleperf/
● Doc is in
https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/
● Prebuilt is release in
https://android.googlesource.com/platform/prebuilts/simpleperf/
How simpleperf works
int perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned
long flags)
returns a file descriptor, which can be used to read counter values and records
Kernel support
● pmu drivers
○ register to perf event driver via perf_pmu_register().
○ cpu pmu driver, which operates ARM PMU, lives in drivers/perf.
○ software pmu driver, events like cpu-clock, page-faults, full list is in perf_sw_ids.
○ tracepoint pmu driver, events like sched:sched_switch, full list is in /sys/kernel/tracing/events.
○ device specific pmu drivers.
How simpleperf works
Options:
-p pid1,pid2,... Stat events on existing processes.
-t tid1,tid2,... Stat events on existing threads.
-a Collect system-wide information.
--cpu cpu_item1,cpu_item2,... Collect information only on the selected cpus.
-e event1[:modifier1],event2[:modifier2],... Select a list of events to count.
--duration time_in_sec Monitor for time_in_sec seconds.
stat cmd: example
$ simpleperf stat -e cache-references,cache-misses -a --duration 1
Options:
-p pid1,pid2,... Record events on existing processes.
-t tid1,tid2,... Record events on existing threads.
-a System-wide collection.
--cpu cpu_item1,cpu_item2,... Collect information only on the selected cpus.
-e event1[:modifier1],event2[:modifier2],... Select a list of events to count.
-f freq Set event sample frequency. It means recording at
most [freq] samples every second.
--duration time_in_sec Monitor for time_in_sec seconds
-o record_file_name Set record file name, default is perf.data.
--call-graph fp | dwarf[,<dump_stack_size>] Enable call graph recording.
-g Same as '--call-graph dwarf'.
record cmd: example
$ simpleperf record -g sleep 1
cpu - cpu