-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrtpirq.py
executable file
·88 lines (75 loc) · 2.35 KB
/
rtpirq.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
import ethtool, schedutils, sys, time, procfs, re
def softirq_info(rxtx):
print "\nSoft IRQ net %s info" % rxtx
pids = ps.find_by_regex(re.compile("sirq-net-%s/.*" % rxtx))
if not pids:
pids = ps.find_by_regex(re.compile("softirq-net-%s/.*" % rxtx))
print "%5s %5s %7s" % ("pid", "rtpri", "affinity")
for pid in pids:
affinity = ",".join("%s" % a for a in schedutils.get_affinity(pid))
rtprio = int(ps[pid]["stat"]["rt_priority"])
print "%5d %5d %8s" % (pid, rtprio, affinity)
def show_header():
print "Hard IRQ info"
print "%5s %5s %5s %11s %7s %s" % (" ", " ", " ", " ", "thread", "IRQ")
print "%5s: %5s %5s %11s %7s %7s %s" % ("irq", "pid", "rtpri", "events", "affinity", "affinity", "users")
def show(irqs, ps):
irq_list = []
for sirq in irqs.keys():
try:
irq_list.append(int(sirq))
except:
continue
irq_list.sort()
nics = ethtool.get_active_devices()
for irq in irq_list:
info = irqs[irq]
pids = ps.find_by_name("IRQ-%d" % irq)
if pids:
pid = pids[0]
thread_affinity_list = schedutils.get_affinity(pid)
if len(thread_affinity_list) <= 4:
thread_affinity = ",".join("%s" % a for a in thread_affinity_list)
else:
thread_affinity = ",".join("0x%x" % a for a in procfs.hexbitmask(schedutils.get_affinity(pid), irqs.nr_cpus))
rtprio = int(ps[pid]["stat"]["rt_priority"])
else:
pid = -1
rtprio = -1
thread_affinity = ""
try:
irq_affinity_list = info["affinity"]
if len(irq_affinity_list) <= 4:
irq_affinity = ",".join("%s" % a for a in irq_affinity_list)
else:
irq_affinity = ",".join("0x%x" % a for a in procfs.hexbitmask(irq_affinity_list, irqs.nr_cpus))
except:
irq_affinity = ""
events = reduce(lambda a, b: a + b, info["cpu"])
users = info["users"]
for u in users:
if u in nics:
users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
print "%5d: %5d %5d %11d %8s %8s %s" % (irq, pid, rtprio,
events, thread_affinity,
irq_affinity,
",".join(users))
if __name__ == '__main__':
irqs = procfs.interrupts()
ps = procfs.pidstats()
show_header()
show(irqs, ps)
try:
interval = int(sys.argv[1])
while True:
time.sleep(interval)
irqs.reload()
ps.reload()
show_header()
show(irqs, ps)
except:
for direction in [ "rx", "tx" ]:
softirq_info(direction)