I was wanting to get heap dumps for my generic java application at regular intervals as csv files. Let's say I have a program
public class Test {
public static void main(String[] args) throws Exception {
// Code to be profiled
}
}
I wanted to check heap dumps at regular intervals after running the program and generate a csv as below
Time Committed size Free size Used size
0.0 251392000 235881000 15511000
1.0 456704000 264288000 192416000
2.0 1024000000 756641000 267359000
3.01 1035776000 217595000 818181000
4.01 1494528000 153111000 1341417000
5.02 1444352000 1235099000 209253000
6.02 1546240000 1185698000 360542000
This looks like the information which is fed to visualvm/jprofiler etc. for them to generate memory dump charts.
I could achieve it quite easily programatically(through cmd line and jprofiler api) using jprofiler with jcontroller and jpexport , but I haven't been able to figure out how to do the same with other similar tools like visualvm , jmap etc.
What I am looking for is a programatic way to profile a java program (here Test.java) without involving the GUI at all. There is a similar question asked here , but the solution suggested is that of Tracer plugin for visualvm which will again involve using the GUI. The closest solution I have found yet is to use JMX like in the given example here , but I couldn't get it to work for me.
Is there a way to achieve this for me ? As a side note I am using Java SE 8 on a mac.