ftrace README:
××××:/sys/kernel/debug/tracing # ls
README buffer_size_kb events options saved_cmdlines set_event trace_clock trace_options tracing_on uprobe_profile
available_events buffer_total_size_kb free_buffer per_cpu saved_cmdlines_size set_event_pid trace_marker trace_pipe tracing_thresh
available_tracers current_tracer instances printk_formats saved_tgids trace trace_marker_raw tracing_cpumask uprobe_events
××××:/sys/kernel/debug/tracing # cat README
tracing mini-HOWTO:
# echo 0 > tracing_on : quick way to disable tracing
# echo 1 > tracing_on : quick way to re-enable tracing
Important files:
trace - The static contents of the buffer
To clear the buffer write into this file: echo > trace
trace_pipe - A consuming read to see the contents of the buffer
current_tracer - function and latency tracers
available_tracers - list of configured tracers for current_tracer
buffer_size_kb - view and modify size of per cpu buffer
buffer_total_size_kb - view total size of all cpu buffers
trace_clock -change the clock used to order events
local: Per cpu clock but may not be synced across CPUs
global: Synced across CPUs but slows tracing down.
counter: Not a clock, but just an increment
uptime: Jiffy counter from time of boot
perf: Same clock that perf events use
trace_marker - Writes into this file writes into the kernel buffer
trace_marker_raw - Writes into this file writes binary data into the kernel buffer
tracing_cpumask - Limit which CPUs to trace
instances - Make sub-buffers with: mkdir instances/foo
Remove sub-buffer with rmdir
trace_options - Set format or modify how tracing happens
Disable an option by adding a suffix 'no' to the
option name
saved_cmdlines_size - echo command number in here to store comm-pid list
uprobe_events - Add/remove/show the userspace dynamic events
Write into this file to define/undefine new trace events.
accepts: event-definitions (one definition per line)
Format: p[:[/]] []
r[maxactive][:[/]] []
-:[/]
place: :
args: =fetcharg[:type]
fetcharg: %, @, @[+|-],
$stack, $stack, $retval, $comm
type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,
b@/
events/ - Directory containing all trace event subsystems:
enable - Write 0/1 to enable/disable tracing of all events
events// - Directory containing all trace events for :
enable - Write 0/1 to enable/disable tracing of all
events
filter - If set, only events passing filter are traced
events/// - Directory containing control files for
:
enable - Write 0/1 to enable/disable tracing of
filter - If set, only events passing filter are traced
trigger - If set, a command to perform when event is hit
Format: [:count][if ]
trigger: traceon, traceoff
enable_event::
disable_event::
stacktrace
example: echo traceoff > events/block/block_unplug/trigger
echo traceoff:3 > events/block/block_unplug/trigger
echo 'enable_event:kmem:kmalloc:3 if nr_rq > 1' > \
events/block/block_unplug/trigger
The first disables tracing every time block_unplug is hit.
The second disables tracing the first 3 times block_unplug is hit.
The third enables the kmalloc event the first 3 times block_unplug
is hit and has value of greater than 1 for the 'nr_rq' event field.
Like function triggers, the counter is only decremented if it
enabled or disabled tracing.
To remove a trigger without a count:
echo '! > //trigger
To remove a trigger with a count:
echo '!:0 > //trigger
Filters can be ignored when removing a trigger.
Subsystem:
××××:/sys/kernel/debug/tracing/events # ls
alarmtimer camera dma_fence fib6 hid kgsl module page_isolation process_reclaim rmnet sde_rotator task vmscan
almk cfg80211 drm filelock i2c kmem msm_bus pagefault qdisc rndis_ipa signal thermal wda
android_fs cgroup dwc3 filemap iommu lmh msm_low_power pagemap random rpm skb thermal_virtual workqueue
asoc clk emulation ftrace ion lowmemorykiller msm_pil_event pdc ras rpmh smbus timer writeback
binder cma enable gadget ipa mdio msm_vidc_events percpu raw_syscalls sched sock udp xdp
block compaction exception gpio ipi mdss_pll napi perf_trace_counters rcu scm spi ufs xhci-hcd
bpf cpuhp ext4 header_event irq migrate net power regmap scsi spmi v4l2
bridge dfc fib header_page jbd2 mmc oom printk regulator sde swiotlb vb2
打开 signal trace:
××××:/ # echo 1 > /sys/kernel/debug/tracing/events/signal/enable
××××:/ # echo 1 > /sys/kernel/debug/tracing/tracing_on
获取 trace:
adb pull /sys/kernel/debug/tracing/trace trace.txt
查看/修改 trace buffer大小:
××××:/ # cat /sys/kernel/debug/tracing/buffer_size_kb
1410
××××:/ # cat /sys/kernel/debug/tracing/buffer_total_size_kb
11280
××××:/ # echo 2048 > /sys/kernel/debug/tracing/buffer_size_kb
××××:/ # cat /sys/kernel/debug/tracing/buffer_size_kb
2048
××××:/ # cat /sys/kernel/debug/tracing/buffer_total_size_kb
16384
打开binder相关 trace:
# echo 1 > /sys/kernel/debug/tracing/events/binder/enable
# cat /sys/kernel/debug/tracing/set_event
binder:binder_ioctl
binder:binder_lock
binder:binder_locked
binder:binder_unlock
binder:binder_ioctl_done
binder:binder_write_done
binder:binder_read_done
binder:binder_set_priority
binder:binder_wait_for_work
binder:binder_transaction
binder:binder_transaction_received
binder:binder_transaction_node_to_ref
binder:binder_transaction_ref_to_node
binder:binder_transaction_ref_to_ref
binder:binder_transaction_fd
binder:binder_transaction_alloc_buf
binder:binder_transaction_buffer_release
binder:binder_transaction_failed_buffer_release
binder:binder_update_page_range
binder:binder_alloc_lru_start
binder:binder_alloc_lru_end
binder:binder_free_lru_start
binder:binder_free_lru_end
binder:binder_alloc_page_start
binder:binder_alloc_page_end
binder:binder_unmap_user_start
binder:binder_unmap_user_end
binder:binder_unmap_kernel_start
binder:binder_unmap_kernel_end
binder:binder_command
binder:binder_return
# cat /sys/kernel/debug/tracing/trace
# tracer: nop
#
# entries-in-buffer/entries-written: 22004/22004 #P:8
#
# _-----=> irqs-off
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / delay
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
ndroid.systemui-2043 [001] .... 4311.582476: binder_ioctl: cmd=0xc0306201 arg=0x7ff5dca058
ndroid.systemui-2043 [001] .... 4311.582505: binder_command: cmd=0x40406300 BC_TRANSACTION
ndroid.systemui-2043 [001] .... 4311.582560: binder_transaction: transaction=388872 dest_node=11251 dest_proc=792 dest_thread=0 reply=0 flags=0x11 code=0x3
ndroid.systemui-2043 [001] .... 4311.582571: binder_update_page_range: proc=792 allocate=1 offset=0 size=4096
ndroid.systemui-2043 [001] .... 4311.582578: binder_alloc_lru_start: proc=792 page_index=0
ndroid.systemui-2043 [001] .... 4311.582583: binder_alloc_lru_end: proc=792 page_index=0
ndroid.systemui-2043 [001] .... 4311.582600: binder_transaction_alloc_buf: transaction=388872 data_size=80 offsets_size=0
ndroid.systemui-2043 [001] .... 4311.582718: binder_write_done: ret=0
ndroid.systemui-2043 [001] .... 4311.582727: binder_wait_for_work: proc_work=0 transaction_stack=0 thread_todo=1
ndroid.systemui-2043 [001] .... 4311.582739: binder_return: cmd=0x7206 BR_TRANSACTION_COMPLETE
ndroid.systemui-2043 [001] .... 4311.582755: binder_read_done: ret=0
ndroid.systemui-2043 [001] .... 4311.582762: binder_ioctl_done: ret=0
Binder:792_3-1237 [001] .... 4311.582971: binder_transaction_received: transaction=388872
Binder:792_3-1237 [001] .... 4311.582974: binder_return: cmd=0x80407202 BR_TRANSACTION
Binder:792_3-1237 [001] .... 4311.582991: binder_read_done: ret=0
Binder:792_3-1237 [001] .... 4311.582996: binder_ioctl_done: ret=0
Binder:792_3-1237 [001] .... 4311.583145: binder_ioctl: cmd=0xc0306201 arg=0x7e36fd4328
Binder:792_3-1237 [001] .... 4311.583150: binder_command: cmd=0x40086303 BC_FREE_BUFFER
Binder:792_3-1237 [001] .... 4311.583159: binder_transaction_buffer_release: transaction=388872 data_size=80 offsets_size=0
Binder:792_3-1237 [001] .... 4311.583169: binder_update_page_range: proc=792 allocate=0 offset=0 size=4096
Binder:792_3-1237 [001] .... 4311.583173: binder_free_lru_start: proc=792 page_index=0
Binder:792_3-1237 [001] .... 4311.583177: binder_free_lru_end: proc=792 page_index=0
Binder:792_3-1237 [001] .... 4311.583188: binder_write_done: ret=0
Binder:792_3-1237 [001] .... 4311.583191: binder_wait_for_work: proc_work=1 transaction_stack=0 thread_todo=0
ndroid.systemui-2043 [000] .... 4311.598003: binder_ioctl: cmd=0xc0306201 arg=0x7ff5dca058
ndroid.systemui-2043 [000] .... 4311.598016: binder_command: cmd=0x40406300 BC_TRANSACTION
ndroid.systemui-2043 [000] .... 4311.598051: binder_transaction: transaction=388873 dest_node=11251 dest_proc=792 dest_thread=0 reply=0 flags=0x11 code=0x3
ndroid.systemui-2043 [000] .... 4311.598055: binder_update_page_range: proc=792 allocate=1 offset=0 size=4096
ndroid.systemui-2043 [000] .... 4311.598058: binder_alloc_lru_start: proc=792 page_index=0
ndroid.systemui-2043 [000] .... 4311.598060: binder_alloc_lru_end: proc=792 page_index=0
ndroid.systemui-2043 [000] .... 4311.598074: binder_transaction_alloc_buf: transaction=388873 data_size=80 offsets_size=0
ndroid.systemui-2043 [000] .... 4311.598118: binder_write_done: ret=0
ndroid.systemui-2043 [000] .... 4311.598122: binder_wait_for_work: proc_work=0 transaction_stack=0 thread_todo=1
ndroid.systemui-2043 [000] .... 4311.598127: binder_return: cmd=0x7206 BR_TRANSACTION_COMPLETE
ndroid.systemui-2043 [000] .... 4311.598138: binder_read_done: ret=0
ndroid.systemui-2043 [000] .... 4311.598141: binder_ioctl_done: ret=0