Reputation: 940
I have a project in Netbeans that I am profiling (using Java 7). What I am looking for is, upon a garbage collection, how much memory from the Eden space is going into the Survivor spaces, and if there is any memory overflowing into the Tenured space. On top of that, I am looking for how the Tenured space is growing in size over time.
I print GC stats but I only get info like this:
2339.967: [GC 2339.967: [ParNew: 66213K->4522K(69376K), 0.0161101 secs] 284589K->223320K(369484K), 0.0161685 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
2344.543: [GC 2344.543: [ParNew: 66218K->4520K(69376K), 0.0161084 secs] 285016K->223739K(369484K), 0.0161647 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
2349.118: [GC 2349.118: [ParNew: 66216K->4519K(69376K), 0.0159046 secs] 285435K->224159K(369484K), 0.0159587 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
Anyone know of a way to figure out the information I am looking for?
Thanks!
Upvotes: 7
Views: 14012
Reputation: 9028
A simple solution is to use jstat
, this shows the occuptation of all different memory regions (Eden, Survivor spaces) across all generations.
Use e.g.
jstat -gcutil -t <pid> <interval> <number_of_samples>
Example output:
jstat -gcutil 21891 250 7
S0 S1 E O P YGC YGCT FGC FGCT GCT
12.44 0.00 27.20 9.49 96.70 78 0.176 5 0.495 0.672
12.44 0.00 62.16 9.49 96.70 78 0.176 5 0.495 0.672
12.44 0.00 83.97 9.49 96.70 78 0.176 5 0.495 0.672
0.00 7.74 0.00 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 23.37 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 43.82 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 58.11 9.51 96.71 79 0.177 5 0.495 0.673
Explanation:
The output of this example shows that a young generation collection occurred between the 3rd and 4th sample. The collection took 0.001 seconds and promoted objects from the eden space (E) to the old space (O), resulting in an increase of old space utilization from 9.49% to 9.51%. Before the collection, the survivor space was 12.44% utilized, but after this collection it is only 7.74% utilized.
More heavyweight options are profilers, e.g. JVisualVM with GC monitoring, or the new Java Mission Control with Java 7u40.
Also, consider the following GC options: -XX:+PrintTenuringDistribution
, -XX:MaxTenuringThreshold
.
Upvotes: 6
Reputation: 14361
Oracle's JDK comes standard now with jvisualvm
which is a free profiler. It will show you what's eating up memory, cpu, threads, network time, db access, etc. Yes, it even shows GC time and a bunch of other goodies about GC in general.
Best part, it's free! (and it may already be installed on your system if you have Oracle JDK)
http://www.youtube.com/watch?v=dUQqmnmCBbg
http://docs.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html
Upvotes: 6
Reputation: 191
Here are some useful GC flags:
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintClassHistogram
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintTenuringDistribution should give you what you are looking for.
Upvotes: 15
Reputation: 2629
Use the -XX:+PrintGCDetails
flag to enable printing more details.
Upvotes: 1