1package Test::Parser::SysbenchCPU;
2
3=head1 NAME
4
5Test::Parser::SysbenchCPU - Perl module to parse output from Sysbench --test=cpu
6
7=head1 SYNOPSIS
8
9    use Test::Parser::SysbenchCPU;
10    my $parser = new Test::Parser::SysbenchCPU;
11    $parser->parse($text);
12
13    $parser->to_xml();
14
15Additional information is available from the subroutines listed below
16and from the L<Test::Parser> baseclass.
17
18=head1 DESCRIPTION
19
20This module provides a way to parse and neatly display information gained from the
21Sysbench CPU test.  This module will parse the output given by this command and
22command similar to it:  `sysbench --test=cpu > cpu.output`  The cpu.output contains
23the necessary information that SysbenchCPU is able to parse.
24
25=head1 FUNCTIONS
26
27See L<Test::Parser> for functions available from the base class.
28
29=cut
30
31use strict;
32use warnings;
33use Test::Parser;
34
35@Test::Parser::SysbenchCPU::ISA = qw(Test::Parser);
36use base 'Test::Parser';
37
38use fields qw(
39              data
40              );
41
42use vars qw( %FIELDS $AUTOLOAD $VERSION );
43our $VERSION = '1.7';
44
45
46=head2 new()
47
48	Purpose: Create a new Test::Parser::SysbenchCPU instance
49	Input: None
50	Output: SysbenchCPU object
51
52=cut
53sub new {
54    my $class = shift;
55    my Test::Parser::SysbenchCPU $self = fields::new($class);
56    $self->SUPER::new();
57
58    $self->testname('sysbench');
59    $self->description('A variety of tests');
60    $self->summary('Lots of things');
61    $self->license('FIXME');
62    $self->vendor('FIXME');
63    $self->release('FIXME');
64    $self->url('FIXME');
65    $self->platform('FIXME');
66
67    $self->{data} = ();
68
69    return $self;
70}
71
72
73=head2 data()
74
75	Purpose: Return a hash representation of the Sysbench data
76	Input: None
77	Output: SysbenchCPU data
78
79=cut
80sub data {
81    my $self = shift;
82    if (@_) {
83        $self->{data} = @_;
84    }
85    return {sysbench => {data => $self->{data}}};
86}
87
88
89=head2 parse_line()
90
91	Purpose: Parse Sysbench --test=cpu log files.  This method override's the default parse_line() of Test::Parser
92	Input: String (one line of log file)
93	Output: 1
94
95=cut
96sub parse_line {
97    my $self = shift;
98    my $line = shift;
99
100    my @labels = ();
101    my @keys = ();
102    my $size = 0;
103
104    # Trim any leading and trailing whitespaces.
105    $line =~ s/(^\s+|\s+$)//g;
106
107    # Determine what info we have in the line...
108    if ($line =~ /^Number .*?threads:(.+)/) {
109        $keys[1] = $1;
110        $labels[1] = 'sum_threads';
111        $size = 1;
112    }
113
114    elsif ($line =~ /^sysbench v(.+):/) {
115        $self->testname('sysbench');
116        $self->version($1);
117    }
118
119    elsif ($line =~ /^Maximum .*?test:(.+)/) {
120        $keys[1] = $1;
121        $labels[1] = 'sum_maxprime';
122        $size = 1;
123    }
124
125    elsif ($line =~ /^total .*?time:\s+([\.\d]+)(\w+)/) {
126        $keys[1] = $1;
127        $labels[1] = 'total_time';
128        $keys[2] = $2;
129        $labels[2] = 'total_time_units';
130        $size = 2;
131    }
132
133    elsif ($line =~ /^total .*?events:\s+(.+)/) {
134        $keys[1] = $1;
135        $labels[1] = 'total_events';
136        $size = 1;
137    }
138
139    elsif ($line =~ /^total .*?execution:\s+(.+)/) {
140        $keys[1] = $1;
141        $labels[1] = 'total_exec';
142        $size = 1;
143    }
144
145    elsif ($line =~ /^min:\s+([\.\d]+)(\w+)/) {
146        $keys[1] = $1;
147        $labels[1] = 'pr_min';
148        $keys[2] = $2;
149        $labels[2] = 'pr_min_units';
150        $size = 2;
151    }
152
153    elsif ($line =~ /^avg:\s+([\.\d]+)(\w+)/) {
154        $keys[1] = $1;
155        $labels[1] = 'pr_avg';
156        $keys[2] = $2;
157        $labels[2] = 'pr_avg_units';
158        $size = 2;
159    }
160
161    elsif ($line =~ /^max:\s+([\.\d]+)(\w+)/) {
162        $keys[1] = $1;
163        $labels[1] = 'pr_max';
164        $keys[2] = $2;
165        $labels[2] = 'pr_max_units';
166        $size = 2;
167    }
168
169    elsif ($line =~ /^approx. .*?tile:\s+([\.\d]+)(\w+)/) {
170        $keys[1] = $1;
171        $labels[1] = 'pr_95';
172        $keys[2] = $2;
173        $labels[2] = 'pr_95_units';
174        $size = 2;
175    }
176
177    # These are done together as there are 2 pieces of information on each line
178    elsif ($line =~ /^events .*?:(.+)\/(.+)/) {
179        $keys[1] = $1;
180        $labels[1] = 'event_avg';
181        $keys[2] = $2;
182        $labels[2] = 'event_stddev';
183        $size = 2;
184    }
185
186    # These are done together as there are 2 pieces of information on each line
187    elsif ($line =~ /^execution .*?:(.+)\/(.+)/) {
188        $keys[1] = $1;
189        $labels[1] = 'exec_avg';
190        $keys[2] = $2;
191        $labels[2] = 'exec_stddev';
192        $size = 2;
193    }
194
195    my $do_units = 0;
196
197    for (my $tekey = 0; $tekey <= $size; $tekey++)
198    {
199        if( $tekey+1 <= $size ) {
200            my $check_me = $labels[$tekey+1];
201            my $orig = $labels[$tekey];
202            my $units = $orig;
203            $units .= "_units";
204            if( $check_me eq $units ) {
205                $do_units = 1;
206            }
207        }
208        if ( defined($labels[$tekey]) ) {
209            $keys[$tekey] =~ s/(^\s+|\s+$)//g;
210            my $col = 0;
211            if ($do_units == 1) {
212                $keys[$tekey+1] =~ s/(^\s+|\s+$)//g;
213                $col = $self->add_column( $labels[$tekey], $keys[$tekey+1] );
214                $self->add_data( $keys[$tekey], $col );
215
216                $tekey++;
217            }
218            else {
219                $col = $self->add_column( $labels[$tekey] );
220                $self->add_data( $keys[$tekey], $col );
221            }
222            $do_units=0;
223        }
224    }
225    return 1;
226}
227
2281;
229__END__
230
231=head1 AUTHOR
232
233John Daiker <daikerjohn@gmail.com>
234
235=head1 COPYRIGHT
236
237Copyright (C) 2006 John Daiker & Open Source Development Labs, Inc.
238All Rights Reserved.
239
240This script is free software; you can redistribute it and/or modify it
241under the same terms as Perl itself.
242
243=head1 SEE ALSO
244
245L<Test::Parser>
246
247=end
248