简体   繁体   English

调用在netbeans配置文件中计数

[英]Invocations count in netbeans profiles

When I use the profiler in NetBeans 7.1 , I am not seeing the expected invocation number for my methods. NetBeans 7.1中使用探查器时,没有看到我的方法的预期调用号。

To test this I created a simple program that has 3 methods that are each called ten thousand times. 为了测试这一点,我创建了一个简单的程序,其中包含3个方法,每个方法被称为一万次。

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. 我希望在分析结束时在探查器快照中看到每个方法10000次调用。 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: 这是结果的屏幕截图:

在此处输入图片说明

I did some more digging, and found this bug report that talks about intrinsic methods and method inlining in the java hotspot compiler. 我做了一些进一步的挖掘,发现了这个bug报告 ,该报告讨论了Java热点编译器中的内在方法和方法内联。 The suggested fix there is to use -Xint option for jdk1.6. 建议的解决方案是对jdk1.6使用-Xint选项。 On JDK 1.7 however, this doesn't change my results. 但是在JDK 1.7上,这不会改变我的结果。

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. 当5个样本连续击中short方法位于堆栈顶部时,它将被计为一次调用,因为从sampler的POV中不会退出short方法。

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. 否则,您需要在采样调用中加一点盐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM