Visit Azul.com Support

Showing Available Heap Sizes

Table of Contents

Looking for Zing? The Azul Zing Virtual Machine is now Azul Zulu Prime Builds of OpenJDK and part of Azul Platform Prime. Learn more.

You can use zing-ps and awk commands to show available heap sizes in MB. The output of the zing-ps -acct command is in bytes; you might prefer to think in Megabytes.

This technique is based on the zing-ps –acct command and is a one-line script that uses the Linux grep command to search the output combined with the Linux awk command to calculate and format the output.

The output from the zing-ps –acct command is searched by grep for the line containing the Committed string. The awk command uses $3 to select the third field which is the available balance in column three of the output with the heading BALANCE.

  • The following one-line script prints the maximum Available Heap size for the JVM command option –Xmx and if other JVMs have already been started this is less than the maximum Reservable value in column four headed MAXIMUM.

     
    $ echo "Zing Available Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($3/(1024*1024))}'
  • To read the total Reservable value in MB, in this one-line script the awk command is modified to use $4 to select the fourth field which is the MAXIMUM balance

$ echo "Zing Total Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($4/(1024*1024))}

Example 1: No JVMs have been started.

 
[[email protected] bin]# zing-ps --acct
 
Fund breakdown (total 8) NAME BALANCE MAXIMUM fund[0]: Committed 4041211904 4041211904 fund[1]: Overdraft 222298112 222298112 fund[2]: Unknown 0 0 fund[3]: PausePrevention 222298112 222298112 fund[4]: Unknown 0 0 fund[5]: Unknown 0 0 fund[6]: Unknown 0 0 fund[7]: Unknown 0 0 Found 0 processes. [[email protected] bin]# echo "Zing Available Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($3/(1024*1024))}'` Zing Available Heapsize (MB) is 3854 [[email protected] bin]# echo "Zing Total Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($4/(1024*1024))}'` Zing Total Heapsize (MB) is 3854 root 5785 java NAME BALANCE ALLOCATED MAXIMUM FND ODFND account[0]: default 10485760 2097152 12582912 0 1 account[1]: emergency_gc 0 0 0 -1 -1 account[2]: heap 555745280 505413632 1283457024 0 1 account[3]: pause_prevention 0 0 274877906944 3 3 account[4]: unknown 0 0 0 -1 -1 account[5]: unknown 0 0 0 -1 -1 account[6]: unknown 0 0 0 -1 -1 account[7]: unknown 0 0 0 -1 -1 [[email protected] bin]# echo "Zing Available Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($3/(1024*1024))}'` Zing Available Heapsize (MB) is 2830 [[email protected] bin]# echo "Zing Total Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($4/(1024*1024))}'` Zing Total Heapsize (MB) is 3854

Example 2: An Azul Inspector 1GB JVM has been started.

See Azul Systems website to download free Open Source tool Azul Inspector, at https://www.azul.com/products/open-source-tools/azul_inspector.

 
[[email protected] bin]# zing-ps --acct Fund breakdown (total 8) NAME BALANCE MAXIMUM fund[0]: Committed 2967470080 4041211904 fund[1]: Overdraft 222298112 222298112 fund[2]: Unknown 0 0 fund[3]: PausePrevention 222298112 222298112 fund[4]: Unknown 0 0 fund[5]: Unknown 0 0 fund[6]: Unknown 0 0 fund[7]: Unknown 0 0 Found 1 processes. USER PID PROCESS root 5785 java NAME BALANCE ALLOCATED MAXIMUM FND ODFND account[0]: default 10485760 2097152 12582912 0 1 account[1]: emergency_gc 0 0 0 -1 -1 account[2]: heap 555745280 505413632 1283457024 0 1 account[3]: pause_prevention 0 0 274877906944 3 3 account[4]: unknown 0 0 0 -1 -1 account[5]: unknown 0 0 0 -1 -1 account[6]: unknown 0 0 0 -1 -1 account[7]: unknown 0 0 0 -1 -1 [[email protected] bin]# echo "Zing Available Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($3/(1024*1024))}'` Zing Available Heapsize (MB) is 2830 [[email protected] bin]# echo "Zing Total Heapsize (MB) is "`zing-ps --acct|grep Committed|awk '{print int($4/(1024*1024))}'` Zing Total Heapsize (MB) is 3854