blob: d72047e34650bdb116f8173d79cdd7b380590712 [file] [log] [blame]
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07001/*
2 * vfsstat.c Count some VFS calls.
3 * For Linux, uses BCC, eBPF. See the Python front-end.
4 *
5 * USAGE: vfsstat.py [interval [count]]
6 *
7 * Copyright (c) 2015 Brendan Gregg.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
11 *
12 * 14-Aug-2015 Brendan Gregg Created this.
13 */
14
15#include <uapi/linux/ptrace.h>
16
17enum stat_types {
18 S_READ = 1,
19 S_WRITE,
20 S_FSYNC,
21 S_OPEN,
22 S_CREATE,
23 S_MAXSTAT
24};
25
26BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
27
28void stats_increment(int key) {
29 u64 *leaf = stats.lookup(&key);
30 if (leaf) (*leaf)++;
31}
32
33void do_read(struct pt_regs *ctx) { stats_increment(S_READ); }
34void do_write(struct pt_regs *ctx) { stats_increment(S_WRITE); }
35void do_fsync(struct pt_regs *ctx) { stats_increment(S_FSYNC); }
36void do_open(struct pt_regs *ctx) { stats_increment(S_OPEN); }
37void do_create(struct pt_regs *ctx) { stats_increment(S_CREATE); }