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