Changeset 2739

Show
Ignore:
Timestamp:
01/31/18 00:19:47 (7 months ago)
Author:
jwoithe
Message:

[PATCH 03/13] python tools: simplify listirqinfo.

* A full import and calls with dot notation allows reference searchs.

The previous import from listirqinfo in ffado-diag refers to 3 functions
but only one is used.

* str() and str() introduce unneeded complexity.

* import os is not used.

* subprocess module is available since python2.4.

* Reading a file from python is easier and more readable than spawning a cat

command.

From Nicolas Boulenguez.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/support/tools/ffado-diag.in

    r2738 r2739  
    2828sys.path.insert(0, "$PYTHONDIR" ) 
    2929 
    30 from listirqinfo import IRQ,SoftIRQ,IRQInfo 
     30import listirqinfo 
    3131import helpstrings 
    3232from ffado_diag_helpers import * 
     
    164164    # check IRQ settings 
    165165    print "  IRQ information" 
    166     info = IRQInfo() 
    167  
     166    info = listirqinfo.IRQInfo() 
    168167    info.load() 
    169     print str(info
     168    info.display(
    170169 
    171170    print "" 
  • trunk/libffado/support/tools/listirqinfo.py

    r2737 r2739  
    1515# 
    1616 
    17 import os 
    1817import 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 
     18import subprocess 
    2619 
    2720LISTIRQINFO_VERSION="0.3" 
     
    3932        self.drivers = [] 
    4033        self.cpu_counts = [] 
    41     def __str__(self): 
     34    def description (self): 
    4235        s = " IRQ %4s: PID: %5s, count: %18s, Sched %4s (priority %4s), drivers: %s" % \ 
    4336            (self.number, self.process_id, self.cpu_counts, 
     
    5447        self.process_id = None 
    5548        self.cpu_counts = [] 
    56     def __str__(self): 
     49    def description (self): 
    5750        s = " SoftIRQ %12s: PID %6s, Sched %4s (priority %4s), name: %s" % \ 
    5851            (self.name, self.process_id ,self.scheduling_class, self.scheduling_priority, self.fullname) 
     
    6659    def load(self): 
    6760        # get PID info 
    68         (exitstatus, outtext) = getstatusoutput('ps -eLo pid,cmd,class,rtprio | grep IRQ') 
    69  
     61        outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')) 
    7062        rawstr = r"""([0-9]+) +\[IRQ-([0-9]+)\] +([A-Z]{2}) +([-0-9]+)""" 
    7163        compile_obj = re.compile(rawstr) 
    72  
    7364        IRQs = {} 
    7465        for line in outtext.splitlines(): 
     
    8576                IRQs[irq.number] = irq 
    8677 
    87         (exitstatus, outtext) = getstatusoutput('ps -eLo pid,cmd,class,rtprio | grep softirq') 
    88  
     78        outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')) 
    8979        rawstr = r"""([0-9]+) +\[softirq-(.*)\] +([A-Z]+) +([-0-9]+)""" 
    9080        compile_obj = re.compile(rawstr) 
    91  
    9281        softIRQs = {} 
    9382        for line in outtext.splitlines(): 
     
    10695 
    10796        # get irq info 
    108         (exitstatus, outtext) = getstatusoutput('cat /proc/interrupts') 
    109         lines = outtext.splitlines() 
     97        with open ('/proc/interrupts') as f: 
     98            lines = f.readlines () 
    11099        nb_cpus = len(lines[0].split()) 
    111100        str0 = "([0-9]+): +"; 
     
    119108        compile_obj = re.compile(rawstr) 
    120109 
    121         for line in outtext.splitlines()
     110        for line in lines
    122111            match_obj = compile_obj.search(line) 
    123112            if match_obj: 
     
    142131        self.IRQs = IRQs 
    143132 
    144     def __str__(self): 
    145         s  = "" 
    146         s += "Hardware Interrupts:\n" 
    147         s += "--------------------\n" 
    148  
     133    def display (self): 
     134        print ("Hardware Interrupts:") 
     135        print ("--------------------") 
    149136        for irq in sortedDictValues(self.IRQs): 
    150             s += str(irq) + "\n" 
    151  
    152         s += "\n" 
    153         s += "Software Interrupts:\n" 
    154         s += "--------------------\n" 
     137            print (irq.description ()) 
     138        print ("") 
     139        print ("Software Interrupts:") 
     140        print ("--------------------") 
    155141        for irq in sortedDictValues(self.softIRQs): 
    156             s += str(irq) + "\n" 
    157  
    158         return s 
     142            print (irq.description ()) 
    159143 
    160144if __name__== '__main__': 
     
    165149    print( "(C) 2008 Pieter Palmers" ) 
    166150    print( "" ) 
    167  
    168151    info = IRQInfo() 
    169  
    170152    info.load() 
    171     print( str(info) ) 
    172  
     153    info.display() 
    173154    print( "" )