perf/scripts: Fix bug in Util.pm
[safe/jmp/linux-2.6] / tools / perf / scripts / perl / Perf-Trace-Util / lib / Perf / Trace / Util.pm
1 package Perf::Trace::Util;
2
3 use 5.010000;
4 use strict;
5 use warnings;
6
7 require Exporter;
8
9 our @ISA = qw(Exporter);
10
11 our %EXPORT_TAGS = ( 'all' => [ qw(
12 ) ] );
13
14 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
15
16 our @EXPORT = qw(
17 avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs
18 );
19
20 our $VERSION = '0.01';
21
22 sub avg
23 {
24     my ($total, $n) = @_;
25
26     return $total / $n;
27 }
28
29 my $NSECS_PER_SEC    = 1000000000;
30
31 sub nsecs
32 {
33     my ($secs, $nsecs) = @_;
34
35     return $secs * $NSECS_PER_SEC + $nsecs;
36 }
37
38 sub nsecs_secs {
39     my ($nsecs) = @_;
40
41     return $nsecs / $NSECS_PER_SEC;
42 }
43
44 sub nsecs_nsecs {
45     my ($nsecs) = @_;
46
47     return $nsecs % $NSECS_PER_SEC;
48 }
49
50 sub nsecs_str {
51     my ($nsecs) = @_;
52
53     my $str = sprintf("%5u.%09u", nsecs_secs($nsecs), nsecs_nsecs($nsecs));
54
55     return $str;
56 }
57
58 1;
59 __END__
60 =head1 NAME
61
62 Perf::Trace::Util - Perl extension for perf trace
63
64 =head1 SYNOPSIS
65
66   use Perf::Trace::Util;
67
68 =head1 SEE ALSO
69
70 Perf (trace) documentation
71
72 =head1 AUTHOR
73
74 Tom Zanussi, E<lt>tzanussi@gmail.com<gt>
75
76 =head1 COPYRIGHT AND LICENSE
77
78 Copyright (C) 2009 by Tom Zanussi
79
80 This library is free software; you can redistribute it and/or modify
81 it under the same terms as Perl itself, either Perl version 5.10.0 or,
82 at your option, any later version of Perl 5 you may have available.
83
84 Alternatively, this software may be distributed under the terms of the
85 GNU General Public License ("GPL") version 2 as published by the Free
86 Software Foundation.
87
88 =cut