Skip to content

Instantly share code, notes, and snippets.

@tuxology
Last active September 22, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxology/5f62fafbd0f9a44b991b to your computer and use it in GitHub Desktop.
Save tuxology/5f62fafbd0f9a44b991b to your computer and use it in GitHub Desktop.
Ping Latency with ftrace
<idle>-0 [000] d... 318152.015828: do_IRQ <-ret_from_intr
<idle>-0 [000] d.h. 318152.015832: irq_handler_entry: irq=45 name=iwlwifi
<idle>-0 [000] dNh. 318152.015837: sched_wakeup: comm=irq/45-iwlwifi pid=598 prio=49 success=1 target_cpu=000
<idle>-0 [000] d... 318152.015846: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=irq/45-iwlwifi next_pid=598 next_prio=49
irq/45-iwlwifi-598 [000] d.s. 318152.015894: sched_wakeup: comm=ping pid=27782 prio=120 success=1 target_cpu=002
<idle>-0 [002] d... 318152.015943: sched_switch: prev_comm=swapper/2 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=ping next_pid=27782 next_prio=120
ping-27782 [002] .... 318152.015952: sys_exit: NR 47 = 84
ping-27782 [002] .... 318152.015983: sys_exit: NR 1 = 97
#!/bin/bash
TRACE_SUBSYSTEM="/sys/kernel/debug/tracing"
cd $TRACE_SUBSYSTEM
# Start pings
ping suchakra.in -c 10 &
PING_PID=$!
# Clear prev tracer
echo nop > current_tracer
echo 0 > events/enable
# Enable irq and scheduling events
# We also need sys_exit for latency calculations
echo 1 > events/irq/irq_handler_entry/enable
echo 1 > events/sched/sched_wakeup/enable
echo 1 > events/sched/sched_switch/enable
echo 1 > events/sched/sched_pi_setprio/enable
echo 1 > events/raw_syscalls/sys_exit/enable
# Set filters
echo "comm == ping || comm == irq/45-em1 || comm == irq/45-iwlwifi" > events/sched/sched_wakeup/filter
echo "next_comm == ping || next_comm == irq/45-em1 || next_comm == irq/45-iwlwifi" > events/sched/sched_switch/filter
echo "common_pid == $PING_PID" > events/raw_syscalls/sys_exit/filter
# We need do_IRQ as well as IRQ handler starts from here
echo 'do_IRQ' > set_ftrace_filter
echo 'function' > current_tracer
#clear trace
echo > trace
#Switch tracing on and off
echo 1 > /sys/kernel/debug/tracing/tracing_on
sleep 2
echo 0 > /sys/kernel/debug/tracing/tracing_on
kill -9 $PING_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment