Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get real RAM usage of current JVM with Java

In HTOP you can see the RES value (resident size) which shows how much of your RAM your JVM process is really taking.

Now I want to get that value by only using pure Java. If you tell me it's just not possible, that's fine as well.

Let me explain all the attempts I made with an application that shows a RES value of 887M in htop:

  1. Combining committed HeapMemory and non Heapmemory via MemoryMXBean gives me 726M
  2. Adding up all commited memory of all ManagementFactory.getMemoryPoolMXBeans() gives me 737M
  3. runtime.totalMemory() gives 515M

Any ideas what else I could try?

like image 901
ASA Avatar asked Sep 30 '22 12:09

ASA


1 Answers

Assuming you are running Linux, just read /proc/self/status file and look for VmRSS: line.

Or parse /proc/self/smaps to get comprehensive memory information for the current process.

like image 187
apangin Avatar answered Oct 06 '22 19:10

apangin