Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | enum stat_types { |
| 18 | S_READ = 1, |
| 19 | S_WRITE, |
| 20 | S_FSYNC, |
| 21 | S_OPEN, |
| 22 | S_CREATE, |
| 23 | S_MAXSTAT |
| 24 | }; |
| 25 | |
| 26 | BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1); |
| 27 | |
| 28 | void stats_increment(int key) { |
| 29 | u64 *leaf = stats.lookup(&key); |
| 30 | if (leaf) (*leaf)++; |
| 31 | } |
| 32 | |
| 33 | void do_read(struct pt_regs *ctx) { stats_increment(S_READ); } |
| 34 | void do_write(struct pt_regs *ctx) { stats_increment(S_WRITE); } |
| 35 | void do_fsync(struct pt_regs *ctx) { stats_increment(S_FSYNC); } |
| 36 | void do_open(struct pt_regs *ctx) { stats_increment(S_OPEN); } |
| 37 | void do_create(struct pt_regs *ctx) { stats_increment(S_CREATE); } |