Reputation: 5721
I am looking for an easy way to find out how much memory the JVM on my computer has allocated to a specific process, i have tried using VisualVM, but it cannot find the process.
I should mention that this it's running a Windows Service, not a regular process.
Any suggestions ?
Thank in advance.
Upvotes: 5
Views: 14541
Reputation: 57
I use in android (if you want to know a programatic way):
// get the total memory for my app
long total = Runtime.getRuntime().totalMemory();
// get the free memory available
long free = Runtime.getRuntime().freeMemory();
// some simple arithmetic to see how much i use
long used = total - free;
System.out.println("Used memory in bytes: " + used);
Works for the PC too(just tested)!
Upvotes: 6
Reputation: 18459
JVisualVM should work for you. There are specific cases where the process is not shown in visualVM.
Local Applications Cannot Be Monitored (Error Dialog On Startup) Description: An error dialog saying that local applications cannot be monitored is shown immediately after VisualVM startup. Locally running Java applications are displayed as (pid ###). Resolution: This can happen on Windows systems if the username contains capitalized letters. In this case, username is UserName but the jvmstat directory created by JDK is %TMP%\hsperfdata_username. To workaround the problem, exit all Java applications, delete the %TMP%\hsperfdata_username directory and create new%TMP%\hsperfdata_UserName directory.
Upvotes: 1
Reputation: 327
there is a command that comes with the JRE called jps
which you can use to see all the running java processes. using jps
with -v
gives you the launch parameters of each process.
You can see here the launch parameters which will tell you the memory usage of each process.
This command should run also on Windows, just replace the terminal with a command prompt.
Upvotes: 7