Merge sensors-detect-stat.pl functionality into sensors-detect. This

will be more reliable that way, and easier to maintain.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5512 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2008-12-03 13:44:26 +00:00
1 parent 17dea03489
commit 495275e1e3
3 files changed
+41 -104

No files matched your search

+2
View File
@@ -38,6 +38,8 @@ SVN-HEAD
Skip ISA detection by default if a Super I/O was found (#2322)
Do not scan I2C adapters on multimedia cards by default
Skip SMBus probing by default if a Super I/O was found (#2322)
Display I2C address statictics with --stat
sensors-detect-stat.pl: Deleted, functionality merged into sensors-detect
3.0.3 (2008-09-28)
libsensors: Avoid namespace pollution
+39
View File
@@ -4838,6 +4838,39 @@ sub c7temp_detect
return;
}
#################
# SPECIAL MODES #
#################
sub show_i2c_stats
{
my ($chip, $addr, %histo, $chips);
# Gather the data
foreach $chip (@chip_ids) {
next unless defined $chip->{i2c_addrs};
$chips++;
foreach my $addr (@{$chip->{i2c_addrs}}) {
$histo{$addr}++;
}
}
# Display the data
printf "\%d I2C chips known, \%d I2C addresses probed\n\n",
$chips, scalar keys %histo;
print " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n".
"00: ";
for (my $addr = 0x03; $addr <= 0x77; $addr ++) {
printf("\n\%02x:", $addr) if ($addr % 16) == 0;
if (defined $histo{$addr}) {
printf ' %02d', $histo{$addr};
} else {
print ' --';
}
}
print "\n";
}
################
# MAIN PROGRAM #
################
@@ -4982,6 +5015,12 @@ sub main
{
my ($input, $superio_features);
# Handle special command line cases first
if (defined $ARGV[0] && $ARGV[0] eq "--stat") {
show_i2c_stats();
exit 0;
}
# We won't go very far if not root
unless ($> == 0) {
print "You need to be root to run this script.\n";
-104
View File
@@ -1,104 +0,0 @@
#!/usr/bin/perl -wT
# sensors-detect-stat.pl
# Statistical analysis of sensors-detect i2c addresses scanner
# Part of the lm_sensors project
# Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
use strict;
use vars qw(%histo $chips $file $skip);
# Where is sensors-detect?
# Use first argument, else try default locations.
if (defined($ARGV[0]))
{
$file = $ARGV[0];
}
elsif (-r '/usr/local/sbin/sensors-detect')
{
$file = '/usr/local/sbin/sensors-detect';
}
elsif (-r '/usr/sbin/sensors-detect')
{
$file = '/usr/sbin/sensors-detect';
}
else
{
print "Usage: $0 /path/to/sensors-detect\n";
exit 1;
}
# Can we read that file?
if (! -r $file)
{
print "Couldn't open $file for reading.\n";
exit 2;
}
# Get the data.
open (SD, $file) || die;
$skip = 0;
while (<SD>)
{
# Some chips are handled differently depending on the kernel
# version, avoid counting them twice.
if (m/^\@chip_kern24_ids\s*=/
|| m/^\@chip_oldfsc_ids\s*=/
|| m/^\@non_hwmon_chip_ids\s*=/) {
$skip = 1;
next;
}
if ($skip && m/^\);$/) {
$skip = 0;
next;
}
next if $skip;
# The regular expression may seem a little bit complex, but we wouldn't
# want to exec malicious code.
next unless m/^\s*i2c_addrs\s*=>\s*(\[( *0x[\dA-Fa-f]{2}( *\.\. *0x[\dA-Fa-f]{2})? *,?)+\])\s*,/;
my $addresses = eval $1 || die "Failed to eval \"$1\"";
$chips++;
foreach my $a (@{$addresses})
{
$histo{$a}++;
}
}
close SD;
# Print the data.
printf "\%s knows \%d chips and scans \%d addresses.\n\n",
$file, $chips, scalar keys %histo;
print " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n";
for (my $i=0; $i<128; $i+=16)
{
printf '%02x:', $i;
for (my $j=0; $j<16; $j++)
{
my $valid = ($i+$j >= 0x04 && $i+$j <= 0x77);
if (defined $histo{$i+$j})
{
printf '%s%02d', ($valid?' ':'!'), $histo{$i+$j};
}
else
{
printf ' %s', ($valid?'--':' ');
}
}
print "\n";
}