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 7# 8# Licensed under the Apache License, Version 2.0 (the "License"); you may 9# not use this file except in compliance with the License. 10# You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, software 15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17# See the License for the specific language governing permissions and 18# limitations under the License. 19 20use warnings; 21use strict; 22 23use utf8; 24use open qw(:std utf8); 25 26die unless @ARGV == 1; 27 28my @snaps; 29open my $fh, '<', $ARGV[0] or die; 30{ local $/ = 'snapshot='; @snaps = <$fh>; } 31close $fh or die; 32 33my ($max, $max_heap, $max_he, $max_stack) = (0, 0, 0, 0); 34for (@snaps) 35{ 36 my ($heap, $heap_extra, $stack) = m{ 37 mem_heap_B=(\d+)\n 38 mem_heap_extra_B=(\d+)\n 39 mem_stacks_B=(\d+) 40 }xm; 41 next unless defined $heap; 42 my $total = $heap + $heap_extra + $stack; 43 if( $total > $max ) { 44 ($max, $max_heap, $max_he, $max_stack) = ($total, $heap, $heap_extra, $stack); 45 } 46} 47 48printf "$max (heap $max_heap+$max_he, stack $max_stack)\n"; 49