Build Your Own Java Performance Profiling Tool
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.'"
Byte-code hacking!?
Why not simply use AspectJ?
I use the JVMPI by sun which IMHO does a pretty good job and is extremely easy to use. However the custom profiler looks easy enough and will probably be much more accurate. Worth a try for sure.
The only popular languages faster than Java are Assembly, C, C++, and Fortra. All of which take are enormously difficult to use for large scale projects.
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?
If you're to the level where you're profiling code, you shouldn't be using Java, period. If you're at the point where you're trying to optimize Java code, you should be using native code.
But, if you want to know better alternatives to Java, there's always Python, Ruby, C#, or a host of other languages that don't have the massive memory problems or library bloat that Java has.
And girl, you know that you're the only girl for me, girl
Girl, you're the girl of my fantasies, you're my girl
You're my girl, my girl.
Coming up later: high performance tuning tips for Citroen 2CV owners.
Only three things are certain; death, taxes, and apocryphal quotations - Ben Franklin.
That is pure Flamebait.
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 executing in a very complex way.
Profiling will expose the gross inefficiencies, and allow them to be corrected.
It will never be possible to write as efficiently (execution time), as
in a more direct language, but the coding efficiency (programming time) is quite good,
and for a lot of applications that matters a lot more. It also has a lot of
cross platform capabilities (not perfect I concede).
I prefer writing code where I can see the bits and bytes (i.e. not Java), but
to put down Java in such an off hand way is unjustified.
If it died a long time ago, why am I still getting paid well to code in it?
--shit, sorry, must have trashed a pointer somewhere. hang on, this'll just take a minute...
Download jrat here
I've used it many times, and it's helped me find horrible Hibernate queries, Lucene bottlenecks, Batik rendering pipeline issues. It is fantastic.
[% slash_sig_val.text %]
Maybe because there is no other cross-platform language with decent graphics support and comprehensive libraries?
I've worked on quite a few contracts where I was part of a massive 3 ring circus to collect Java metrics, so we could make pie charts for PHBs to show their PHBs. Of course the coders with half a brain already knew where their bottlenecks were. Glad to see all my efforts are being taken so seriously.
Give a man a fish and you have fed him for today. Teach a man to fish, and he'll say "WHERE'S MY FISH, YOU IDIOT?"
Sure, JRat is interesting, but I like the DeveloperWorks article's idea of taking the *exact* bytecode you'll be running and instrumenting it. Now if I can just figure out how to shoehorn it into Tomcat ...
Here you go, be sure to thank HP for them.
d ex.htmln e/index.html
http://www.hp.com/products1/unix/java/hpjmeter/in
http://www.hp.com/products1/unix/java/java2/hpjtu
silent memory corruption or npe w/stack trace, take your pick.
Seriously. Modifying a program to profile it?
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.
"Time flies like an arrow; fruit flies like a banana." --Groucho Marx
O R L Y?
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.
I agree totally. Java is dead. We just have to get the message through to the huge numbers of organizations and developers who depend on the technology to get their jobs done. Oh, and then we have to come up with something better to replace it. Give me a little while... ;)
The idea of being easily able to measure where a program is using resources appeals to me. It might settle a few arguments around here.
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 hear C programmers insist that they can be as productive as someone writing in a higher level language. They say it's just that the people writing in the higher level language never learned to program properly. Actually they're right about that one. Many people who get paid to write in higher level languages aren't really good programmers but that doesn't prove anything about the innate goodness of the languages in question.
We have gotten to the point where being able to write at a low level isn't as advantageous as it used to be. For instance, it used to be possible to write key elements of code (for DSPs in my case) in assembler. With modern tools, that advantage has evaporated. Trying to code by hand often creates much slower code. (Actually in this case, C is the higher level language.)
My own preference for a higher level language is Python. The large majority of the time, there is absolutely no useful benefit that I could get by writing in C.
Anyway, your comment about programming in C with a monkey chewing on your arm, reminded me a lot of an ongoing argument with the people who teach programming around here. The students do need C because they do a lot of embedded stuff, but the rabidity of some of the C folks does seem a bit overboard. Sorry if you got caught in the crossfire.;-)
Nope. I can't think of one either.
"java to native binary" and "portable"
what are you smoking?
Other than Mono, none of those even remotely compares to Java and there's numerous reasons why to use Java over Mono. I love it when the topic is performance and people suggest Python/Ruby/Perl etc., it just shows that they're completely clueless. For most real world *paid* developers the choice is between .NET and Java, each having their respective strong points.
I'm looking for an application that will monitor a specified application and log how long the application is "not responding".
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 metric that I could use for justification.
Anyone know about anything like this?
Steve
A work that expires before its copyright never enters the public domain and thus enjoys eternal copyright protection.
How about walmart.com?
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 antBuildfile: 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 0m1.071s
user 0m0.089s
sys 0m0.015s
Ruby's an interpreted language, and it's one of the slowest in its class. (Slower than Python or Perl). It's loading in all the libraries as source code and interpreting them. Yet it still wipes the floor with Java at speed of startup. And that's before you actually start building anything--the first time I used Rant, it was so much faster than ANT that I thought I must have done something wrong.
Try launching a major Java GUI application, and you can profile the application startup speed with a manual stopwatch. Try launching a J2EE setup, and compare it with starting up Ruby on Rails.
Java isn't going to lose its well-deserved reputation for slowness until some major work is done on startup speeds.
(And yes, I'm using Java 1.5.0.)
GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
./configure
make
make install
Just raise the taxes on crack.
"Quick! Name a successful Java program. Nope. I can't think of one either."
.NET.
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
I said language.
perl - illegitimate offspring of bash and grep.
python - perl for people who hold their little fingers up when they drink tea.
mono - I had that as a teenager
tcl - heh heh
You need a real unix like solaris for this feature and not linux.
Although I heard linux has limited support for profiling these days I dont know how good it is for monitoring regular applications in userspace.
http://saveie6.com/
Never use the word "best-of-breed" again. Or else.
Oh wait, do you mean .NET? :-) And while you are downloading the "free" IDE, you can also pick up one of several
visual code profilers out there.
Sorry, we are on Windows. They don't even write a *nix version of this software. Anyone know of a not-responding process monitoring app for Windows? Steve
A work that expires before its copyright never enters the public domain and thus enjoys eternal copyright protection.
This perl script. (Or google for "wherehot.pl")
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 script, copy and paste it into eclipse's Java Stack Trace console, and be able to click on the lines identified as being slow.
We've found it to be a nice complement to graphical tools that let you visualize what bits are slow, like HPJmeter.
I love when people try and use server applications to prove that Java is useful. Yeah, when you can throw as much server hardware as you need at a problem, you can get Java to work. But just because Java works when you shove enough server power under it doesn't quite make it a lean, agile platform. There are successful web applications written in Visual Basic, after all.
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.
Let's see, Azureus, which is well known for massive CPU and RAM usage, LimeWire, which as I recall is slow and buggy, Eclispe, which is slow and flakey, Netbeans, which flat-out sucks...
It's interesting you should mention jEdit. You might want to read the developer's blog where he explains why Java sucks ass, and why he'll never touch Java ever again.
The simple reality is that Java isn't used for anything useful, or any place where a simpler language couldn't have been used to create a faster, more scalable, dynamic solution. The people claiming otherwise are deluding themselves.
if this profiler is written in java (likely) it is as slow as the crap it's supposed to analyze...
The MAFIAA is a bunch of mindless jerks who will be the first up against the wall when the revolution comes
No, it is CoCreate OneSpace Designer.
>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
A work that expires before its copyright never enters the public domain and thus enjoys eternal copyright protection.
Actually, I have avoided Java like the plague. When I decided to dump Windows and run Linux I had zero Linux or Mac experience. I was looking for a language that would be cross-platform. I was considering Java but then there was a story on Slashdot. The story said that developers at Sun didn't think Java was very good in their programming environment. They recommended a couple of languages and Python was one of them.
p ?memo_id=1321
Here's a link:
http://www.internalmemos.com/memos/memodetails.ph
We have a product that requires that profiling be done on a per-object basis. I'm not using the Java class transformer interface, but I am rewriting classfiles in a manner similar to hprof's bytecode instrumentation option (as opposed to the stack sampling option), using JVMTI.
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.
I prefer Mercury's profiler. Its for J2EE or .NET applications but it integrates with Load Runner and Business Availabillity Center. There is a free trail here.
~~ What's stopping you?
Look, nobody is using notepad/vi and javac these days to develop anything. And most of the Java software we develop these days doesn't simply run from the command line. Be it a J2EE application or an Eclipse RCP application, most *free* (as in speech or beer) tools don't do the greatest job when dealing with a predefined configuration, such as the aforementioned.
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 simply launch them in a JVM and have your way with them.
I have used some plugins for Eclipse that almost do an OK job of this, but even they are limited. The best I've found to-date is:
http://sourceforge.net/projects/eclipsecolorer
Even this one has major warts, though. Such as it only runs reasonably on Windows, while I do most of my Java development on a Mac these days.
I'm sure someone will come along and suggest JProbe, or another commercial product. If the price were right, I'd by any of these as well. Unfortunately, for the moment, it is more cost effective to pepper my code with Log4J statements providing profiling information in the form of a log file and to parse the results myself.
Again, if anyone can prove that I'm incredibly wrong, I'll buy you all the beer you can drink the next time I'm "in your neck of the woods."
http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html
- I don't need to go outside, my CRT tan'll do me just fine.
I can't see why you would do this, except as an exercise. I've used JProfiler on clients' apps for a long time now, and I couldn't imagine that I could write something better and more comprehensive myself.
--It allows me to filter on only the classes I want.
--It provides good reports. Not only are these nice for the Brass, but nice for including in reports to other developers.
--It's stupidly easy to set up and use. That stuff from the Eclipse plugin looks a lot more time consuming and tiring to view than the visual representions of my objects JProfiler gives.
--True it does not run on ALL platforms. I guess that could be considered a downfall. But still, with Java, I have many times profiled an app on my dev machine, when that is a different platorm than the prod machine. Not ideal, but it sure gets you miles further down the field than not profiling at all.
True, it's not open source, but honestly what tool this good is? *ducks* That was a joke, but I don't agree with the article that OS should necessarily be a feature of the "ideal" profiler.
True it does cost money to license. But hey, it's my business. I don't mind investing a little money for something as critical to my business as a Java profiler.
That's simply not true. I work on a large Java project that deals with a lot of matrix intensive work. Our Java code has been rigorously architected, engineered, and optimized.
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 the speed that users actually get, rather than the speed that users would get if they were running a JVM other than the one they were actually running.
It is more meaningful to ask: How easy is it to do things really badly in Java vs C++? The answer to that is: it is very easy to write extremely slow Java code, and very easy to write extremely fragile (and leaky) C++ code. I've managed large Java projects and seen how fast good programmers can make Java go, but I've also seen how slow merely average programmers can make Java go. And how much of a resource hog Java can be in the hands of average programmers (and on average VMs). Likewise, my own C++ code is clean and robust, but I've worked with developers who just aren't safe to let near a C++ compiler. Invalid iterators aren't the half of it.
The fact that extremely good programmers can make Java apps fast does not make Java a "fast language" any more than the fact that extremely good C++ programmers can make C++ apps safe makes C++ a safe language. It will always be really easy to write Java apps that move at the speed grass grows and use up all the memory in the machine, and it will always be really easy to blow you whole leg off with C++. Both languages require really good developers to use them well.
Blasphemy is a human right. Blasphemophobia kills.
Most of your comment is idiotic and I'm not going to reply to most of it. As for your accusation about Slava, I know him personally and he's an extremely intelligent programmer. Of course what you fail to mention is that he thinks that practically every language available today sucks and has poor design and implementation. To some degree he's probably correct. The only language he really likes is Lisp and that's why he's gone on to create Factor. Of course when you're bashing Java it's nice to bring up that he doesn't like Java, however people that do this always fail to mention that he hates almost every other language equally or more so.
The points you've made against Java are also pathetically weak and unjustified. They're also nowhere near the same issues that he has with the language. Come to Freenode if you would like him to tell you himself.
At $JOB-1 I trialled and bought Yourkit's YJP, which is truly excellent, very easy to use and a very effective tool. Moreover, it's not expensive, and the support is pretty good too. I'm just a happy customer, not affiliated in any other way.
I've written my own java profiler/coverage tool using JVMTI, JNI which publishes results on a dynamic webpage (see Patty @ SourceForge ). One of the problems when maintaining statistics on execution and line number coverage if you keep it in the same JVM is that it has a large performance impact to continuously look up the buckets (like many profilers do), the buckets where the statistics are kept. So one of the things is to bring down this impact by only profiling certain classes, plus sending all the profiling data to a separate computer, which has CPU available to put the data into the stat buckets to be extracted later. (this is the process that is costly to do inside the same process, putting stats into the correct buckets, due to `lookup` code ). I'm using a Tomcat process to gather data for example on a simple text-based protocol. With ByteCode Engineering (called bytecode instrumentation in this case) rather than AOP, the advantage is that you can reload the class later without the instrumentation. AOP is not that flexible. So the advantage is that without any instrumented classes, if your environment is set up correctly, you can even start profiling in production if you wanted to (I would highly recommend not to though). The other benefit of native profilers is that you can put this profiler under every JVM, even code that you don't know anything about, and it allows you to profile anything at will without writing specific AOP junctions or other stuff. (let's not assume you only want to profile your own 'known' code?) JVMTI also allows you to analyze the objects on the heap. If you look into the Sun API, you can see there are various functions to tag objects, which cna be used to filter on specific objects only. I'm using this to make an estimate how many instances of certain objects there are and how much memory they are using. Sun comes out with their own implementations (JFluid for NetBeans) and jconsole. So the benefit of future projects is that it must be aimed at a specific problem not yet solved. My project on SourceForge has full source code available if you wanted to have a look how it works (C and Java). (GPL / Mozilla, you choose)
"It will never be possible to write as efficiently (execution time), as
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).
Also a very cool company, as I have had personal replies to my enquiries regarding certain aspects and suggested enhancements...
>I must be missing something. Is "to A from B" somehow different than "from B to A" ???
/said/ "windows to unix" - I think he meant "unix to windows" since I was saying our software was only available on Windows).
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
A work that expires before its copyright never enters the public domain and thus enjoys eternal copyright protection.
Would the Apple store and the iTunes Music store be considered successful?
Yup, bothering to run a profiler on your Java code is like ricers fixing up econo boxes. If performance is important, try starting with something fast.
It's been 11 minutes since you last successfully posted a comment
(It was in a goddamn journal, for chrissakes. That was my first post to Slashdot all day, and this is my second. It's not like I'm fucking flooding the system.)
In fact there are two articles on DeveloperWorks that I wrote last fall that describe how to use AspectJ to do more advanced performance monitoring (that are cited in the original article). See http://www-128.ibm.com/developerworks/java/library /j-aopwork10/ and http://www-128.ibm.com/developerworks/java/library /j-aopwork12/
The big benefits of using AspectJ are the ability to build more interesting coherent logic with a higher level language rather than (virtual) assembly language, and to have a well-document, accessible extension language for custom monitors.
Ron Bodkin