Test::Parser::Oprofile - Perl module to parse output from oprofile.


Test-Parser documentation Contained in the Test-Parser distribution.

Index


Code Index:

NAME

Top

Test::Parser::Oprofile - Perl module to parse output from oprofile.

SYNOPSIS

Top

 use Test::Parser::Oprofile;

 my $parser = new Test::Parser::Oprofile;
 $parser->parse($text);

DESCRIPTION

Top

This module transforms oprofile output into a hash that can be used to generate XML.

FUNCTIONS

Top

Also see Test::Parser for functions available from the base class.

new()

Creates a new Test::Parser::Oprofile instance. Also calls the Test::Parser base class' new() routine. Takes no arguments.

data()

Returns a hash representation of the oprofile data.

Override of Test::Parser's default parse_line() routine to make it able to parse oprofile output.

to_xml()

Returns oprofile data transformed into XML.

AUTHOR

Top

Mark Wong <markwkm@gmail.com>

COPYRIGHT

Top

SEE ALSO

Top

Test::Parser


Test-Parser documentation Contained in the Test-Parser distribution.
package Test::Parser::Oprofile;

use strict;
use warnings;
use Test::Parser;
use XML::Simple;

@Test::Parser::Oprofile::ISA = qw(Test::Parser);
use base 'Test::Parser';

use fields qw(
              data
              info
              time_units
              );

use vars qw( %FIELDS $AUTOLOAD $VERSION );
our $VERSION = '1.7';

sub new {
    my $class = shift;
    my Test::Parser::Oprofile $self = fields::new($class);
    $self->SUPER::new();

    $self->name('oprofile');
    $self->type('standards');

    return $self;
}

sub data {
    my $self = shift;
    if (@_) {
        $self->{data} = @_;
    }
    return {oprofile => {symbol => $self->{data}, info => [$self->{info}]}};
}

sub parse_line {
    my $self = shift;
    my $line = shift;

    #
    # Drop anything that doesn't show symbols.
    #
    return 1 if ($line =~ /(no symbols)/);

    #
    # Trim any leading and trailing whitespaces.
    #
    $line =~ s/^\s+//;

    my @i = split / +/, $line;
    if (scalar @i == 4) {
        chomp($i[3]);
        push @{$self->{data}}, {samples => $i[0], percentage => $i[1],
                app_name => $i[2], name => $i[3]};
    } elsif ($i[0] ne 'samples') {
        $self->{info} .= $line;
    }

    return 1;
}

sub to_xml {
    my $self = shift;
    my $outfile = shift;
    return XMLout({symbol => $self->{data}, info => [$self->{info}]},
            RootName => 'oprofile');
}

1;
__END__