Util.pm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. clear_term
  13. );
  14. our $VERSION = '0.01';
  15. sub avg
  16. {
  17. my ($total, $n) = @_;
  18. return $total / $n;
  19. }
  20. my $NSECS_PER_SEC = 1000000000;
  21. sub nsecs
  22. {
  23. my ($secs, $nsecs) = @_;
  24. return $secs * $NSECS_PER_SEC + $nsecs;
  25. }
  26. sub nsecs_secs {
  27. my ($nsecs) = @_;
  28. return $nsecs / $NSECS_PER_SEC;
  29. }
  30. sub nsecs_nsecs {
  31. my ($nsecs) = @_;
  32. return $nsecs % $NSECS_PER_SEC;
  33. }
  34. sub nsecs_str {
  35. my ($nsecs) = @_;
  36. my $str = sprintf("%5u.%09u", nsecs_secs($nsecs), nsecs_nsecs($nsecs));
  37. return $str;
  38. }
  39. sub clear_term
  40. {
  41. print "\x1b[H\x1b[2J";
  42. }
  43. 1;
  44. __END__
  45. =head1 NAME
  46. Perf::Trace::Util - Perl extension for perf script
  47. =head1 SYNOPSIS
  48. use Perf::Trace::Util;
  49. =head1 SEE ALSO
  50. Perf (script) documentation
  51. =head1 AUTHOR
  52. Tom Zanussi, E<lt>tzanussi@gmail.com<gt>
  53. =head1 COPYRIGHT AND LICENSE
  54. Copyright (C) 2009 by Tom Zanussi
  55. This library is free software; you can redistribute it and/or modify
  56. it under the same terms as Perl itself, either Perl version 5.10.0 or,
  57. at your option, any later version of Perl 5 you may have available.
  58. Alternatively, this software may be distributed under the terms of the
  59. GNU General Public License ("GPL") version 2 as published by the Free
  60. Software Foundation.
  61. =cut