root/lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect-stat.pl @ 4971

Revision 4971, 2.5 KB (checked in by khali, 6 years ago)

sensors-detect-stat.pl: Handle alternative chip lists.
Ultimately this script should be folded into sensors-detect.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl -wT
2
3# sensors-detect-stat.pl
4# Statistical analysis of sensors-detect i2c addresses scanner
5# Part of the lm_sensors project
6# Copyright (C) 2003-2007  Jean Delvare <khali@linux-fr.org>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22use strict;
23use vars qw(%histo $chips $file $skip);
24
25# Where is sensors-detect?
26# Use first argument, else try default locations.
27if (defined($ARGV[0]))
28{
29        $file = $ARGV[0];
30}
31elsif (-r '/usr/local/sbin/sensors-detect')
32{
33        $file = '/usr/local/sbin/sensors-detect';
34}
35elsif (-r '/usr/sbin/sensors-detect')
36{
37        $file = '/usr/sbin/sensors-detect';
38}
39else
40{
41        print "Usage: $0 /path/to/sensors-detect\n";
42        exit 1;
43}
44
45# Can we read that file?
46if (! -r $file)
47{
48        print "Couldn't open $file for reading.\n";
49        exit 2;
50}
51
52# Get the data.
53open (SD, $file) || die;
54$skip = 0;
55while (<SD>)
56{
57        # Some chips are handled differently depending on the kernel
58        # version, avoid counting them twice.
59        if (m/^\@chip_kern24_ids\s*=/ || m/^\@chip_oldfsc_ids\s*=/) {
60                $skip = 1;
61                next;
62        }
63        if ($skip && m/^\);$/) {
64                $skip = 0;
65                next;
66        }
67        next if $skip;
68
69        # The regular expression may seem a little bit complex, but we wouldn't
70        # want to exec malicious code.
71        next unless m/^\s*i2c_addrs\s*=>\s*(\[( *0x[\dA-Fa-f]{2}( *\.\. *0x[\dA-Fa-f]{2})? *,?)+\])\s*,/;
72        my $addresses = eval $1 || die "Failed to eval \"$1\"";
73        $chips++;
74        foreach my $a (@{$addresses})
75        {
76                $histo{$a}++;
77        }
78}
79close SD;
80
81# Print the data.
82printf "$file knows \%d chips and scans \%d addresses.\n\n",
83        $chips, scalar keys %histo;
84print "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n";
85for (my $i=0; $i<128; $i+=16)
86{
87        printf '%02x:', $i;
88        for (my $j=0; $j<16; $j++)
89        {
90                my $valid = ($i+$j >= 0x04 && $i+$j <= 0x77);
91                if (defined $histo{$i+$j})
92                {
93                        printf '%s%02d', ($valid?' ':'!'), $histo{$i+$j};
94                }
95                else
96                {
97                        printf ' %s', ($valid?'--':'  ');
98                }
99        }
100        print "\n";
101}
Note: See TracBrowser for help on using the browser.