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