From c6ee8f0702805c3b11ae91294492a3c5c85068b1 Mon Sep 17 00:00:00 2001 From: sendaoYan Date: Mon, 16 Sep 2024 18:12:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=9C=A8check-native-memory-?= =?UTF-8?q?usage.pl=E8=84=9A=E6=9C=AC=E9=87=8C=E6=94=B6=E9=9B=86=E6=95=B4?= =?UTF-8?q?=E7=90=86NMT=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=B9=B6=E5=AF=B9?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E8=BF=9B=E8=A1=8C=E6=A3=80=E6=9F=A5=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E7=A1=AE=E8=AE=A4=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codecache/stress/CodecacheMemoryCheck.sh | 3 +- .../stress/check-native-memory-usage.pl | 156 ------------------ .../stress/get-native-memory-usage.pl | 30 +++- 3 files changed, 30 insertions(+), 159 deletions(-) delete mode 100755 test/hotspot/jtreg/compiler/codecache/stress/check-native-memory-usage.pl diff --git a/test/hotspot/jtreg/compiler/codecache/stress/CodecacheMemoryCheck.sh b/test/hotspot/jtreg/compiler/codecache/stress/CodecacheMemoryCheck.sh index b80e19a56c5..5409ba15d11 100755 --- a/test/hotspot/jtreg/compiler/codecache/stress/CodecacheMemoryCheck.sh +++ b/test/hotspot/jtreg/compiler/codecache/stress/CodecacheMemoryCheck.sh @@ -209,10 +209,9 @@ if grep -q "Unable to open socket file" *-native_memory-summary.log ; then exit 1 fi -( set +x ; perl -w ${TESTSRC}/get-native-memory-usage.pl 25 `ls *-native_memory-summary.log | sort -n | xargs` ) -generatePlotPNG ( set +x ; perl -w ${TESTSRC}/check-native-memory-usage.pl 25 "Code-malloc:2.6,Code-mmap:2.8,Compiler-malloc:4.6" `ls *-native_memory-summary.log | sort -n | xargs` ) exitCode=$? +generatePlotPNG mkdir -p native_memory-summary ; mv *-native_memory-summary.log native_memory-summary/ diff --git a/test/hotspot/jtreg/compiler/codecache/stress/check-native-memory-usage.pl b/test/hotspot/jtreg/compiler/codecache/stress/check-native-memory-usage.pl deleted file mode 100755 index b28fe547d2c..00000000000 --- a/test/hotspot/jtreg/compiler/codecache/stress/check-native-memory-usage.pl +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/perl -w -# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# 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 -w ${TESTSRC}/check-native-memory-usage.pl 25 "Code-malloc:2.6,Code-mmap:2.8,Compiler-malloc:4.6" `ls *-native_memory-summary.log | sort -n | xargs` -use strict; -use warnings; -use POSIX; -my $verbose = 0; - -die "please input split number, rules and more than 3 jcmd native log files" if( @ARGV < 10 ); -my $split = shift @ARGV; -my $rules = shift @ARGV; -my $lastIndexResultHash = parserJcmdResult($ARGV[-1]); -my $thirdIndexResultHash = parserJcmdResult($ARGV[ceil(scalar(@ARGV)/3)]); -my %isIncreasementalResult; -my @allData; -foreach my $file ( @ARGV ) -{ - my $result = parserJcmdResult($file); - push @allData, $result; -} - -foreach my $rule ( split /,/, $rules ) -{ - 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 ) - { - die "$moduleName: $lastIndexValue > $compareValue=$thirdIndexValue*$coefficient"; - } -} - -sub parserJcmdResult -{ - my ($filename) = @_; - my %malloc; - my $name; - my $number; - open(my $fh, "<$filename") or die "Can't open file '$filename' $!"; - foreach my $line ( <$fh> ) - { - chomp($line); - if( $line =~ /^-\s*(.*)\s+\(/ ) - { - $name = $1; - $name =~ s/\s+//g; - $number = -1; - next; - } - if( $line =~ /\(malloc=([0-9]+)KB/ ) - { - $number = $1; - die "filename=$filename\tline=$line can't get name!\n" if( length($name) <= 0 ); - my $key = "$name" . "-malloc"; - print("name=$key\t\tnumber=$number\n") if( $verbose == 1 ); - $malloc{$key} = $number; - next; - } - if( $line =~ /\(mmap:.*committed=([0-9]+)KB/ ) - { - $number = $1; - die "filename=$filename\tline=$line can't get name!\n" if( length($name) <= 0 ); - my $key = "$name" . "-mmap"; - print("name=$key\t\tnumber=$number\n") if( $verbose == 1 ); - $malloc{$key} = $number; - next; - } - } - close($fh); - return \%malloc; -}; - -sub isIncreasemental -{ - my @array = @_; - my $length = scalar(@array); - my $windowLength = floor($length/$split); - warn("windowLength=$windowLength\n") if( $verbose > 0 ); - my $count = $windowLength * $split; - warn("count=$count, $length=$length\n") if( $verbose > 0 );; - my $previousSum = 0; - my $steady = 0; - my $result = 0; - - #calculate the main part data - foreach my $i ( 0..$split-1 ) - { - my $currentSum = 0; - foreach my $j (0..$windowLength-1) - { - my $index = $i*$windowLength+$j; - $currentSum += $array[$i*$windowLength+$j]; - } - $currentSum /= $windowLength; - warn("currentSum=$currentSum, previousSum=$previousSum\n") if( $verbose >= 3 ); - if( $currentSum < $previousSum ) - { - $result++; - warn("currentSum=$currentSum, previousSum=$previousSum\n") if( $verbose >= 1 ); - } - elsif( $currentSum == $previousSum ) - { - $steady++; - } - $previousSum = $currentSum; - } - - #calculate the tail data - my $currentSum = 0; - foreach my $i ( $count .. ($length-1) ) - { - $currentSum += $array[$i];; - } - $currentSum /= ($length-$count); - if( $currentSum < $previousSum ) - { - $result++; - warn("currentSum=$currentSum, previousSum=$previousSum\n") if( $verbose >= 1 ); - } - elsif( $currentSum == $previousSum ) - { - $steady++; - } - - #statistics the result - warn("steady=$steady, split=$split\n") if( $verbose >= 2 ); - if( $steady == $split ) - { - $result = -1; - } - return $result; -} diff --git a/test/hotspot/jtreg/compiler/codecache/stress/get-native-memory-usage.pl b/test/hotspot/jtreg/compiler/codecache/stress/get-native-memory-usage.pl index 77e4faf0793..2bfeb3ea3b1 100755 --- a/test/hotspot/jtreg/compiler/codecache/stress/get-native-memory-usage.pl +++ b/test/hotspot/jtreg/compiler/codecache/stress/get-native-memory-usage.pl @@ -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 -w ${TESTSRC}/get-native-memory-usage.pl 25 `ls *-native_memory-summary.log | sort -n | xargs` +#usage: perl -w ${TESTSRC}/get-native-memory-usage.pl 25 "Code-malloc:2.6,Code-mmap:2.8,Compiler-malloc:4.6" `ls *-native_memory-summary.log | sort -n | xargs` use strict; use warnings; use POSIX; @@ -28,6 +28,7 @@ die "please input split number and more than 3 jcmd native log files" if( @ARGV < 10 ); my $split = shift(@ARGV); +my $rules = shift(@ARGV); my $baseline = parserJcmdResult(shift(@ARGV)); my @nameArray; my %resultCsv; @@ -39,6 +40,8 @@ my %resultThirdValue; my %resultHalfValue; my %resultLastValue; +my %isIncreasementalResultHash; +my $memoryLeakNumber = 0; my $plotDataDir = "plot-data"; my $lastFile = $ARGV[-1]; $lastFile =~ /^([0-9]+)-.*?/; @@ -126,6 +129,7 @@ my $halfMultiple = sprintf("%.1f", $resultLastValue{$key} / $resultHalfValue{$key}); my $thirdSurprise = ""; my $isIncreasementalResult = isIncreasemental(@data); + $isIncreasementalResultHash{$name} = $isIncreasementalResult; my $isMemoryLeak = ""; if( $thirdMultiple >= 2.5 ) { @@ -151,6 +155,30 @@ close($summaryFh); +my $lastIndexResultHash = parserJcmdResult($ARGV[-1]); +my $thirdIndexResultHash = parserJcmdResult($ARGV[ceil(scalar(@ARGV)/3)]); +foreach my $rule ( split /,/, $rules ) +{ + 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 && $isIncreasementalResultHash{$moduleName} == 0 ) + { + warn("$moduleName: $lastIndexValue > $compareValue=$thirdIndexValue*$coefficient"); + $memoryLeakNumber++; + } +} +if( $memoryLeakNumber > 0 ) +{ + die "memoryLeakNumber=$memoryLeakNumber!"; +} + + sub parserJcmdResult {