Sun's OS, Solaris has some nice features built-in. One of my favourites is the ability to get CPU performance counter iinformation with built-in commands and libraries, which are also available to normal users.
Java doesn't have a built-in way to access these, so I wrote a little C program which does, and a little Java class to access them via JNI.
Here's some background references:
Performance Analysis and Monitoring Using Hardware Counters:http://developers.sun.com/solaris/articles/hardware_counters.html
Optimizing Applications with Large Working Sets:http://developers.sun.com/solaris/articles/optimizing_apps.html
One thing I like about using these counters is that the values are very precise and very stable. I'm only using the number of CPU cycles and instructions executed, but there's many more counters available (for analysing floating-point or cache/memory usage), depending on what the CPU provides.
Here's the output from analysing a simple program (adding two integer arrays), where samples were taken every iteration of a higher-level loop. The lower level loop does 2,000 iterations each time. These results are with Java 1.4.1 server on a 500MHz UltraSPARC IIe on Solaris 8. Support for a good variety of x86 CPU counters isn't available until Solaris 10 though.Loop Cycles Instrs wall-clock (ns)
0 708823 491297 1344732
1 656932 476504 1204708
2 646695 476503 1185966
3 698243 513165 1286524
4 686206 500540 2025927
5 693815 500516 1272467
6 665485 500529 1220026
7 479821 222572 27391653
8 58270 48423 120922
9 32648 48419 69021
10 32360 48419 68480
11 32268 48419 68119
12 32270 48419 68300
13 32438 48419 68660
14 32272 48419 68119
You can see here that when the compiler kicks in at loop #7 it doesn't affect the cycles and instructions counts that much - this is because the compiler is on a seperate thread, and the counting is only being done for the user thread.
Anyway, this is in very early stages, but it works. First time I've done something with JNI or the CPU performance counter C-library.
If anyone is particularly interested I can post the code, but you'd need Solaris to run it. Last I heard, Linux doesn't have an equivalent built-in, and I'm pretty sure Windows doesn't. MacOS X comes with a program called "monster", but it's not installed as standard.
I'm doing this as part of an article analysing run-time optimisation aspects of JVMs (particularly Sun's JVM).