massif_max.pl 747 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl
  2. # Parse a massif.out.xxx file and output peak total memory usage
  3. use warnings;
  4. use strict;
  5. use utf8;
  6. use open qw(:std utf8);
  7. die unless @ARGV == 1;
  8. my @snaps;
  9. open my $fh, '<', $ARGV[0] or die;
  10. { local $/ = 'snapshot='; @snaps = <$fh>; }
  11. close $fh or die;
  12. my ($max, $max_heap, $max_he, $max_stack) = (0, 0, 0, 0);
  13. for (@snaps)
  14. {
  15. my ($heap, $heap_extra, $stack) = m{
  16. mem_heap_B=(\d+)\n
  17. mem_heap_extra_B=(\d+)\n
  18. mem_stacks_B=(\d+)
  19. }xm;
  20. next unless defined $heap;
  21. my $total = $heap + $heap_extra + $stack;
  22. if( $total > $max ) {
  23. ($max, $max_heap, $max_he, $max_stack) = ($total, $heap, $heap_extra, $stack);
  24. }
  25. }
  26. printf "$max (heap $max_heap+$max_he, stack $max_stack)\n";