Back to home page

OSCL-LXR

 
 

    


0001 package Perf::Trace::Util;
0002 
0003 use 5.010000;
0004 use strict;
0005 use warnings;
0006 
0007 require Exporter;
0008 
0009 our @ISA = qw(Exporter);
0010 
0011 our %EXPORT_TAGS = ( 'all' => [ qw(
0012 ) ] );
0013 
0014 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
0015 
0016 our @EXPORT = qw(
0017 avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs
0018 clear_term
0019 );
0020 
0021 our $VERSION = '0.01';
0022 
0023 sub avg
0024 {
0025     my ($total, $n) = @_;
0026 
0027     return $total / $n;
0028 }
0029 
0030 my $NSECS_PER_SEC    = 1000000000;
0031 
0032 sub nsecs
0033 {
0034     my ($secs, $nsecs) = @_;
0035 
0036     return $secs * $NSECS_PER_SEC + $nsecs;
0037 }
0038 
0039 sub nsecs_secs {
0040     my ($nsecs) = @_;
0041 
0042     return $nsecs / $NSECS_PER_SEC;
0043 }
0044 
0045 sub nsecs_nsecs {
0046     my ($nsecs) = @_;
0047 
0048     return $nsecs % $NSECS_PER_SEC;
0049 }
0050 
0051 sub nsecs_str {
0052     my ($nsecs) = @_;
0053 
0054     my $str = sprintf("%5u.%09u", nsecs_secs($nsecs), nsecs_nsecs($nsecs));
0055 
0056     return $str;
0057 }
0058 
0059 sub clear_term
0060 {
0061     print "\x1b[H\x1b[2J";
0062 }
0063 
0064 1;
0065 __END__
0066 =head1 NAME
0067 
0068 Perf::Trace::Util - Perl extension for perf script
0069 
0070 =head1 SYNOPSIS
0071 
0072   use Perf::Trace::Util;
0073 
0074 =head1 SEE ALSO
0075 
0076 Perf (script) documentation
0077 
0078 =head1 AUTHOR
0079 
0080 Tom Zanussi, E<lt>tzanussi@gmail.com<gt>
0081 
0082 =head1 COPYRIGHT AND LICENSE
0083 
0084 Copyright (C) 2009 by Tom Zanussi
0085 
0086 This library is free software; you can redistribute it and/or modify
0087 it under the same terms as Perl itself, either Perl version 5.10.0 or,
0088 at your option, any later version of Perl 5 you may have available.
0089 
0090 Alternatively, this software may be distributed under the terms of the
0091 GNU General Public License ("GPL") version 2 as published by the Free
0092 Software Foundation.
0093 
0094 =cut