#!/usr/bin/env bpftrace /** * Print durations and invocations * Call this script with the duration in seconds as argument * e.g. bpftrace func_benchmark.bt 30 */ //tracepoint:sched:sched_wakeup fentry:try_to_wake_up { if(args->p->mm != 0) { @_mms[args->p->mm] = true; @_processes[args->p->tgid] = true; @_threads[args->p->pid] = true; } } fentry:task_mm_cid_work { @start[tid] = nsecs; @preemptions[tid] = (uint64)0; } fexit:task_mm_cid_work /@start[tid]/ { $curr_preemption = @preempted[tid] ? @preemptions[tid] : 0; $duration = (nsecs - @start[tid] - $curr_preemption)/1000; @durations = lhist($duration, 10, 100, 5); @duration_total = stats($duration); @duration_max = max($duration); delete(@start[tid]); delete(@preemptions[tid]); delete(@preempted[tid]); } /* Support only one preemption, should be fine for non-sleeping functions */ tracepoint:sched:sched_switch // /@start[args.prev_pid] || @start[args.next_pid]/ { if (@start[args.prev_pid]) { @preempted[args.prev_pid] = true; @preemptions[args.prev_pid] = nsecs; } if (@start[args.next_pid] && @preempted[args.next_pid]) { @preemptions[args.next_pid] = nsecs - @preemptions[args.next_pid]; } } //interval:s:30 interval:s:$1 { exit(); } END { @mms = len(@_mms); @processes = len(@_processes); @threads = len(@_threads); clear(@_mms); clear(@_processes); clear(@_threads); clear(@start); clear(@preemptions); clear(@preempted); }