1#!/usr/bin/perl
2
3use strict;
4
5sub compare_proc_interrupts {
6    my ($run1, $run2) = @_;
7
8    my $printed_header;
9    foreach my $irq (sort keys %{$run1}) {
10        if (! $printed_header) {
11            printf "%-8s ", "IRQ";
12            foreach my $cpu (sort keys %{$run1->{$irq}}) {
13                printf "%-5s ", $cpu;
14            }
15            print "\n";
16            $printed_header = 1;
17        }
18        printf "%-8s ", $irq;
19        foreach my $cpu (sort keys %{$run1->{$irq}}) {
20            printf "%-5s ", $run2->{$irq}->{$cpu} - $run1->{$irq}->{$cpu};
21        }
22        print "\n";
23    }
24}
25
26
27sub parse_proc_interrupts {
28    my $content = shift;
29    my @cpus;
30    my %run;
31
32    foreach my $line (split /\n/, $content) {
33        $line =~ s/^\s+//;
34        $line =~ s/\s+$//;
35
36        if (! @cpus) {
37            @cpus = split /\s+/, $line;
38        } else {
39            my @items = split /\s+/, $line;
40            my $irq = shift @items;
41            $irq =~ s/:$//;
42            foreach my $cpu (@cpus) {
43                $run{"IRQ$irq"}->{"$cpu"} = shift @items;
44            }
45        }
46    }
47    return \%run;
48}
49
50my $run1 = parse_proc_interrupts(shift @ARGV);
51my $run2 = parse_proc_interrupts(shift @ARGV);
52
53compare_proc_interrupts($run1, $run2);
54