Skip to content

Commit

Permalink
perl脚本传入校测规则,检查java程序最后一次内存使用记录,跟1/3时刻的内存使用情况相比,超过传入的规格数据则报错
Browse files Browse the repository at this point in the history
  • Loading branch information
sendaoYan committed Sep 14, 2024
1 parent 9ab8aec commit 46bc492
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ if grep -q "Unable to open socket file" *-native_memory-summary.log ; then
exit 1
fi

( set +x ; perl ${TESTSRC}/get-native-memory-usage.pl `ls *-native_memory-summary.log | sort -n | xargs` )
( set +x ; perl -w ${TESTSRC}/get-native-memory-usage.pl `ls *-native_memory-summary.log | sort -n | xargs` )
generatePlotPNG
( set +x ; perl ${TESTSRC}/check-native-memory-usage.pl 1 `ls *-native_memory-summary.log | sort -n | xargs` )
( set +x ; perl -w ${TESTSRC}/check-native-memory-usage.pl "Code-malloc:2.6,Code-mmap:2.8,Compiler-malloc:4.6" `ls *-native_memory-summary.log | sort -n | xargs` )
exitCode=$?

mkdir -p native_memory-summary ; mv *-native_memory-summary.log native_memory-summary/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,30 @@
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#usage: perl ${TESTSRC}/check-native-memory-usage.pl 2 `ls *-native_memory-summary.log | sort -n | xargs`
#usage: perl -w ${TESTSRC}/check-native-memory-usage.pl "Code-malloc:2.6,Code-mmap:2.8,Compiler-malloc:4.6" `ls *-native_memory-summary.log | sort -n | xargs`
use strict;
use warnings;
my $verbose = 2;
use POSIX;
my $verbose = 0;

die "please input multiple and more than 2 jcmd native log files" if( @ARGV < 3 );
my $multiple = shift @ARGV;
my $baseline = parserJcmdResult(shift(@ARGV));
foreach my $file ( @ARGV )
die "please input rules and more than 2 jcmd native log files" if( @ARGV < 3 );
my $rules = shift @ARGV;
my $lastIndexResultHash = parserJcmdResult(pop(@ARGV));
my $thirdIndexResultHash = parserJcmdResult($ARGV[ceil(scalar(@ARGV)/3)]);

foreach my $rule ( split /,/, $rules )
{
my $data = parserJcmdResult($file);
foreach my $key ( keys %$data )
print("rule: $rule\n");
my($moduleName, $coefficient) = split /:/, $rule;
print("$moduleName: $coefficient\n") if( $verbose > 3 );
my $lastIndexValue = $lastIndexResultHash->{$moduleName};
my $thirdIndexValue = $thirdIndexResultHash->{$moduleName};
die "can't find $moduleName memory usage information!" if( ! defined $lastIndexValue );
die "can't find $moduleName memory usage information!" if( ! defined $thirdIndexValue );
my $compareValue = $thirdIndexValue * $coefficient;
if( $lastIndexValue > $compareValue )
{
my $currentValue = $data->{$key};
my $baselineValue = $baseline->{$key};
print("$file:$key: $currentValue -> $baselineValue\n") if($verbose == 2);
my $coefficient = 1;
$coefficient = 5 if( "Code" eq "$key" );
$coefficient = 20 if( "Class" eq "$key" );
$coefficient = 20 if( "Module" eq "$key" );
$coefficient = 20 if( "Synchronizer" eq "$key" );
$coefficient = 10 if( "ArenaChunk" eq "$key" );
my $compareValue = $baselineValue * $multiple * $coefficient;
if( $currentValue > $compareValue )
{
die "$file:$key: $currentValue > $compareValue=$baselineValue*$multiple*$coefficient";
}
die "$moduleName: $lastIndexValue > $compareValue=$thirdIndexValue*$coefficient";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#usage: perl ${TESTSRC}/get-native-memory-usage.pl `ls *-native_memory-summary.log | sort -n | xargs`
#usage: perl -w ${TESTSRC}/get-native-memory-usage.pl `ls *-native_memory-summary.log | sort -n | xargs`
use strict;
use warnings;
use POSIX;
Expand All @@ -35,11 +35,16 @@
my %resultMinValue;
my %resultMinIndex;
my %resultQuarterValue;
my %resultThirdValue;
my %resultHalfValue;
my %resultLastValue;
my $plotDataDir = "plot-data";
my $lastFile = $ARGV[-1];
$lastFile =~ /^([0-9]+)-.*?/;
my $lastIndex = $1;
my $quarterIndex = ceil($lastIndex / 4);
my $thirdIndex = ceil($lastIndex / 3);
my $halfIndex = ceil($lastIndex / 2);
die "lastIndex undefine!" if( ! defined $lastIndex );

foreach my $key ( sort keys %$baseline )
Expand Down Expand Up @@ -78,6 +83,18 @@
{
$resultQuarterValue{$key} = $value;
}
if( $index == $thirdIndex )
{
$resultThirdValue{$key} = $value;
}
if( $index == $halfIndex )
{
$resultHalfValue{$key} = $value;
}
if( $index == $lastIndex )
{
$resultLastValue{$key} = $value;
}
}
}

Expand All @@ -88,7 +105,7 @@

open(my $csvFh, ">native-memory-summary.csv");
open(my $summaryFh, ">native-memory-summary.txt");
print $summaryFh ("total $lastIndex files, quarter index is $quarterIndex.\n");
print $summaryFh ("total $lastIndex files, quarter index is $quarterIndex, third index is $thirdIndex, half index is $halfIndex.\n");
foreach my $key ( sort @nameArray )
{
print $csvFh "$resultCsv{$key}\n";
Expand All @@ -98,9 +115,16 @@
print("$key minimum vaule is $minValue, the minimum value will set to 0.01 to log file.\n");
$minValue = 0.01;
}
my $maxMultiple = ceil($resultMaxValue{$key} / $minValue);
my $quartermultiple = ceil($resultQuarterValue{$key} / $minValue);
print $summaryFh "$key\tmax=$resultMaxValue{$key},index=$resultMaxIndex{$key}\tmin=$minValue,index=$resultMinIndex{$key}\tquarter=$resultQuarterValue{$key}\tmax/min=$maxMultiple\tquarter/mix=$quartermultiple\n";
my $maxMultiple = sprintf("%.1f", $resultMaxValue{$key} / $minValue);
my $quarterMultiple = sprintf("%.1f", $resultLastValue{$key} / $resultQuarterValue{$key});
my $thirdMultiple = sprintf("%.1f", $resultLastValue{$key} / $resultThirdValue{$key});
my $halfMultiple = sprintf("%.1f", $resultLastValue{$key} / $resultHalfValue{$key});
my $thirdSurprise = "";
if( $thirdMultiple >= 2.0 )
{
$thirdSurprise = "!!";
}
print $summaryFh "$key\tmax=$resultMaxValue{$key},index=$resultMaxIndex{$key}\tmin=$minValue,index=$resultMinIndex{$key}\tquarter=$resultQuarterValue{$key},half=$resultHalfValue{$key}\tmax/min=$maxMultiple\tlast/quarter=$quarterMultiple\tlast/third=$thirdMultiple$thirdSurprise\tlast/half=$halfMultiple\n";

#write plot data
my @data = split /,/, $resultCsv{$key};
Expand Down

0 comments on commit 46bc492

Please sign in to comment.