-
Notifications
You must be signed in to change notification settings - Fork 2
/
mem_release_test
executable file
·53 lines (41 loc) · 1.46 KB
/
mem_release_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env perl
while($ARGV[0]=~/^-/) {
my $opt=shift;
last if($opt eq '--');
if($opt=~s/^-v//) { $verb=1; unshift(@ARGV, '-'.$opt) if($opt ne ""); }
elsif($opt=~s/^-0//) { $m2opt='-0'; unshift(@ARGV, '-'.$opt) if($opt ne ""); }
elsif($opt=~s/^-1//) { $m2opt='-1'; unshift(@ARGV, '-'.$opt) if($opt ne ""); }
elsif($opt=~s/^-t//) { $m2opt='-t'; unshift(@ARGV, '-'.$opt) if($opt ne ""); }
elsif($opt=~s/^-h//) { usage(); exit 0; }
else { die "$opt: invalid option"; }
}
my $min=1, $max=1;
while(!system "./m2 $m2opt $max") {
if($max > (1<<30)) { die "memory is never returned up to 1Gb\n"; exit 0; }
$min=$max;
$max*=2;
}
if($min == $max) { print "memory is always returned to OS\n"; exit 0; }
print "starting at boundaries: $min - $max\n" if($verb);
my $mid=int(($min+$max)/2);
while($mid > $min) {
print "trying $mid\n" if($verb);
if(system "./m2 $m2opt $mid") { $max=$mid; }
else { $min=$mid; }
$mid=int(($min+$max)/2);
}
if($verb) { print "memory returned to OS at $mid bytes\n"; }
else { print "$mid\n"; }
0;
sub usage
{
print "mem_release_test - check if and at which limit released",
" memory is returned to OS\n",
"Syntax: mem_release_test [-v] [-h]\n",
"Options:\n",
" -0 : emulate the memory is never released\n",
" -1 : emulate the memory is always released\n",
" -t : allocate additional byte at the end to prevent sbrk() memory trim\n",
" -v : print verbose info\n",
" -h : print this help\n";
}