line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Parser::Mpstat; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Parser::Mpstat - Perl module to parse output from mpstat. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Parser::Mpstat; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $parser = new Test::Parser::Mpstat; |
12
|
|
|
|
|
|
|
$parser->parse($text); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module transforms mpstat output into a hash that can be used to generate |
17
|
|
|
|
|
|
|
XML. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 FUNCTIONS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Also see L for functions available from the base class. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
27208
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
26
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
27
|
1
|
|
|
1
|
|
667
|
use Test::Parser; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
33
|
|
28
|
1
|
|
|
1
|
|
2216
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@Test::Parser::Mpstat::ISA = qw(Test::Parser); |
31
|
|
|
|
|
|
|
use base 'Test::Parser'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use fields qw( |
34
|
|
|
|
|
|
|
data |
35
|
|
|
|
|
|
|
time_units |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use vars qw( %FIELDS $AUTOLOAD $VERSION ); |
39
|
|
|
|
|
|
|
our $VERSION = '1.7'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 new() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Creates a new Test::Parser::Mpstat instance. |
44
|
|
|
|
|
|
|
Also calls the Test::Parser base class' new() routine. |
45
|
|
|
|
|
|
|
Takes no arguments. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
|
|
|
|
|
|
my $class = shift; |
51
|
|
|
|
|
|
|
my Test::Parser::Mpstat $self = fields::new($class); |
52
|
|
|
|
|
|
|
$self->SUPER::new(); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->name('mpstat'); |
55
|
|
|
|
|
|
|
$self->type('standards'); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# Mpstat data in an array. |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
$self->{data} = []; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# Used for plotting. |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
$self->{format} = 'png'; |
66
|
|
|
|
|
|
|
$self->{outdir} = '.'; |
67
|
|
|
|
|
|
|
$self->{time_units} = 'Minutes'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head3 data() |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a hash representation of the mpstat data. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
sub data { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
if (@_) { |
80
|
|
|
|
|
|
|
$self->{data} = @_; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
return {mpstat => {data => $self->{data}}}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Override of Test::Parser's default parse_line() routine to make it able |
88
|
|
|
|
|
|
|
to parse mpstat output. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
sub parse_line { |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
my $line = shift; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# Trim any leading and trailing whitespaces. |
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
$line =~ s/^\s+//; |
99
|
|
|
|
|
|
|
chomp($line); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my @i = split / +/, $line; |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# These should ignore the first header line. |
104
|
|
|
|
|
|
|
# |
105
|
|
|
|
|
|
|
return 1 if (scalar @i != 11); |
106
|
|
|
|
|
|
|
return 1 if ($i[1] eq 'CPU'); |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
# The first set of data doesn't appear to be garbage. |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
my $count = scalar @{$self->{data}}; |
111
|
|
|
|
|
|
|
push @{$self->{data}}, {cpu => $i[1], user => $i[2], nice => $i[3], |
112
|
|
|
|
|
|
|
sys => $i[4], iowait => $i[5], irq => $i[6], soft => $i[6], |
113
|
|
|
|
|
|
|
steal => $i[7], idle => $i[8], intrs => $i[9], |
114
|
|
|
|
|
|
|
elapsed_time => $count}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head3 to_xml() |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns mpstat data transformed into XML. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
sub to_xml { |
125
|
|
|
|
|
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
my $outfile = shift; |
127
|
|
|
|
|
|
|
return XMLout({data => $self->{data}}, RootName => 'mpstat'); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
__END__ |