Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * vfscount.c Count some VFS calls. |
| 3 | * For Linux, uses BCC, eBPF. See the Python front-end. |
| 4 | * |
| 5 | * USAGE: vfscount.py |
| 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 | struct key_t { |
| 18 | u64 ip; |
| 19 | }; |
| 20 | |
| 21 | BPF_TABLE("hash", struct key_t, u64, counts, 256); |
| 22 | |
| 23 | int do_count(struct pt_regs *ctx) { |
| 24 | struct key_t key = {}; |
| 25 | u64 zero = 0, *val; |
| 26 | key.ip = ctx->ip; |
| 27 | val = counts.lookup_or_init(&key, &zero); |
| 28 | (*val)++; |
| 29 | return 0; |
| 30 | } |