![]() |
|
|||
0001 #!/usr/bin/perl 0002 ## 0003 ## @brief @(#) Trace Enduro/X memory allocation 0004 ## 0005 ## @file memtrace.pl 0006 ## 0007 ## ----------------------------------------------------------------------------- 0008 ## Enduro/X Middleware Platform for Distributed Transaction Processing 0009 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 0010 ## Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved. 0011 ## This software is released under one of the following licenses: 0012 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use. 0013 ## See LICENSE file for full text. 0014 ## ----------------------------------------------------------------------------- 0015 ## AGPL license: 0016 ## 0017 ## This program is free software; you can redistribute it and/or modify it under 0018 ## the terms of the GNU Affero General Public License, version 3 as published 0019 ## by the Free Software Foundation; 0020 ## 0021 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 0022 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0023 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3 0024 ## for more details. 0025 ## 0026 ## You should have received a copy of the GNU Affero General Public License along 0027 ## with this program; if not, write to the Free Software Foundation, Inc., 0028 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0029 ## 0030 ## ----------------------------------------------------------------------------- 0031 ## A commercial use license is available from Mavimax, Ltd 0032 ## contact@mavimax.com 0033 ## ----------------------------------------------------------------------------- 0034 ## 0035 0036 # 0037 # Track down the stuff 0038 # 0039 %M_allocs = (); 0040 0041 # 0042 # Read from file or stdin. 0043 # 0044 my $file = shift @ARGV; 0045 0046 my $ifh; 0047 my $is_stdin = 0; 0048 if (defined $file){ 0049 open $ifh, "<", $file or die $!; 0050 } 0051 else 0052 { 0053 $ifh = *STDIN; 0054 $is_stdin++; 0055 } 0056 0057 while (<$ifh>){ 0058 # Process 0059 my $line = $_; 0060 0061 0062 #print $line; 0063 0064 chomp $line; 0065 0066 if ($line =~/\<\= malloc/ || $line =~/\<\= calloc/ || $line =~/\<\= fopen/) 0067 { 0068 # 4465:20161111:19454501:server :[0xefbcc0] <= malloc(size=100):Balloc /home/mvitolin/projects/endurox/libubf/ubf.c:1217 0069 my ($addr) = ($line=~m/\[(0x.*)\]/); 0070 0071 $M_allocs{$addr} = $line; 0072 } 0073 elsif ($line =~/\=\> free/ || $line =~/\=\> fclose/) 0074 { 0075 # 4465:20161111:19454501:server :[0xebd100] => free(ptr=0xebd100):_tpfree /home/mvitolin/projects/endurox/libatmi/typed_buf.c:353 0076 0077 my ($addr) = ($line=~m/\[(0x.*)\]/); 0078 0079 if ($M_allocs{$addr}) 0080 { 0081 delete $M_allocs{$addr}; 0082 } 0083 else 0084 { 0085 print "!!! ERROR Double free: [$line]\n"; 0086 } 0087 } 0088 elsif ($line =~ /\<\= realloc/) 0089 { 0090 # 4472:20161111:19455456:client :[0x7faa743ba600] <= realloc(ptr=[0x7faa743ba600], size=128):Brealloc /home/mvitolin/projects/endurox/libubf/ubf.c:1273 0091 my ($addr, $addr_old) = ($line=~m/\[(0x.*)\].*\[(0x.*)\]/); 0092 0093 if ($M_allocs{$addr_old}) 0094 { 0095 delete $M_allocs{$addr_old}; 0096 } 0097 else 0098 { 0099 print "!!! ERROR Double free (for realloc): [$line]\n"; 0100 } 0101 0102 $M_allocs{$addr} = $line; 0103 } 0104 } 0105 0106 # Print the stuff in 0107 0108 foreach my $key (keys %M_allocs) 0109 { 0110 my $line = $M_allocs{$key}; 0111 print "!!! WARNING Still in memory: [$line]\n"; 0112 } 0113 0114 # Close the file 0115 close $ifh unless $is_stdin; 0116 0117 0118 # vim: set ts=4 sw=4 et smartindent:
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |