File Coverage

blib/lib/Test/Parser/Oprofile.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Test::Parser::Oprofile;
2              
3             =head1 NAME
4              
5             Test::Parser::Oprofile - Perl module to parse output from oprofile.
6              
7             =head1 SYNOPSIS
8              
9             use Test::Parser::Oprofile;
10              
11             my $parser = new Test::Parser::Oprofile;
12             $parser->parse($text);
13              
14             =head1 DESCRIPTION
15              
16             This module transforms oprofile output into a hash that can be used to
17             generate XML.
18              
19             =head1 FUNCTIONS
20              
21             Also see L for functions available from the base class.
22              
23             =cut
24              
25 1     1   22009 use strict;
  1         3  
  1         42  
26 1     1   6 use warnings;
  1         2  
  1         30  
27 1     1   664 use Test::Parser;
  1         18  
  1         37  
28 1     1   1828 use XML::Simple;
  0            
  0            
29              
30             @Test::Parser::Oprofile::ISA = qw(Test::Parser);
31             use base 'Test::Parser';
32              
33             use fields qw(
34             data
35             info
36             time_units
37             );
38              
39             use vars qw( %FIELDS $AUTOLOAD $VERSION );
40             our $VERSION = '1.7';
41              
42             =head2 new()
43              
44             Creates a new Test::Parser::Oprofile instance.
45             Also calls the Test::Parser base class' new() routine.
46             Takes no arguments.
47              
48             =cut
49              
50             sub new {
51             my $class = shift;
52             my Test::Parser::Oprofile $self = fields::new($class);
53             $self->SUPER::new();
54              
55             $self->name('oprofile');
56             $self->type('standards');
57              
58             return $self;
59             }
60              
61             =head3 data()
62              
63             Returns a hash representation of the oprofile data.
64              
65             =cut
66             sub data {
67             my $self = shift;
68             if (@_) {
69             $self->{data} = @_;
70             }
71             return {oprofile => {symbol => $self->{data}, info => [$self->{info}]}};
72             }
73              
74             =head3
75              
76             Override of Test::Parser's default parse_line() routine to make it able
77             to parse oprofile output.
78              
79             =cut
80             sub parse_line {
81             my $self = shift;
82             my $line = shift;
83              
84             #
85             # Drop anything that doesn't show symbols.
86             #
87             return 1 if ($line =~ /(no symbols)/);
88              
89             #
90             # Trim any leading and trailing whitespaces.
91             #
92             $line =~ s/^\s+//;
93              
94             my @i = split / +/, $line;
95             if (scalar @i == 4) {
96             chomp($i[3]);
97             push @{$self->{data}}, {samples => $i[0], percentage => $i[1],
98             app_name => $i[2], name => $i[3]};
99             } elsif ($i[0] ne 'samples') {
100             $self->{info} .= $line;
101             }
102              
103             return 1;
104             }
105              
106             =head3 to_xml()
107              
108             Returns oprofile data transformed into XML.
109              
110             =cut
111             sub to_xml {
112             my $self = shift;
113             my $outfile = shift;
114             return XMLout({symbol => $self->{data}, info => [$self->{info}]},
115             RootName => 'oprofile');
116             }
117              
118             1;
119             __END__