This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
How do I analyze and conclude the performance of simple java program in general like have i used the right datatypes, do the program executes in less time, would i suppose to use any other datatypes for better performance etc. Also, how do I track the execution time of java program.
VisualVM and jhat (both free and installed tohether with the jvm) can give you the number of allocated instances.
For profiling method timings, I would not recommend visualvm or Netbeans or anything JVMTI/JVMPI/introspection based,because these profilers cause huge overheads and results are often bogus. My personal win is the StackProbe profiler - great accuracy, ease of use and low overheads, however it is free only for opensource projects.
Toby Eggitt wrote:On this topic, what profiler tools do people recommend (for use inside Eclipse, specifically)?
I want to look at method timings, object instances, and total memory used by objects of any given class.
Othervise you could try JRockit Mission Control. It will also give you statistics about the number of object instances on the heap and how much memory they occupy, both live using the Memory Leak Detector or stored in a file for offline analysis using the JRA-tool. The overhead for method profiling is very low, less than 1% or so, because the tool piggybacks on the hot spot detector the JVM uses. You can get the the Eclipse plugins from the update site. The tool can also give you cheap memory allocation profiling.
Both tools are free to use for development and you can jump to the souce code in your Eclipse projects.
I know this is a simplistic answer, but there are times when the easiest way to get the job done is to code a simple millisecond timer using Date methods, or maybe the Calendar interface. Place these at appropriate locations in your code, and you have a quick and easy way during development to measure improvements in algorithm speed, or check suspected bottlenecks, without having to mess around with learning a resource hungry performance evaluator.
p.s. I see this thread is a little old, but I thought I'd throw this in there.
Kees Jan Koster
Joined: Mar 31, 2009
I agree and that is what I use mostly. Or rather, I mainly use a mish-mash of the tool-du-jour and print statements that do simple timing. Tools tend to find stuff you had never though of, and print statements serve to track problems that I know are there.
Joined: Dec 10, 2007
Fred Hamilton - I can't agree it's the best way to go, tweaking existing code to add the 'statistics gathering' by hand - I thought that's what the tools were for ? But hey, I might be wrong ;)
Joined: May 13, 2009
Lucas Lech wrote:Fred Hamilton - I can't agree it's the best way to go, tweaking existing code to add the 'statistics gathering' by hand - I thought that's what the tools were for ? But hey, I might be wrong ;)
Fair enough, but notice I said "sometimes" and I was speaking more of the development phase, looking for ways to refine algorithms to improve performance. And it depends how advanced of a programmer you are too. And I wasn't really talking about statistics gathering,unless you want to call putting a simple timer on a method call statistics gathering.
But yeah, once code is nailed down, their ain't much point in my suggestion. And if your performance analysis needs are complex, then I imagine my idea would fall short also.
you can use jvmstat+visualgc together to see the garbage collection of your application so you can find if there is a memory leak in your application.
Eclipse MAT can only show you the analysis by reading a memory dump file. I have blogged about how to set up jvmstat+visualgc if you are interested here
if who i am is what i have, and what i have is lost, then who am i?<br /> <br />SCJP 5.0<br />SCWCD 1.4<br />SCBCD preparing