which java profiler?

im currently searching for performance bottlenecks so if tryed the trial of jprofiler but i have a lot inner loops wich call some get methods and the cpu profiling vom jprofiler seems to give realy wrong info about whats happening there :confused: (more info: see below)

so what im searching is a profiler wich can give me exact information about whats uses a lot cpu-time and what not… especialy in inner loops wich are processed some thousend times per frame
it would be perfect if it is freeware or at least free for non comercial use…

so wich profiler do u use?
or wich would u suggest to try out?

//-------------------------------
my problem with jprofiler:
as i said method calls in inner loops are profiled very wrong (it seems the profiler counts its own overheat)

my testscenario in short (full code at the bottom):
-one method (perGetter()) wich gets the data out of an object over the get method
-one method (direct()) wich breaks the oop style and directly accesses the membervariables
both iterate over a larg array filled with test objects

results by manualy checking the time before and after such a method call:
getter time:1.093902716 sec
direct time:1.104081944 sec

getter time:1.057655652 sec
direct time:1.0200114820000001 sec

getter time:1.214332269 sec
direct time:1.061467309 sec

jprofiler tells me that perGetter() uses 95% cpu time and direct() 5%
well thats a too big mistake so that it is realy impossible to work with this profiler :confused:

the testscenario:

import java.util.Random;

class helper{
      int a;
      byte b;
      float c;
      double d;
      
      static int MULTIPLY = 50000;
      static Random rand = new Random();
      
      public helper() {
            a=rand.nextInt(MULTIPLY);
            b=(byte)(0xFF&rand.nextInt());
            c=rand.nextFloat()*MULTIPLY;
            d=rand.nextDouble()*MULTIPLY;
      }

      public int getA() {
            return a;
      }
      public byte getB() {
            return b;
      }
      public float getC() {
            return c;
      }
      public double getD() {
            return d;
      }
      
}


public class profilerTest {
      static helper h[];

      static long t1,t2,t3;
      static double d1=0,d2=0;
      
      static int repeats = 5;
      
      public static void main(String[] args) {
            for (int i=0;i<3;i++){
                  makeArray(1000000);
                  
                  test();
            }
            
            //wait forever
            while(true){
                  try {
                        Thread.sleep(Integer.MAX_VALUE);
                  } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                  }
            }

      }
      
      static void test(){
            d1=d2=0;
            
            t1=System.nanoTime();
            
            for(int j = 0; j<repeats;j++)
                  d1+=perGetter();
            
            t2=System.nanoTime();
            
            for(int j = 0; j<repeats;j++)
                  d2+=direct();
            
            t3=System.nanoTime();
            
            System.out.println("getter:"+d1+" \t\ttime:"+
            ((t2-t1)*1e-9));
            System.out.println("direct:"+d2+" \t\ttime:"+
            ((t3-t2)*1e-9));
            System.out.println();

      }
      
      static double perGetter(){
            double ret =0 ;
            for (helper i : h) {
                  ret-=i.getA();
                  ret+=i.getB();
                  ret-=i.getC();
                  ret+=i.getD();
            }
            return ret;
      }
      
      static double direct(){
            double ret =0 ;
            for (helper i : h) {
                  ret-=i.a;
                  ret+=i.b;
                  ret-=i.c;
                  ret+=i.d;
            }
            return ret;
      }
      
      static void makeArray(int count){
            h=new helper[count];
            for (int i=0; i<count; i++) {
                  h[i]=new helper();
            }
      }

}

Personally, i love yourkit.com profiler:

http://www.yourkit.com

Simply rocks! Dont know about number reliability tho and stuff like that…

DP

I just ran your test with yourkit.com

my results:

And this is what it said:

direct() uses 12% of the CPU
perGetter() uses 16% of the CPU
makeArray(int) uses 71% of the CPU, 58% of that goes to the Helper class and 100% of that goes to Random.nextXXX() call.

Are those the results you expected?

DP

[quote]Personally, i love yourkit.com profiler:

http://www.yourkit.com

Simply rocks! Dont know about number reliability tho and stuff like that…

DP
[/quote]
500$. lol.

Here is a nice list of open source profilers:
http://www.manageability.org/blog/stuff/open-source-profilers-for-java/view

since he was using JProfiler, i assumed he wanted commercial quality stuff… ;D

But seriously, yourkit.com is awsome and well worth the email if you have an opensource project :slight_smile:

DP

Yea… but who wants to use several sets of tools? I rather don’t use it at all then.

It’s yet another example of bad market segmentation. The big corporations with lots of money get it really cheap. Only 2350$ for an unlimited license. That means 2.25$ for each of your 1000 machines.

And the small independent developer has to pay 500 bucks for it. Wow. That’s like so smart.

[BTW this thread should be over at the tools forum]

[quote]direct() uses 12% of the CPU
perGetter() uses 16% of the CPU
makeArray(int) uses 71% of the CPU, 58% of that goes to the Helper class and 100% of that goes to Random.nextXXX() call.
[/quote]
that means that direct uses 42%
and perGetter 58% das looks much much better…
but well 500$$… (oww i see that jprofiler also costs 400$)
ill have to look for those free ones… especialy cause i wont use it for commercial development… and also dont have a open source project to show…

so are there some other open source profilers wich u can suggest?
ill now take a look at those suggestet from oNyx

thx for your answers

well, if you have an opensource project that as an active community, you can email yourkit.com and they will send you a license for their profiler.

DP

I use this eclipse plugin, enougth for me :slight_smile:
http://eclipsecolorer.sourceforge.net/index_profiler.html

heard a lot of good about yourkit, but never tried (500$ … ekk)

@dark prophed
all i have is a private project wich will hopefully see daylight before 2010 (or hopefully will see it ever)

thx to Ken Russel iv found out that there are 2 build in profilers in the jvm one is -Xprof the other one is -agentlib:hprof wich is much more complex than the first one… ill have to test if its usefull or not…
also hes suggested JFluid but it seems its called now The NetBeans Profiler Project… and it seems it can only profile 1.4 bytecode… but im using heavily 1.5 stuff like templates or whatever :confused:

iv now tested -agentlib:hprof a bit and it seems that it also gives very wrong output with cpu timing enabled but ok output with sampling (but however sampling is not realy accurate because of the way its done :/)

[quote]I use this eclipse plugin, enougth for me :slight_smile:
http://eclipsecolorer.sourceforge.net/index_profiler.html
[/quote]
I tried it and I like it, seems to be good piece of software.
BTW have you tried profiling java api classes? I would especially like to know how often is called new String() It should be possible, I tried to set up filters, but I just could not get it working. For my own classes it works very well. If you have some time please try it.