Build Your Own Java Performance Profiling Tool 153
An anonymous reader writes "IBM DeveloperWorks has an interesting look at creating a custom profiler using Java 5 and AOP. From the article: 'Profiling is a technique for measuring where software programs consume resources, including CPU time and memory. This article provides a list of best-of-breed features you might look for in an ideal profiler and explains why aspect-oriented techniques are well suited to achieving some of those features. It also introduces you to the JDK 5.0 agent interface and walks you through the steps of using it to build your own aspect-oriented profiler.'"
AspectJ (Score:3, Interesting)
Why not simply use AspectJ?
Re:AspectJ (Score:1)
The things he mentions are fun to do, and for some projects they may be necessary, but the big thing seems to be "My profiler is more customized than yours!" As for byte-code hacking and other "Refliective" programming techniques, that's the all-mighty Heavenly Father's (ar at least Matz's) gift to Ruby.
Re:AspectJ (Score:5, Interesting)
You could as easily ask "Why use AspectJ", couldn't you?
I mean... what you're trying to do in the case of profiling is _not_ change the actual byte code you're working on any more than neccessary. Is using the aspectj runtime somehow better than using the -javaagent JVM option? I'm going to guess here... not neccessarilly, unless you're using AspectJ anyway. If you're _not_ using AspectJ and are not familiar with all of the extra syntax that AspectJ introduces, it becomes very unclear that doing your profiling that way is really a good way to go.
How would you specifically do the same thing they're talking about in the article using AspectJ ? I'm asking as a Java programmer who has shied away from using AspectJ ( the reasons for using it to me have not become terribly compelling; I'm aware that some folks love it ). Is there an article somewhere that spells out how to do the same sort of thing using AspectJ or some other AOP system? Maybe that would be a helpful link, or make another good story.
Re:AspectJ (Score:2)
aspect ProfileAll {
pointcut myMethod(): execution(* *(..));
before(): myMethod() {
System.out.println(thisJoinPointStaticPart.getSign ature() + "/tstart/t" + System.currentTimeMillis());
}
after(): myMethod() {
Re:I Wrote 2 Articles on Monitoring with AspectJ (Score:2)
I wish I could mod that up. Obviously I missed the references in the original article. Thanks.
Re:AspectJ (Score:2)
Re:AspectJ (Score:2)
JVMPI (Score:2)
Yourkit YJP Re:JVMPI (Score:2)
jrat - Already does everything you need. (Score:5, Informative)
Download jrat here [sourceforge.net]
I've used it many times, and it's helped me find horrible Hibernate queries, Lucene bottlenecks, Batik rendering pipeline issues. It is fantastic.
jrat already does MOST everything you need. (Score:2)
Re:jrat already does MOST everything you need. (Score:2)
You can instantiate tomcat yourself, which means you have full control over the loading of the libraries. Just create your own classloader and inject your instructions as they're read from the JAR.
Re:jrat - Already does everything you need. (Score:2, Informative)
Glad to see SOMEONE takes performance seriously (Score:2)
HP is your friend (Score:2)
http://www.hp.com/products1/unix/java/hpjmeter/in
http://www.hp.com/products1/unix/java/java2/hpjtu
Re:HP is your friend (Score:2, Informative)
Er, Why is this in IT? (Score:3, Interesting)
I'd do that, but I'm a hybrid java developer/IT d00d. Most IT folk I know wouldn't touch a profiler with a 10-foot pole, much less write one and semi-build it into an app. This is a programming topic, not an IT one.
Re:Er, Why is this in IT? (Score:3, Insightful)
you really need more than hprof ? (Score:3, Interesting)
Using hprof and decent unit testing, you can work out where your problems are, I've found. All of this bytecode hacking and AOP stuff might show how l33t you are, but I'm not convinced it's really *needed*. Just my humble, uninformed opinion, of course, I'm very willing to hear from others. It could be that I'm just not working on sufficiently complex systems, or that I'm spending more time writing unit tests and pouring through hprof results than most folks.
Re:you really need more than hprof ? (Score:3, Interesting)
Re:you really need more than hprof ? (Score:3, Interesting)
Thanks, that was exactly the sort of post I was looking for.
So, to continue the discussion... do you think the approach outlined in the article would be usable or appropriate for the system you just described ? How
Re:you really need more than hprof ? (Score:2)
That's why I like the bytecode-injection-at-load-time idea - it works with normal code. If I think the code is too slow under the profiler, I can run the same class files without the profiler and see if it's the application or the profiler that'
Re:you really need more than hprof ? (Score:2)
You and I are so on the same page, it makes me smile a little. I officially apologize for pushing the hprof debate just to get this comment out of you, by the way. I think the injection technique looks pretty cool, as I'd much rather do that than modify ( and then have to change, by hand, again ) the source code to place timing information.
On the other hand, I'm a huge fan of writing unit and 'prototype' tests, although I understa
Re:you really need more than hprof ? (Score:5, Informative)
I like hprof -- it's helped me out more times that I can say, but it also has some short comings, which is why I developed JIP
For filtering, I've also got another option (Score:2)
It's a relatively simple script I wrote a while back to filter hprof textual output. It tells you things like "which of the code inside com.foo.* is being slow"? And "which of the code inside com.foo.* is causing StringBufffer.expandCapacity to be invoked, and thereby being slow?".
A further enhancement of it (that I haven't posted yet, sorry) changes the output format to look something like a java stack trace, which means you can take the output of that scri
Re:you really need more than hprof ? (Score:2)
That's true for the timing mode. The sampling mode is zippy. For most stuff that I do, it's good enough. It's generally pretty obvious which are blocking calls and which are actually using the CPU. Monitor contention can be a bit confusing sometimes, though - a relatively simple operation will have many, many samples because it's waiting on a monitor held by something more complex. This is good to show yo
Re:you really need more than hprof ? (Score:2)
This is a common problem with badly designed software. Software should be designed so that all parts can be unittested - and hence profiled - independently. Not only will such a design facilitate better and easier testing, it also makes the code more readable, extendable, and reusable.
"not responding" checker? Anyone? (Score:2)
We use CAD (Computer Aided Design) software, and I would like to justify new hardware by being able to say how much less time we would have to spend waiting on the software if we had faster computers.
If I had a way to measure how often the cursor was an hourglass in our CAD software during the course of a standard workweek and then benchmark this on a new computer I could have a metr
Re:"not responding" checker? Anyone? (Score:2)
Although I heard linux has limited support for profiling these days I dont know how good it is for monitoring regular applications in userspace.
sorry, Windows based... (Score:2)
Re:sorry, Windows based... (Score:2)
Its a shame the cad market is going to windows from unix. Its certainly no unix and the vendors drank the NT coolaid from all teh hype in the 90's.
No, not Autocad (Score:2)
>Its a shame the cad market is going to windows from unix.
I think you meant "from unix to windows"?
I'm not surprised. CAD is becoming more and more a commodity - it is currently running about $5000 a seat for stuff like SolidWorks or Pro/Engineer. There are less and less dollars to spend on things like multi-platform support.
Windows is the predominate desktop environment.
Personally, I don't care what the platform is.
Steve
Re:No, not Autocad (Score:2)
>Its a shame the cad market is going to windows from unix.
I think you meant "from unix to windows"?
I must be missing something. Is "to A from B" somehow different than "from B to A" ???
Not to me... (Score:2)
I'm not sure what you mean. The fellow was (I think) trying to lament how the CAD market was going from unix to Windows (though he
As I said - I don't care what platform the software runs on.
Steve
here's my profiler (Score:4, Funny)
Re:here's my profiler (Score:2)
% Some people say this'll never be quite as fast as hand-tuned C.
*snip*
Well, I think it really depends on whether you downloaded the hand-tuned C as a pre-build binary or compiled it yourself...
best-of-breed (Score:4, Funny)
One reason to do your own instrumentation (Score:3, Interesting)
JVMTI + JNI is pretty slick stuff. The source code to hprof comes with the JDK 1.5 release and is very informative, if overwhelming at first. If I instrument methods very selectively, the effect on runtime speed is minimal.
OTOH, trying to implement something like this for Perl (my favorite language) would be an exploration of pain the likes of which hasn't been experienced since people were broken on the wheel.
Re:One reason to do your own instrumentation (Score:2)
Mercury's Profiler (Score:1)
IDE/platform integration is, well... integral (Score:1)
Please, someone prove me wrong on this, but I can't seem to find a decent code profiler for use with J2EE or Eclipse RCP applications. You can't
Re:IDE/platform integration is, well... integral (Score:1, Informative)
http://profiler.netbeans.org/ [netbeans.org]
What AOP does not solve... (Score:1)
This annoys me greatly (Score:1, Insightful)
Java's a speed demon compared to almost all other programming languages out there. So what if it's 1/5 (warning : 97% of statistics are made up on the spot...) the speed of Assembly?
Re:This annoys me greatly (Score:1, Troll)
Re:This annoys me greatly (Score:1)
Re:This annoys me greatly (Score:2)
Re:This annoys me greatly (Score:2)
Java startup annoys me greatly (Score:2)
Depends what you mean by "speed". For example, compare how long it takes to fire up ANT, compared to Ruby's Rant. Both are build tools offering roughly equivalent functionality.
Results:
$ time ant
Buildfile: build.xml does not exist!
Build failed
real 0m1.233s
user 0m0.188s
sys 0m0.043s
$ time rant
rant: [ERROR] No Rantfile found, looking for:
Rantfile, rantfile, root.rant
rant aborted!
real 0
Re:Java startup annoys me greatly (Score:2)
java right now is fast where it's supposed to be, in large serverside applications running in multiple threads and having a stable platform all around it. if you've got 50 threads up and running , all doing various sort of fast i/o and depending heavily on automatic garbage collection, java sweeps the place clean. python is dead, perl doesn't even have proper threads (ithreads are not really that much of "thread"
a
Re:Java startup annoys me greatly (Score:2)
And I'm not just talking about 5 liner scripts. I mentioned Rails, which does database persistence, XML, and the other web application things a J2EE environment does--and starts up 10x faster than any J2EE setup I've seen.
Sure, Java threading is good. The point is
Re:Java startup annoys me greatly (Score:2)
The reason it takes so long to startup is because you have the overhead of:
All of that takes time, that's why it takes so long. Ruby on the other hand has the overhead of:
After that it simply follows the instructions in the script...slowly (by comparison, but not in the grand scheme of things).
I
Re:Java startup annoys me greatly (Score:2)
Guess what ant is doing all the tiem while it is using your CPU? It loads an XML parser, it loads an XML Schema (likely via the internet) and it laods some ant taks and finaly it wants to open a file that is not existing
Sure, for your little benchmark it would be much better to open the file first and abort early
Rule number one in meassuring and benchmarking: get a clue what you measure.
Re:Java startup annoys me greatly (Score:2)
Re:Java startup annoys me greatly (Score:2)
The Java startup time is, simply put, INCREDIBLY slow. When you start loading anything complicated, the massive number of classes that get loaded slows things down even further.
That was my point.
I assumed that ant starts with loading a massive amount of classes
angel'o'sphere
Re:If you're optimizing Java, you're sunk (Score:5, Informative)
Re:If you're optimizing Java, you're sunk (Score:2)
If your code is targetted to a specific platform then all that says is your C/C++ coders were idiots. The only case where a jitted language exceeds a natively compiled language is where the JIT compiler can apply optimizations the native code compiler cannot for compatibility reasons (eg avoiding SSE3 when you might run on an older CPU).
There is no excuse for heavy math code su
Re:If you're optimizing Java, you're sunk (Score:1)
Actually, the post to which you replied never said the Java solution was faster than a C++ implementation. He said it was "superior". True, it is a vague term, but for his organization, superior may mean "easier to maintain", "smaller codebase", "easier to use on other hardware platforms", or any other number of possibilities.
Re:If you're optimizing Java, you're sunk (Score:1)
Re:If you're optimizing Java, you're sunk (Score:2)
Re:If you're optimizing Java, you're sunk (Score:1)
Re:If you're optimizing Java, you're sunk (Score:2)
Re:If you're optimizing Java, you're sunk (Score:1, Informative)
Re:If you're optimizing Java, you're sunk (Score:2)
There is no excuse for heavy math code such as matrix processing to be faster in Java than C/C++. In the absolute worst case, you can simply take the machine code generated from the Java JIT and reproduce better code in C/C++.
Following your logic I rather would write: There is no excuse for heavy math code such as matrix processing to be faster in C/C++ than in Java. In the absolute worst case, you can simply take the machine code generated from the C/C++ compiler and reproduce better code with the Java JIT
Re:If you're optimizing Java, you're sunk (Score:2)
Sorry, but you are wrong. For some things Java can never be as fast as C/C++ due to the definition of the language itself - things like lack of value objects, specifics of method dispatching, late binding, etc.
I don't want to go into details here, but as a good example of Java's inefficiencies think about an array of complex numbers in Java and C/C++. Java is at least an order of magnitude slower in this particular example and no JIT can ever fix that unless the language itself is changed. If you don't be
Re:If you're optimizing Java, you're sunk (Score:2)
This does not make Java "an order of magnitude slower...", a real test of requires two seperate developers, with roughly equal skill in their respective languages, given a general problem and the task of implementing a solution, then comparing the resulting applications.
Given those results, the first thing you'll note is tha
Re:If you're optimizing Java, you're sunk (Score:3, Interesting)
I shouldn't really be replying, since you already said that all the specific instances which prove Java is slower don't matter - how could I argue with that ? However I would like to benefit from your obvious knowledge of the matter.
Also, please note that I didn't say "C/C++ is best", which you seem to be implying in your last paragraph - I was commenting in the context of the thread about Java vs C/C++ performance for matrix computations. I don't care about language wars, because obviously everyone who d
Please stop. You're wrong. Get over it. (Score:2)
Re:Please stop. You're wrong. Get over it. (Score:3, Interesting)
Very interesting read, thanks. It does show that in practice Java is fast enough, but it doesn't address my point. Too many things are omitted - restricted pointers, manual cache control, etc. I could delve into the specifics but I doubt anyone would read that om Slashdot.
For one the paper doesn't even mention the pointer chasing problem, which is inherent in the definition of the language. In Java almost everything is an object reachable through a pointer - accessing the object means stalling the CPU unt
Re:If you're optimizing Java, you're sunk (Score:2)
However I sincerely doubt that the current generation of JAVA JITs do complex optimizations like loop reshaping, cache blocking, prefetching, etc.
But you are wrong.
And your example about complext numbers
You won't need virtual methods in both cases, so you use standard methods (or non virtual operators).
Especially in vector math and matrix operatiosn Java is proofen to be
Re:If you're optimizing Java, you're sunk (Score:2)
Am I really wrong about complex optimizations like cache blocking and prefetching ? I might be - however unless you provide a verifiable reference I am disinclined to believe you. Many static compilers don't even do those.
To answer your question about why C++ would be faster. Examine the C++ declarations below and think about how fast a sum of the entire array would be in each case. If you like to look at the bigger picture, think about memory consumption too.
double arr1[10000];
double * arr2[10000];
Re:If you're optimizing Java, you're sunk (Score:2)
No, you can't. The language restrictions of Java are far more significant than the language restrictions in C. For example, you cannot perform unchecked array access in Java on arbitrary memory. In a very real sense, Java'
Re:If you're optimizing Java, you're sunk (Score:1)
You do realize that array bounds checking is eliminated by modern VM's? i.e. HotSpot. Suggest you read:
http://java.sun.com/products/hotspot/docs/whitepap er/Java_Hotspot_v1.4.1/Java_HSpot_WP_v1.4.1_1002_4
The Java version of Quake performs faster than the C version:
http://www.bytonic.de/html/benchmarks.html [bytonic.de]
Here are some other benchmarks:
http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html [idiom.com]
http://kano.net/javabench/ [kano.net]
Java VM's such as HotSpot have the
Re:If you're optimizing Java, you're sunk (Score:2)
Not guilty. However, you seem guilty of Java bigotry and failure to read and understand research papers.
You do realize that array bounds checking is eliminated by modern VM's?
Of course, and I've read the paper you linked. Thanks for telling me stuff I know and even recognized in my previous posts by saying that Java has an upper bound at C's optimized performance. *If* the runtime checks can be removed then Java array access is as fast as C. If they can't
Re:If you're optimizing Java, you're sunk (Score:2)
A human optimizing C code can optimize for all those situations and more.
C optimization is therefore a superset of Java optimization. Whine about it all you like, but that's the fundamental truth.
Thanks for playing, you lose.
Re:If you're optimizing Java, you're sunk (Score:3, Insightful)
The Java code will probably be more maintainable and less error-prone, but to suggest that it will outperform optimized C code is patently ridiculous.
Well, you are to narrow minded. Your example about arrays is strictly correct, but modern Java jits REMOVE the array bounds check if they can prove that the index will never be out of bounds. So this arguemnt does not hold
So I only picked the one above.
Please: why the heck do you think that a linke
Re:If you're optimizing Java, you're sunk (Score:2)
Re:If you're optimizing Java, you're sunk (Score:2)
you always speak about the upper bound is optimzed C. So you want to say: Java is most of the time slower than C, and in the cases where it is approaching C speed, it is at max on equal speed.
Sorry, I have to admit I missed that little word uper bound. In fact it is not nice of you to make a conversation over 3 posts and finally hit me with that into my face.
So let me give you a last small example:
Your argument is not taking into account modern C compiler tec
Re:If you're optimizing Java, you're sunk (Score:2)
It's not nice of me to make you miss a word I clearly posted and used? You need to wear more tinfoil on your head so my mind control rays affect you less.
A very simple situation where the C model fails is: compile a program to Pentium code and let it run on a Pentium 4.
Yes - and that is the case that most Java nuts use to "prove" Java is fa
Re:If you're optimizing Java, you're sunk (Score:2)
So, no. Unless you change the bounds of the argument, fully optimized C will always present the upper bound of performance for fully optimized Java when you know the target platform. To suggest anything else is simple ignorance of how computers work.
No you can't.
You accuse me to overlook a word you used only once
C compilers work on one compilation unit only, and optimize that oen only.
Jit compiler span multiple compilation units and optimize on that. So Jit compile
You're asking the wrong question (Score:2)
It is meaningless to ask, "Which is faster, Java or C++?" because how the compiler, not the language, has a very large effect on that. People who claim that Java is fast because their favourite JVM happens to have some particular optimization they like are barking even further up the wrong tree, because the only speed that matters is
Re:If you're optimizing Java, you're sunk (Score:2, Insightful)
Re:This annoys me greatly (Score:3, Insightful)
Re:This annoys me greatly (Score:2)
No, not all of it was rewritten in managed code, but there are performance level areas that were moved to managed code for stability and security.
Go check out channel9, and see the DirectX team talk about the decision to move parts to managed
Re:This annoys me greatly (Score:3, Insightful)
Yes. Batik [apache.org], for example, is written in Java. Admittedly, it is much slower than Inkview [inkscape.org] in starting up and opening a file, or opening another file once started, but on the other hand, it supports filters (which inkview doesn't) and clips properly at image edge (inkview doesn't), and supports scripts and other niceties.
Re:This annoys me greatly (Score:2)
You even know this is a bad excuse...
Optimization is always something EVERY developer should be doing. However, there is no way to 'override' some of the inherent performance issues present in JAVA currently.
And no it has nothing to do with s
A generalized profiler is just what I need now! (Score:1, Insightful)
Programming in C with a monkey chewing on your arm. I see students doing that all the time. They struggle for hours to write code that they could do in minutes with a higher level language. They look like they are having about as much fun as if they had a monkey chewing on their arm for sure. Usually, for what they are doing, speed of execution is irrelevant.
I often hea
Re:A generalized profiler is just what I need now! (Score:2)
This not something we disagree on, whatsoever... In fact my past post supporting higher level languages and help from IDEs have not been received so we
Re:Amen (Score:2)
A good environment was Kylix and Delpi (pascal) from Borland for Linux and Windows. Fast com
Re:This annoys me greatly (Score:2)
I will buy its viability after another 10 years of hype, and when they can show the industry companies like ATI or NVidia using JAVA for video driver library performance level coding.
They already use
I could be wrong, but I was an early JAVA lover, and even stuck with them when they cut of their nose to spite their face with the MS lawsuit, but to date Sun has not p
Re:This annoys me greatly (Score:2)
You are a beginner... Internet applications to Internet distributed platform independant applications, including business applications.
Go reseach where Corel tried to put a lot of work into pulling off some interesting JAVA based appli
Re:Oh, please, that's EASY (Score:3, Insightful)
Java is a language which benefits more than most from performance profiling, in that
it is very easy to write inefficient code, because the mapping from code to actual
execution is not always very clear.
This is a strength, and a weakness. The degree of abstraction from the underlying
machine is high. This results in quite intelligible code, and an ease of coding complex
and abstract tasks. It also results in it being quite possible to write apparently
simple looking code which ends up exe
Re:Oh, please, that's EASY (Score:2)
in a more direct language.."
Well, obviously, theoretically you're right. But in practice some Java applications that run under JIT can actually go faster as, e.g. C++ code. Especially if you take some common coding practices in C++ (heavy use of copying constructors etc).
Re:My Java Profiler Written in C (Score:1, Funny)
--shit, sorry, must have trashed a pointer somewhere. hang on, this'll just take a minute...
Re:My Java Profiler Written in C (Score:1)
Re:My Java Profiler Written in C (Score:1, Insightful)
Re:Quick! Name a successful Java program. (Score:4, Informative)
Gmail. It uses Java for almost all of its back end. In fact almost all of Google's large scale web applications use Java in some form. Python is also used extensively however, it's generally used for simple scripts and smaller applications. Tons of websites use Java extensively and people like you are just too dumb to realize it. If you do online banking it's almost guaranteed that the website is using server side Java.
In terms of client side applications there's; Azureus, LimeWire, Eclipse, Netbeans, Intellij IDEA, Yahoo Site Builder, ZipCreator, Summit Groupware, jEdit, SmartCVS, NeoOffice etc. etc. Just because you don't use them doesn't mean that they're not there. The truth is that most people only use a very select few programs and these programs are often using code bases that are over 10 years old (ie. Microsoft Office, Outlook, Internet Explorer etc.). Then there's all the enterprise applications that are written in Java.... In the enterprise world Java is dominant and the only real competitor is
Re:Why? (Score:5, Funny)
Re:Why? (Score:1)
visual [microsoft.com] code [amberpoint.com] profilers out there.
Re:java is crap (Score:1)
Class rewriting is cool, and can be done on a live JVM, even multiple times for the same class if desired. The result runs just like the original unmodified class. It's like *func = sub { print "new sub" } in Perl, but with much greater control and granularity.
Anyway, don't be such a tard in public.