blob: 52ca606b525ad74e8775494ce8a8d0abf3767c31 [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#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +01007
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
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010021my ($max, $max_heap, $max_he, $max_stack) = (0, 0, 0, 0);
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010022for (@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;
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010031 if( $total > $max ) {
32 ($max, $max_heap, $max_he, $max_stack) = ($total, $heap, $heap_extra, $stack);
33 }
Manuel Pégourié-Gonnard4d5cc112014-11-25 12:21:48 +010034}
35
Manuel Pégourié-Gonnardc6dbc8e2014-12-01 14:05:45 +010036printf "$max (heap $max_heap+$max_he, stack $max_stack)\n";