forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpidpersec
executable file
·40 lines (34 loc) · 863 Bytes
/
pidpersec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
#
# pidpersec Count new processes (via fork).
# For Linux, uses BCC, eBPF. See .c file.
#
# USAGE: pidpersec
#
# Written as a basic example of counting an event.
#
# Copyright (c) 2015 Brendan Gregg.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 11-Aug-2015 Brendan Gregg Created this.
from bpf import BPF
from ctypes import c_ushort, c_int, c_ulonglong
from time import sleep, strftime
# load BPF program
b = BPF(src_file = "pidpersec.c")
b.attach_kprobe(event="sched_fork", fn_name="do_count")
stats = b.get_table("stats")
# stat indexes
S_COUNT = 1
# header
print("Tracing... Ctrl-C to end.")
# output
last = 0
while (1):
try:
sleep(1)
except KeyboardInterrupt:
pass; exit()
print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
(stats[c_int(S_COUNT)].value - last)))
last = stats[c_int(S_COUNT)].value