blob: f5d870f5ab859cfbea5fee9c295f3b2ec164c209 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +01002
3# Parse a massif.out.xxx file and output peak total memory usage
Bence Szépkúti700ee442020-05-26 00:33:31 +02004#
5# Copyright (C) 2014, Arm Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# 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.
Bence Szépkúti700ee442020-05-26 00:33:31 +020019#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010021
22use warnings;
23use strict;
24
25use utf8;
26use open qw(:std utf8);
27
28die unless @ARGV == 1;
29
30my @snaps;
31open my $fh, '<', $ARGV[0] or die;
32{ local $/ = 'snapshot='; @snaps = <$fh>; }
33close $fh or die;
34
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010035my ($max, $max_heap, $max_he, $max_stack) = (0, 0, 0, 0);
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010036for (@snaps)
37{
38 my ($heap, $heap_extra, $stack) = m{
39 mem_heap_B=(\d+)\n
40 mem_heap_extra_B=(\d+)\n
41 mem_stacks_B=(\d+)
42 }xm;
43 next unless defined $heap;
44 my $total = $heap + $heap_extra + $stack;
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010045 if( $total > $max ) {
46 ($max, $max_heap, $max_he, $max_stack) = ($total, $heap, $heap_extra, $stack);
47 }
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010048}
49
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010050printf "$max (heap $max_heap+$max_he, stack $max_stack)\n";