Saturday Mar 08, 2008

Profiling with Netbeans 6

Working on industrial application,profiling project is one of the major
challenge. There are some of the profiling tools shipped with JDK like
jhat, jmap, jconsole. But week back, I start looking the profiling
power of Netbeans which is quite better than JDK tools. It provides
much better and relevant tools for profiling. Don't mind if it will not
able to connect VM sometime :). Here I have written one small code for
deadlock:



class DeadLockTest {
public static void main(String[] args) {
    Object lock1 = new String("Lock 1");
    Object lock2 = new String("Lock 2");
    new DeadLockCondition("t1", lock1, lock2);

    new DeadLockCondition("t2", lock2, lock1);
    }

}
class DeadLockCondition extends Thread {
Object lock1;

Object lock2;
DeadLockCondition(String name, Object lock1, Object lock2)

{

    super(name);

    this.lock1 = lock1;

    this.lock2 = lock2;

    start();

}
public void run() {

    while(true) {

        method();

    }

}

public void method() {

    synchronized(lock1) {

        method2();

    }

}
public void method2() {

    int count = 0;

    synchronized(lock2) {

        while(count<100000){

        count++;

        System.out.println(count);

        }

    }
}
}


Now I have started Netbeans Profiling. The best part is CPU profiling
which allow you to profile parts of project, no need to profile whole
project. It will show you heap memory, GC memory, classes loaded like:

 

 

Here you can definitely see how threads are waiting for each other in Thread view.

 


Now take the heap dump from Profiling option. It will by default open your heap dump in heap walker. Now in heap walker you can see classes, instances, size and lot many things. From classes we can directly go to the source code. See this:

 

 



And here I go in the source :)

 

 



There is lot to do here. But I am sick of pasting this image. Go ahead, and explore it :), it's worthwhile to spend some time. Right now, I am working on a printer memory leak problem. Will write more if able to solve with Profiling.


About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today