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