1 /* 2 * vfsreadlat.c VFS read latency distribution. 3 * For Linux, uses BCC, eBPF. See .py file. 4 * 5 * Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2 of the GNU General Public 8 * License as published by the Free Software Foundation. 9 * 10 * 15-Aug-2015 Brendan Gregg Created this. 11 */ 12 13 #include <uapi/linux/ptrace.h> 14 15 BPF_HASH(start, u32); 16 BPF_HISTOGRAM(dist); 17 do_entry(struct pt_regs * ctx)18int do_entry(struct pt_regs *ctx) 19 { 20 u32 pid; 21 u64 ts, *val; 22 23 pid = bpf_get_current_pid_tgid(); 24 ts = bpf_ktime_get_ns(); 25 start.update(&pid, &ts); 26 return 0; 27 } 28 do_return(struct pt_regs * ctx)29int do_return(struct pt_regs *ctx) 30 { 31 u32 pid; 32 u64 *tsp, delta; 33 34 pid = bpf_get_current_pid_tgid(); 35 tsp = start.lookup(&pid); 36 37 if (tsp != 0) { 38 delta = bpf_ktime_get_ns() - *tsp; 39 dist.increment(bpf_log2l(delta / 1000)); 40 start.delete(&pid); 41 } 42 43 return 0; 44 } 45