| 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 |
LISTIRQINFO_VERSION="0.3" |
|---|
| 25 |
|
|---|
| 26 |
def sortedDictValues(adict): |
|---|
| 27 |
items = adict.items() |
|---|
| 28 |
items.sort() |
|---|
| 29 |
return [value for key, value in items] |
|---|
| 30 |
|
|---|
| 31 |
class IRQ: |
|---|
| 32 |
def __init__(self): |
|---|
| 33 |
self.number = None |
|---|
| 34 |
self.scheduling_class = None |
|---|
| 35 |
self.scheduling_priority = None |
|---|
| 36 |
self.process_id = None |
|---|
| 37 |
self.drivers = [] |
|---|
| 38 |
self.cpu_counts = [] |
|---|
| 39 |
def __str__(self): |
|---|
| 40 |
s = " IRQ %4s: PID: %5s, count: %18s, Sched %4s (priority %4s), drivers: %s" % \ |
|---|
| 41 |
(self.number, self.process_id, self.cpu_counts, |
|---|
| 42 |
self.scheduling_class, self.scheduling_priority, |
|---|
| 43 |
self.drivers) |
|---|
| 44 |
return s |
|---|
| 45 |
|
|---|
| 46 |
class SoftIRQ: |
|---|
| 47 |
def __init__(self): |
|---|
| 48 |
self.name = None |
|---|
| 49 |
self.fullname = None |
|---|
| 50 |
self.scheduling_class = None |
|---|
| 51 |
self.scheduling_priority = None |
|---|
| 52 |
self.process_id = None |
|---|
| 53 |
self.cpu_counts = [] |
|---|
| 54 |
def __str__(self): |
|---|
| 55 |
s = " SoftIRQ %12s: PID %6s, Sched %4s (priority %4s), name: %s" % \ |
|---|
| 56 |
(self.name, self.process_id ,self.scheduling_class, self.scheduling_priority, self.fullname) |
|---|
| 57 |
return s |
|---|
| 58 |
|
|---|
| 59 |
class IRQInfo: |
|---|
| 60 |
def __init__(self): |
|---|
| 61 |
self.softIRQs = {} |
|---|
| 62 |
self.IRQs = {} |
|---|
| 63 |
|
|---|
| 64 |
def load(self): |
|---|
| 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 |
self.softIRQs = softIRQs |
|---|
| 140 |
self.IRQs = IRQs |
|---|
| 141 |
|
|---|
| 142 |
def __str__(self): |
|---|
| 143 |
s = "" |
|---|
| 144 |
s += "Hardware Interrupts:\n" |
|---|
| 145 |
s += "--------------------\n" |
|---|
| 146 |
|
|---|
| 147 |
for irq in sortedDictValues(self.IRQs): |
|---|
| 148 |
s += str(irq) + "\n" |
|---|
| 149 |
|
|---|
| 150 |
s += "\n" |
|---|
| 151 |
s += "Software Interrupts:\n" |
|---|
| 152 |
s += "--------------------\n" |
|---|
| 153 |
for irq in sortedDictValues(self.softIRQs): |
|---|
| 154 |
s += str(irq) + "\n" |
|---|
| 155 |
|
|---|
| 156 |
return s |
|---|
| 157 |
|
|---|
| 158 |
if __name__== '__main__': |
|---|
| 159 |
|
|---|
| 160 |
print "" |
|---|
| 161 |
print "Interrupt list utility " + LISTIRQINFO_VERSION |
|---|
| 162 |
print "==========================" |
|---|
| 163 |
print "(C) 2008 Pieter Palmers" |
|---|
| 164 |
print "" |
|---|
| 165 |
|
|---|
| 166 |
info = IRQInfo() |
|---|
| 167 |
|
|---|
| 168 |
info.load() |
|---|
| 169 |
print str(info) |
|---|
| 170 |
|
|---|
| 171 |
print "" |
|---|