Java Profiling with hprof (default java profiler)

2012.01.06 23:37
hprof is comes with the java by default 

Outline
1. CPU Hog 
2. Memory Leak
3. Deadlock

See all available options
># java -Xrunhprof:help

Run hprof
># java -agentlib:hprof=[<options>=<value>,...] MemoryLeak
OR
># java -Xrunhprof[:<options>=<value>,...] MemoryLeak

* Output file: java.hprof.txt 

1. Diagnose a CPU hog
- Download a sample source code, 


># javac CPUHog.java

- Run hprof
># java -Xrunhprof:cpu=samples,thread=y CPUHog

># java -Xrunhprof:cpu=times,thread=y CPUHog


- Analyze which method using the most CPU
CPU SAMPLES
* It seems I can't figure out how to get the correct output like in the web site, but here is what I have. 



CPU TIMES
* Even with this output, I cannot find Slouch, WorkingStiff, Workaholic method. 



2. Diagnose a Memory Leak

- Download a sample source code, 


- Run hprof
># javac MemoryLeak.java
># java -Xrunhprof MemoryLeak
># vim java.hprof.txt

- Let's find the memory leak



We see that MemoryConsumer is created in the main. I should fix the line 16. 

3. Diagnose deadlock

- Download source code, 


># javac ClassicDeadlock.java

- Run hprof
># java -Xrunhprof ClassicDeadlock

* Run the deadlock occurs, hit Ctrl+\ which will generate the dump file 

- Find the deadlock



References
1. Diagnose common runtime problems with hprof, http://www.javaworld.com/javaworld/jw-12-2001/jw-1207-hprof.html
2. Perfornance Analysis, http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf3.html
3. A Heap/CPU Profiling Tool, http://java.sun.com/developer/technicalArticles/Programming/HPROF.html
4.  
저작자 표시
신고

'programming > java' 카테고리의 다른 글

Java Profiling with hprof (default java profiler)  (1) 2012.01.06
Profiling Java Application using YourKit (on Mac)  (0) 2012.01.06
SQLite with Java  (0) 2010.11.12
java.lang.OutOfMemoryError  (0) 2010.04.08
Get host name & IP address of the local system using Java  (0) 2010.03.24
getInstance  (0) 2009.11.30

Frank kenshin579 programming/java hprof, Java profiler

  1. Blog Icon

    비밀댓글입니다

Profiling Java Application using YourKit (on Mac)

2012.01.06 21:44
YourKit allows us to profile J2EE web application (ex. JSP) and shows live performance in graphs.

Setup YourKit
1. Download YourKit from http://www.yourkit.com/java/profiler/index.jsp

Setup YourKit Plugin for Eclipse Indigo (3.7.1)
1. Go to Help > Install New Software and add the following repository
http://www.yourkit.com/download/yourkit10_for_eclipse/ 



2. Install the plugin



Watch all flash demos on the website. It's quite helpful. 


Let's run some sample code and trace with YourKit
* I am going to use three sample codes from #3

1. Memory Leak (not releasing objects)
- Open up Profile Configurations from Eclipse and make sure to click on Memory Profiling.




 

We can see that byte[] is kept accumulated which indicates we are not deleting the object properly. 

2. CPU Hog
* It quite easy to see which method uses the most CPU times. 
- Thread trace


- Method list


- Time traces (invocation count)




3. Deadlock detector
- Deadlock found pop-up window


- Deadlocks result
 


- Thread trace
 



References
1. Completing Eclipse plugin installation, http://www.yourkit.com/docs/10/help/complete_eclipse36.jsp
2. Watch demo, http://www.yourkit.com/docs/index.jsp
3. Java Profiling with hprof, http://kenshin579.tistory.com/456
4. 
 
저작자 표시
신고

'programming > java' 카테고리의 다른 글

Java Profiling with hprof (default java profiler)  (1) 2012.01.06
Profiling Java Application using YourKit (on Mac)  (0) 2012.01.06
SQLite with Java  (0) 2010.11.12
java.lang.OutOfMemoryError  (0) 2010.04.08
Get host name & IP address of the local system using Java  (0) 2010.03.24
getInstance  (0) 2009.11.30

Frank kenshin579 programming/java Java profiler, YourKit