vfsreadlat.c 975 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * vfsreadlat.c		VFS read latency distribution.
 *			For Linux, uses BCC, eBPF. See .py file.
 *
 * Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * 15-Aug-2015	Brendan Gregg	Created this.
 */

#include <uapi/linux/ptrace.h>

15
BPF_HASH(start, u32);
16 17 18 19
BPF_TABLE("array", int, u64, dist, 64);

int do_entry(struct pt_regs *ctx)
{
20
	u32 pid;
Brendan Gregg's avatar
Brendan Gregg committed
21
	u64 ts, *val;
22

23
	pid = bpf_get_current_pid_tgid();
24
	ts = bpf_ktime_get_ns();
25
	start.update(&pid, &ts);
26 27 28 29 30
	return 0;
}

int do_return(struct pt_regs *ctx)
{
31
	u32 pid;
32 33
	u64 *tsp, delta;

34 35
	pid = bpf_get_current_pid_tgid();
	tsp = start.lookup(&pid);
36 37 38

	if (tsp != 0) {
		delta = bpf_ktime_get_ns() - *tsp;
Brendan Gregg's avatar
Brendan Gregg committed
39
		int index = bpf_log2l(delta / 1000);
40 41
		u64 *leaf = dist.lookup(&index);
		if (leaf) (*leaf)++;
42
		start.delete(&pid);
43 44 45 46
	}

	return 0;
}