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

Revision 2373, 2.2 KB (checked in by khali, 11 years ago)

New Perl script, scans sensors-detect and prints statistics.

  • 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-2004  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);
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;
54while (<SD>)
55{
56        # The regular expression may seem a little bit complex, but we wouldn't
57        # want to exec malicious code.
58        next unless m/^\s*i2c_addrs\s*=>\s*(\[( *0x[\dA-Fa-f]{2}( *\.\. *0x[\dA-Fa-f]{2})? *,?)+\])\s*,/;
59        my $addresses = eval $1 || die "Failed to eval \"$1\"";
60        $chips++;
61        foreach my $a (@{$addresses})
62        {
63                $histo{$a}++;
64        }
65}
66close SD;
67
68# Print the data.
69printf "$file knows \%d chips and scans \%d addresses.\n\n",
70        $chips, scalar keys %histo;
71print "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n";
72for (my $i=0; $i<128; $i+=16)
73{
74        printf '%02x:', $i;
75        for (my $j=0; $j<16; $j++)
76        {
77                my $valid = ($i+$j >= 0x04 && $i+$j <= 0x77);
78                if (defined $histo{$i+$j})
79                {
80                        printf '%s%02d', ($valid?' ':'!'), $histo{$i+$j};
81                }
82                else
83                {
84                        printf ' %s', ($valid?'--':'  ');
85                }
86        }
87        print "\n";
88}
Note: See TracBrowser for help on using the browser.