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