Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pidpersec.c Count new processes (via fork). |
| 3 | * For Linux, uses BCC, eBPF. See the Python front-end. |
| 4 | * |
| 5 | * USAGE: pidpersec.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 | * 11-Aug-2015 Brendan Gregg Created this. |
| 13 | */ |
| 14 | |
| 15 | #include <uapi/linux/ptrace.h> |
| 16 | |
| 17 | enum stat_types { |
| 18 | S_COUNT = 1, |
| 19 | S_MAXSTAT |
| 20 | }; |
| 21 | |
| 22 | BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1); |
| 23 | |
| 24 | void stats_increment(int key) { |
| 25 | u64 *leaf = stats.lookup(&key); |
| 26 | if (leaf) (*leaf)++; |
| 27 | } |
| 28 | |
| 29 | void do_count(struct pt_regs *ctx) { stats_increment(S_COUNT); } |