Graph/Iost.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 102 CC 3 SCAR 17.5
CC
3
Cov
0%
read
12.0
new
2.0
get_data_type
2.0
CRAP 5.8
1 ################################################################################
2  
3 use strict;
4 use POSIX qw(mktime);
5 use StatsView::Graph;
6 package StatsView::Graph::Iost;
7 @StatsView::Graph::Iost::ISA = qw(StatsView::Graph);
8
9 ################################################################################
10  
11 sub new($$$)
12 {
13 my ($class, $file, $fh) = @_;
14 $class = ref($class) || $class;
15  
16 # Look for the header line
17 my $line;
18 while (defined($line = $fh->getline()) && $line =~ /^\s*$/) { }
19 $line =~ /iost\+ started on/ || return(undef);
20  
21 my $self = $class->SUPER::init($file);
22 return($self);
23 }
24  
25 ################################################################################
26  
27 sub read($)
28 {
29 my ($self) = @_;
30 $self->SUPER::read();
31  
32 # Open the file
33 my $iost = IO::File->new($self->{file}, "r")
34 || die("Can't open $self->{file}: $!\n");
35 $self->{title} = "Iost+ Statistics";
36  
37 # Look for the header line & get the date
38 my $line;
39 while (defined($line = $iost->getline()) && $line =~ /^\s*$/) { }
40 $line =~ /iost\+\ started\ on\
41 (\d\d)\/(\d\d)\/(\d\d\d\d)\
42 (\d\d):(\d\d):(\d\d)\ on\ (\S+),\
43 sample\ interval\ (\d+)\ seconds/x
44 || die("$self->{file} is not an iost+ file (1)\n");
45 my ($D, $M, $Y, $h, $m, $s, $host, $interval) = ($1, $2, $3, $4, $5, $6);
46 $self->{interval} = $8;
47 $M--; $Y -= 1900;
48 my $last_t = POSIX::mktime($s, $m, $h, $D, $M, $Y, 0, 0, -1);
49 $self->{start} = $last_t + $self->{interval};
50  
51 # Define the column types - N = numeric, % = percentage
52 $self->define_cols(['Read op/sec', 'Write op/sec',
53 'Read Kb/sec', 'Write Kb/sec',
54 'WaitQ/qlen', 'WaitQ/res_t', 'WaitQ/svc_t', 'WaitQ/%ut',
55 'ActiveQ/qlen', 'ActiveQ/res_t', 'ActiveQ/svc_t',
56 'ActiveQ/%ut'],
57 [ qw(N N N N N N N % N N N %) ]);
58  
59 my $no_data = [ (0) x 12 ];
60 while (defined($line = $iost->getline()))
61 {
62 # Look for the start of the next sample point (a timestamp)
63 next if ($line !~ /^(\d\d):(\d\d):(\d\d)/);
64 ($h, $m, $s) = ($1, $2, $3);
65 my $tstamp = POSIX::mktime($s, $m, $h, $D, $M, $Y, 0, 0, -1);
66  
67 # Look for day rollover & save timestamp
68 if ($tstamp < $last_t)
69 {
70 $D++;
71 $tstamp = POSIX::mktime($s, $m, $h, $D, $M, $Y, 0, 0, -1);
72 }
73 $last_t = $tstamp;
74  
75 # Skip the next header line
76 $iost->getline();
77  
78 # Read the data & save away
79 my %seen_insts;
80 while (defined($line = $iost->getline()) && $line !~ /^\s*$|TOTAL|:\//)
81 {
82 my (@value) = split(' ', $line);
83 my $inst = pop(@value);
84  
85 $self->define_inst($inst);
86 push(@{$self->{data}{$inst}}, { tstamp => $tstamp, value => [ @value ] });
87 $seen_insts{$inst} = 1;
88 }
89  
90 # Add entries for any devices that were idle
91 foreach my $inst (grep(! exists($seen_insts{$_}), $self->get_instances()))
92 {
93 push(@{$self->{data}{$inst}}, { tstamp => $tstamp, value => $no_data });
94 }
95 }
96 $self->{finish} = $last_t;
97 $iost->close();
98 }
99  
100 ################################################################################
101  
102 sub get_data_type($;$)
103 {
104 return("3d");
105 }
106  
107 ################################################################################
108 1;