File: linux26diskaccess.pl

package info (click to toggle)
netmrg 0.18.2-14
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,104 kB
  • ctags: 1,575
  • sloc: xml: 8,912; php: 7,389; sh: 4,019; cpp: 2,581; perl: 471; ansic: 338; makefile: 316; sql: 5
file content (76 lines) | stat: -rwxr-xr-x 1,360 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
#
# linux26diskaccess.pl
#
# reports some disk access counters
#
# # reads issued, # writes issued
#

use strict;

### config variables
my $blockdev = "/sys/block";
### status variables
my $hd = "";
my $partition = "";
my @fields = ();


### argument processing
if (scalar(@ARGV) != 2
	|| ($ARGV[0] ne "-r" && $ARGV[0] ne "-w")
	|| ($ARGV[1] !~ /^hd\w(\d+)?$/)
	)
{
	print "U\n";
	print "\n";
	print "$0 [-r|-w] <hdx(N)>\n";
	print "  -r: Report Reads\n";
	print "  -w: Report Writes\n";
	print "\n";
	exit(1);
} # end if not enough parameters


### figure out device/partitions
if ($ARGV[1] =~ /^(hd\w)\d+$/)
{
	$partition = $ARGV[1];
	$hd = $1;
} # end if hd has a partition
else
{
	$hd = $ARGV[1];
} # end else hd is just the drive


### read info from system block

# read the data from the correct path
my $path = "$blockdev/$hd";
$path .= "/$partition" if ($partition ne "");
$path .= "/stat";
open(STAT, $path) || die ("U\nERROR: couldn't open $path\n\n");
my $line = <STAT>;
chomp($line);
@fields = split /\s+/, $line;
close(STAT);


### output the data
if ($ARGV[0] eq "-r")
{
	print $fields[1]."\n";
} # end if read statistics
elsif ($ARGV[0] eq "-w")
{
	print $fields[5]."\n" if ($partition eq "");
	print $fields[3]."\n" if ($partition ne "");
} # end if write statistics
else
{
	print "U\n";
} # else we don't know what happened