Linux profilers: oprofile vs. ftrace (with guide for use in Android)

设置 ftrace

echo function_graph > current_tracer
echo funcgraph-cpu > trace_options
echo funcgraph-proc > trace_options
echo funcgraph-abstime > trace_options
echo nofuncgraph-overhead > trace_options

准备工作

umount tmp
mount -o rw,remount /
mkdir /tmp
mount -t tmpfs none /tmp
echo 0 > tracing_enabled

执行 profiling

cat trace_pipe > /tmp/trace.out &
echo 1 > tracing_enabled
echo 0 > tracing_enabled

程序 3X 时间,大量 lost events,需减少目标函数

echo 'sys_*' > set_ftrace_filter # covers sys_futex (do_futex, futex_wait)
echo '*page*' >> set_ftrace_filter
echo 'sleep_on_*' >> set_ftrace_filter
echo '*wait*' >> set_ftrace_filter
echo '__schedule' >> set_ftrace_filter  # covers schedule, schedule_timeout, poll_schedule_timeout, schedule_hrtimeout_range
echo 'do_fork' >> set_ftrace_filter; echo '!sys_clone' >> set_ftrace_filter # covers kernel_thread
echo 'copy_process' >> set_ftrace_filter
echo 'binder_thread_*' >> set_ftrace_filter # binder_thread_read/write
echo 'do_exit' >> set_ftrace_filter
echo 'do_IRQ' >> set_ftrace_filter
echo 'do_IPI' >> set_ftrace_filter
echo 'do_softirq' >> set_ftrace_filter
echo 'flush_dcache_page' >> set_ftrace_filter # covers __flush_dcache_page
echo 'subsystem_flush_mapped_mem_cache' >> set_ftrace_filter
echo '__atomic_notifier_call_chain' >> set_ftrace_filter # covers atomic_notifier_call_chain
echo 'down_interruptable' >> set_ftrace_filter
echo 'do_local_timer' >> set_ftrace_filter
echo 'load_balance' >> set_ftrace_filter
echo 'rebalance_domains' >> set_ftrace_filter # covers run_rebalance_domains
echo 'sched_move_task' >> set_ftrace_filter
echo '__alloc_pages_nodemask' >> set_ftrace_filter # covers page allocation, __rmqueue
echo '__free_pages' >> set_ftrace_filter # covers __free_page, __free_pages_ok
echo 'mali_mmap' >> set_ftrace_filter
echo 'split_vma' >> set_ftrace_filter
echo 'process_one_work' >> set_ftrace_filter # workers
echo 'do_signal*' >> set_ftrace_filter
echo 'mmc_*' >> set_ftrace_filter
echo 'generic_make_request' >> set_ftrace_filter # main for block layer
echo 'vfs_fsync_range' >> set_ftrace_filter # covers vfs_fsync, do_fsync
echo 'shrink_*' >> set_ftrace_filter # covers try_to_free_pages
echo 'kswapd' >> set_ftrace_filter
echo 'input_event' >> set_ftrace_filter
 

你可能感兴趣的:(android,linux,linux,linux,android,android,ftrace)