Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Sep 1999 15:14:54 +0300
From:      "Vladimir COTFAS" <ulianov@ns.csm.ro>
To:        freebsd-ports@FreeBSD.org
Subject:   showints
Message-ID:  <199909031209.PAA01740@boca.livius.net>

next in thread | raw e-mail | index | archive | help

--Message-Boundary-5062
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

Hi,

While being idle at my job I wrote a small Perl5 script that
displays infos related to interrupts/devices. It gathers informations
offered by dmesg, scanpci and vmstat in a form that is close to
that of /proc/interrupts in Linux.

I attached this script to the letter. It is BSD-copyrighted.

Vlad


--Message-Boundary-5062
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'showints'

#!/usr/bin/perl

$name = 'showints';

sub pciStuff{
    my ($dev, $line, @devNames, @irqNumbers);

    $dev = 0;
    open(PCI, "scanpci -v |")
	    or die "$name: can't fork: $!\n";
    while(defined($line = <PCI>)){
	chomp($line);

	next if(length($line) < 1 || $line =~ /^Probing/ || 
		$line =~ /^PCI says/ || $line =~ /^PCI probing/);

	$dev++ 
	    if($line =~ /^pci bus/);
	if($line =~ /^\ [A-Z]/){
	    $devNames[$dev] = $line;
	}
	if($line =~ /INT_LINE/){
	    my($irq); 
	    #print $line, "\n";
	    $_ = $line; /INT_LINE/; $_ = $'; $irq = (split(' ', $_))[0];
	    $irq =~ s/^0x//g; $irq =~ s/^0//g;
	    if($irq eq 'a') { $irq = 10;}
	    elsif($irq eq 'b') { $irq = 11;}
	    elsif($irq eq 'c') { $irq = 12;}
	    elsif($irq eq 'd') { $irq = 13;}
	    elsif($irq eq 'e') { $irq = 14;}
	    elsif($irq eq 'f') { $irq = 15;}

	    $irqNumbers[$dev] = $irq; 
	}
    }
    close(PCI);

    for($dev = 0; $dev <= $#devNames; $dev++){
	$PCI_IRQS{$irqNumbers[$dev]} .= ':' . $devNames[$dev];
    }
}

sub dmesgPCI_Stuff{
    my ($ifc, $line);

    open(MSG, "dmesg |")
	    or die "$name: can't fork: $!\n";
    while(defined($line = <MSG>)){
	chomp($line);
	next
	    unless($line =~ /pci/ && $line =~ /irq/);
	
	$_ = $line; /:/; $ifc = $`; 

	$_ = $'; /irq\ /; $_ = (split(' ', $'))[0]; 
	$IFC_by_IRQ{$_} .= ':' . $ifc;
    }
    close(MSG);
}

$n = 0;
open(INT, "vmstat -i |")
	or die "$name: can't fork: $!\n";
while(defined($line = <INT>)){
    next if($line =~ /^interrupt/ || $line =~ /^Total/);

    @foo = split(' ', $line);    
    $irq = $foo[1]; $irq =~ s/^irq//g; 
    $IRQS{$irq} = join(':', $foo[0], $foo[2], $foo[3]);
}
close(INT);

pciStuff; dmesgPCI_Stuff;

printf("%-10s \t%s\t%10s\t%s\t%s\n", 'Device', 'IRQ', 'Total', 'Rate', 'Description');

foreach $irq (sort {$a <=> $b} keys(%IRQS)){
    @foo = split(':', $IRQS{$irq});

    $ifc = $foo[0];
    if($ifc eq 'pci' && defined($IFC_by_IRQ{$irq})){
	my(@ifs);
	@ifs = split(':', $IFC_by_IRQ{$irq});
	if($#ifs > 1){
	    $ifc = join('/', @ifs); $ifc =~ s/^\///g;
	}else{
	    $ifc = $ifs[1];
	}
    }
    printf("%-10s \t%s\t%10s\t%4s", $ifc, $irq, $foo[1], $foo[2]);

    if($foo[0] eq 'pci' && defined($PCI_IRQS{$irq})){
	my(@desc, $i);
	@desc = split(':', $PCI_IRQS{$irq});

	print "\t", $desc[1];
	if($#desc > 1) { # Oops! PCI shared IRQ's 
	    for($i = 2; $i <= $#desc; $i++){
		print "/\n\t\t\t\t\t\t", $desc[$i];
	    }
	}
    }    
    print "\n";
}






--Message-Boundary-5062--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909031209.PAA01740>