-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtps.py
executable file
·72 lines (61 loc) · 1.97 KB
/
rtps.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
import ethtool, procfs, schedutils, sys, time
def show_header():
print "RT threads"
print "%5s %6s %5s %7s %s" % (" ", " ", " ", "thread", "ctxt_switches")
print "%5s %6s %5s %7s %9s %12s %15s %s" % ("pid", "SCHED_", "rtpri", "affinity", "voluntary", "nonvoluntary", "cmd", "IRQ users")
def show(ps, cpuinfo, irqs):
ps_list = []
for pid in ps.keys():
if schedutils.get_scheduler(pid) == 0:
continue
ps_list.append(pid)
ps_list.sort()
nics = ethtool.get_active_devices()
for pid in ps_list:
thread_affinity_list = schedutils.get_affinity(pid)
if len(thread_affinity_list) <= 4:
thread_affinity = ",".join(str(a) for a in thread_affinity_list)
else:
thread_affinity = ",".join(str(hex(a)) for a in procfs.hexbitmask(schedutils.get_affinity(pid), cpuinfo.nr_cpus))
sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
rtprio = int(ps[pid]["stat"]["rt_priority"])
cmd = ps[pid]["stat"]["comm"]
users = ""
if cmd[:4] == "IRQ-":
try:
users = irqs[cmd[4:]]["users"]
for u in users:
if u in nics:
users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
users = ",".join(users)
except:
users = "Not found in /proc/interrupts!"
try:
voluntary_ctxt_switches = int(ps[pid]["status"]["voluntary_ctxt_switches"])
nonvoluntary_ctxt_switches = int(ps[pid]["status"]["nonvoluntary_ctxt_switches"])
except:
voluntary_ctxt_switches = -1
nonvoluntary_ctxt_switches = -1
print "%5d %6s %5d %8s %9d %12s %15s %s" % (pid, sched, rtprio,
thread_affinity,
voluntary_ctxt_switches,
nonvoluntary_ctxt_switches,
cmd, users)
if __name__ == '__main__':
ps = procfs.pidstats()
cpuinfo = procfs.cpuinfo()
irqs = procfs.interrupts()
show_header()
show(ps, cpuinfo, irqs)
try:
interval = int(sys.argv[1])
while True:
time.sleep(interval)
ps.reload()
show_header()
show(ps, cpuinfo, irqs)
except:
pass