massif_max.pl 1.3 KB

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