blob: 77da22e570274a9ebc25386faf50d48d93c63767 [file] [log] [blame]
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07001/*
2 * vfsreadlat.c VFS read latency distribution.
3 * For Linux, uses BCC, eBPF. See .py file.
4 *
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07005 * 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 Greggf92e6682015-09-10 11:34:28 -070015BPF_HASH(start, u32);
Brendan Gregg8d70a882015-09-25 11:07:23 -070016BPF_HISTOGRAM(dist);
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070017
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070018int do_entry(struct pt_regs *ctx)
19{
Brendan Greggf92e6682015-09-10 11:34:28 -070020 u32 pid;
Brendan Gregg75f47be2015-09-10 12:16:30 -070021 u64 ts, *val;
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070022
Brendan Greggf92e6682015-09-10 11:34:28 -070023 pid = bpf_get_current_pid_tgid();
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070024 ts = bpf_ktime_get_ns();
Brendan Greggf92e6682015-09-10 11:34:28 -070025 start.update(&pid, &ts);
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070026 return 0;
27}
28
29int do_return(struct pt_regs *ctx)
30{
Brendan Greggf92e6682015-09-10 11:34:28 -070031 u32 pid;
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070032 u64 *tsp, delta;
33
Brendan Greggf92e6682015-09-10 11:34:28 -070034 pid = bpf_get_current_pid_tgid();
35 tsp = start.lookup(&pid);
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070036
37 if (tsp != 0) {
38 delta = bpf_ktime_get_ns() - *tsp;
Brendan Gregg8d70a882015-09-25 11:07:23 -070039 dist.increment(bpf_log2l(delta / 1000));
Brendan Greggf92e6682015-09-10 11:34:28 -070040 start.delete(&pid);
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070041 }
42
43 return 0;
44}