root/trunk/libffado/support/tools/listirqinfo.py

Revision 895, 2.0 kB (checked in by ppalmers, 15 years ago)

add irq listing tool

  • Property svn:executable set to *
Line 
1 #!/usr/bin/python
2 #
3
4 import os
5 import commands
6 import re
7
8 class IRQ:
9         def __init__(self):
10                 self.number = None
11                 self.scheduling_class = None
12                 self.scheduling_priority = None
13                 self.process_id = None
14                 self.drivers = []
15                 self.cpu_counts = []
16         def __str__(self):
17                 s = "IRQ %4s: PID %6s, Sched %4s (priority %4s), drivers: %s" % \
18                     (self.number, self.process_id ,self.scheduling_class, self.scheduling_priority, self.drivers)
19                 return s
20
21 def sortedDictValues(adict):
22     items = adict.items()
23     items.sort()
24     return [value for key, value in items]
25
26
27
28 # get PID info
29 (exitstatus, outtext) = commands.getstatusoutput('ps -eLo pid,cmd,class,rtprio | grep IRQ')
30
31 rawstr = r"""([0-9]+) +\[IRQ-([0-9]+)\] +([A-F]{2}) +([0-9]+)"""
32 compile_obj = re.compile(rawstr)
33
34 IRQs = {}
35 for line in outtext.splitlines():
36         match_obj = compile_obj.search(line)
37         if match_obj:
38                 irq = IRQ()
39                 irq.process_id = int(match_obj.group(1))
40                 irq.number = int(match_obj.group(2))
41                 irq.scheduling_class = match_obj.group(3)
42                 irq.scheduling_priority = int(match_obj.group(4))
43                 IRQs[irq.number] = irq
44
45 # get PID info
46 (exitstatus, outtext) = commands.getstatusoutput('cat /proc/interrupts')
47 lines = outtext.splitlines()
48 nb_cpus = len(lines[0].split())
49 str0 = "([0-9]+): +";
50 str_cpu = "([0-9]+) +"
51 str1="([\w\-]+) +([\w\-, :]+)"
52
53 rawstr = str0;
54 for i in range(nb_cpus):
55         rawstr += str_cpu
56 rawstr += str1
57 compile_obj = re.compile(rawstr)
58
59 for line in outtext.splitlines():
60         match_obj = compile_obj.search(line)
61         if match_obj:
62                 irq_number = int(match_obj.group(1))
63                 if not irq_number in IRQs.keys():
64                         IRQs[irq_number] = IRQ()
65                         IRQs[irq_number].number = irq_number
66                
67                 irq = IRQs[irq_number]
68                 cpu_counts = []
69                 for i in range(nb_cpus):
70                         cpu_counts.append(int(match_obj.group(1 + 1)))
71                 irq.cpu_counts = cpu_counts
72                 irq.type = match_obj.group(nb_cpus + 2)
73                 drivers = match_obj.group(nb_cpus + 3).split(',')
74                 for driver in drivers:
75                         irq.drivers.append(driver.strip())
76
77                 IRQs[irq.number] = irq
78
79 print "Interrupt list: "
80 for irq in sortedDictValues(IRQs):
81         print irq
82        
83
Note: See TracBrowser for help on using the browser.