Util.pm 1.4 KB

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