Invocations count in netbeans profiles

739 views Asked by At

When I use the profiler in NetBeans 7.1, I am not seeing the expected invocation number for my methods.

To test this I created a simple program that has 3 methods that are each called ten thousand times.

public class profilerTest {
    static int one;
    static int two;
    static int three;

    public static void main(String args[]) {
        for (int i = 0 ;i<= 10000; i++)one();
    }

    public static void one() {
        System.out.println("one:" + one++);
        two();
    }

    public static void two() {
        System.out.println("two:" + two++);
        three();
    }

    public static void three() {  
        System.out.println("three:" + three++);
    }
}

I expect to see 10000 invocations per method in my profiler snapshot that I take at the end of the profiling. However, the results I get gives significantly lower numbers of invocations for each method, and they are also different for each of the three methods.

I'm curious to what is causing this, and if and how it's possible to get the actual invocation count for each method.

Here is a screenshot of the results:

enter image description here

I did some more digging, and found this bug report that talks about intrinsic methods and method inlining in the java hotspot compiler. The suggested fix there is to use -Xint option for jdk1.6. On JDK 1.7 however, this doesn't change my results.

1

There are 1 answers

0
JB- On

If you are using the sampled mode this is expected. The profiler uses stack sampling to estimate the number of entries/exits for each method and also the duration of that particular method.

Due to sampling the invocation numbers can be completely off in some cases - like running really short methods really many times in loop. Eg. when 5 samples successively hit the short method being the top of the stack it will be counted as one invocation because from the POV of the sampler the short method never exited.

The time data are much more precise in sampling - the only delimiter is the sampling frequency.

If you want the exact invocation counts switch to the instrumented profiling mode. Otherwise you need to take the sampled invocations with a grain of salt.