Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * vfsreadlat.c VFS read latency distribution. |
| 3 | * For Linux, uses BCC, eBPF. See .py file. |
| 4 | * |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 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 | |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 15 | BPF_HASH(start, u32); |
Brendan Gregg | 8d70a88 | 2015-09-25 11:07:23 -0700 | [diff] [blame] | 16 | BPF_HISTOGRAM(dist); |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 17 | |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 18 | int do_entry(struct pt_regs *ctx) |
| 19 | { |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 20 | u32 pid; |
Brendan Gregg | 75f47be | 2015-09-10 12:16:30 -0700 | [diff] [blame] | 21 | u64 ts, *val; |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 22 | |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 23 | pid = bpf_get_current_pid_tgid(); |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 24 | ts = bpf_ktime_get_ns(); |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 25 | start.update(&pid, &ts); |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | int do_return(struct pt_regs *ctx) |
| 30 | { |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 31 | u32 pid; |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 32 | u64 *tsp, delta; |
| 33 | |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 34 | pid = bpf_get_current_pid_tgid(); |
| 35 | tsp = start.lookup(&pid); |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 36 | |
| 37 | if (tsp != 0) { |
| 38 | delta = bpf_ktime_get_ns() - *tsp; |
Brendan Gregg | 8d70a88 | 2015-09-25 11:07:23 -0700 | [diff] [blame] | 39 | dist.increment(bpf_log2l(delta / 1000)); |
Brendan Gregg | f92e668 | 2015-09-10 11:34:28 -0700 | [diff] [blame] | 40 | start.delete(&pid); |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |