1 |
# |
---|
2 |
# Copyright (C) 2008 Pieter Palmers |
---|
3 |
# |
---|
4 |
# This program is free software: you can redistribute it and/or modify |
---|
5 |
# it under the terms of the GNU General Public License as published by |
---|
6 |
# the Free Software Foundation, version 3 of the License. |
---|
7 |
# |
---|
8 |
# This program is distributed in the hope that it will be useful, |
---|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 |
# GNU General Public License for more details. |
---|
12 |
# |
---|
13 |
# You should have received a copy of the GNU General Public License |
---|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 |
# |
---|
16 |
|
---|
17 |
import os |
---|
18 |
import re |
---|
19 |
|
---|
20 |
# Allow for the movement of getstatusoutput from the "commands" module (in |
---|
21 |
# python2) to the "subprocess" module in python3. |
---|
22 |
try: |
---|
23 |
from subprocess import getstatusoutput |
---|
24 |
except ImportError: |
---|
25 |
from commands import getstatusoutput |
---|
26 |
|
---|
27 |
LISTIRQINFO_VERSION="0.3" |
---|
28 |
|
---|
29 |
def sortedDictValues(adict): |
---|
30 |
items = sorted(adict.items()) |
---|
31 |
return [value for key, value in items] |
---|
32 |
|
---|
33 |
class IRQ: |
---|
34 |
def __init__(self): |
---|
35 |
self.number = None |
---|
36 |
self.scheduling_class = None |
---|
37 |
self.scheduling_priority = None |
---|
38 |
self.process_id = None |
---|
39 |
self.drivers = [] |
---|
40 |
self.cpu_counts = [] |
---|
41 |
def __str__(self): |
---|
42 |
s = " IRQ %4s: PID: %5s, count: %18s, Sched %4s (priority %4s), drivers: %s" % \ |
---|
43 |
(self.number, self.process_id, self.cpu_counts, |
---|
44 |
self.scheduling_class, self.scheduling_priority, |
---|
45 |
self.drivers) |
---|
46 |
return s |
---|
47 |
|
---|
48 |
class SoftIRQ: |
---|
49 |
def __init__(self): |
---|
50 |
self.name = None |
---|
51 |
self.fullname = None |
---|
52 |
self.scheduling_class = None |
---|
53 |
self.scheduling_priority = None |
---|
54 |
self.process_id = None |
---|
55 |
self.cpu_counts = [] |
---|
56 |
def __str__(self): |
---|
57 |
s = " SoftIRQ %12s: PID %6s, Sched %4s (priority %4s), name: %s" % \ |
---|
58 |
(self.name, self.process_id ,self.scheduling_class, self.scheduling_priority, self.fullname) |
---|
59 |
return s |
---|
60 |
|
---|
61 |
class IRQInfo: |
---|
62 |
def __init__(self): |
---|
63 |
self.softIRQs = {} |
---|
64 |
self.IRQs = {} |
---|
65 |
|
---|
66 |
def load(self): |
---|
67 |
# get PID info |
---|
68 |
(exitstatus, outtext) = getstatusoutput('ps -eLo pid,cmd,class,rtprio | grep IRQ') |
---|
69 |
|
---|
70 |
rawstr = r"""([0-9]+) +\[IRQ-([0-9]+)\] +([A-Z]{2}) +([-0-9]+)""" |
---|
71 |
compile_obj = re.compile(rawstr) |
---|
72 |
|
---|
73 |
IRQs = {} |
---|
74 |
for line in outtext.splitlines(): |
---|
75 |
match_obj = compile_obj.search(line) |
---|
76 |
if match_obj: |
---|
77 |
irq = IRQ() |
---|
78 |
irq.process_id = int(match_obj.group(1)) |
---|
79 |
irq.number = int(match_obj.group(2)) |
---|
80 |
irq.scheduling_class = match_obj.group(3) |
---|
81 |
if match_obj.group(4) != '-': |
---|
82 |
irq.scheduling_priority = int(match_obj.group(4)) |
---|
83 |
else: |
---|
84 |
irq.scheduling_priority = None |
---|
85 |
IRQs[irq.number] = irq |
---|
86 |
|
---|
87 |
(exitstatus, outtext) = getstatusoutput('ps -eLo pid,cmd,class,rtprio | grep softirq') |
---|
88 |
|
---|
89 |
rawstr = r"""([0-9]+) +\[softirq-(.*)\] +([A-Z]+) +([-0-9]+)""" |
---|
90 |
compile_obj = re.compile(rawstr) |
---|
91 |
|
---|
92 |
softIRQs = {} |
---|
93 |
for line in outtext.splitlines(): |
---|
94 |
match_obj = compile_obj.search(line) |
---|
95 |
if match_obj: |
---|
96 |
irq = SoftIRQ() |
---|
97 |
irq.process_id = int(match_obj.group(1)) |
---|
98 |
irq.name = "%s-%s" % (match_obj.group(2),irq.process_id) |
---|
99 |
irq.fullname = "softirq-%s" % match_obj.group(2) |
---|
100 |
irq.scheduling_class = match_obj.group(3) |
---|
101 |
if match_obj.group(4) != '-': |
---|
102 |
irq.scheduling_priority = int(match_obj.group(4)) |
---|
103 |
else: |
---|
104 |
irq.scheduling_priority = None |
---|
105 |
softIRQs[irq.name] = irq |
---|
106 |
|
---|
107 |
# get irq info |
---|
108 |
(exitstatus, outtext) = getstatusoutput('cat /proc/interrupts') |
---|
109 |
lines = outtext.splitlines() |
---|
110 |
nb_cpus = len(lines[0].split()) |
---|
111 |
str0 = "([0-9]+): +"; |
---|
112 |
str_cpu = "([0-9]+) +" |
---|
113 |
str1="([\w\-]+) +([\w\-, :]+)" |
---|
114 |
|
---|
115 |
rawstr = str0; |
---|
116 |
for i in range(nb_cpus): |
---|
117 |
rawstr += str_cpu |
---|
118 |
rawstr += str1 |
---|
119 |
compile_obj = re.compile(rawstr) |
---|
120 |
|
---|
121 |
for line in outtext.splitlines(): |
---|
122 |
match_obj = compile_obj.search(line) |
---|
123 |
if match_obj: |
---|
124 |
irq_number = int(match_obj.group(1)) |
---|
125 |
if not irq_number in IRQs.keys(): |
---|
126 |
IRQs[irq_number] = IRQ() |
---|
127 |
IRQs[irq_number].number = irq_number |
---|
128 |
|
---|
129 |
irq = IRQs[irq_number] |
---|
130 |
cpu_counts = [] |
---|
131 |
for i in range(nb_cpus): |
---|
132 |
cpu_counts.append(int(match_obj.group(i + 2))) |
---|
133 |
irq.cpu_counts = cpu_counts |
---|
134 |
irq.type = match_obj.group(nb_cpus + 2) |
---|
135 |
drivers = match_obj.group(nb_cpus + 3).split(',') |
---|
136 |
for driver in drivers: |
---|
137 |
irq.drivers.append(driver.strip()) |
---|
138 |
|
---|
139 |
IRQs[irq.number] = irq |
---|
140 |
|
---|
141 |
self.softIRQs = softIRQs |
---|
142 |
self.IRQs = IRQs |
---|
143 |
|
---|
144 |
def __str__(self): |
---|
145 |
s = "" |
---|
146 |
s += "Hardware Interrupts:\n" |
---|
147 |
s += "--------------------\n" |
---|
148 |
|
---|
149 |
for irq in sortedDictValues(self.IRQs): |
---|
150 |
s += str(irq) + "\n" |
---|
151 |
|
---|
152 |
s += "\n" |
---|
153 |
s += "Software Interrupts:\n" |
---|
154 |
s += "--------------------\n" |
---|
155 |
for irq in sortedDictValues(self.softIRQs): |
---|
156 |
s += str(irq) + "\n" |
---|
157 |
|
---|
158 |
return s |
---|
159 |
|
---|
160 |
if __name__== '__main__': |
---|
161 |
|
---|
162 |
print( "" ) |
---|
163 |
print( "Interrupt list utility " + LISTIRQINFO_VERSION ) |
---|
164 |
print( "==========================" ) |
---|
165 |
print( "(C) 2008 Pieter Palmers" ) |
---|
166 |
print( "" ) |
---|
167 |
|
---|
168 |
info = IRQInfo() |
---|
169 |
|
---|
170 |
info.load() |
---|
171 |
print( str(info) ) |
---|
172 |
|
---|
173 |
print( "" ) |
---|