I am looking for a tool that can provide VisuaVM-like profiling about live objects, but in non-GUI mode.
The Visual VM functionality I am referring, is accessed by going to the "Profiler" tab and clicking "Memory".
By setting a profile preset of "Profile object allocations and GC" for ever 1 objects (all objects). This gives me exactly what I need in an auto-refreshing view, which I can filter for the class that interests me.
However, I want to be able to export the table of "live objects" to a text file, for every snapshot that is taken (Visual VM refreshes every one seconds). Obviously, pointing and clicking cannot possibly be a solution...
Anyone know of such a "command-line" profiler?
I have been looking at jmap which provides heap dumps, but it is too costly (the dump takes too long, I am just interested in the number of objects).
There is a commercial tool called YourKit but I don't know whether it can do what I need (and also seems rather expensive for the type of "one-off" usage I need it for).
If I could use VisualVM as-is, but have it append the output to a file (instead of refreshing its GUI) it'd be perfect...
I think Class Histograms are what you look for. You could collect the histograms in regular intervals and this will show you number of objects of each class and occupied space. You can then parse the text output yourself in order to:
Collect class histogram with
jmap -histo $pid.