The Lazy Man’s Profiler


News: The Lazy Man’s Profiler

  1. The Lazy Man’s Profiler (3 messages)

    At Windward Wrocks David Thielen talks about an alternative to profilers that can be used in many situations.

    The way we're all taught to profile is you install a profiler like YourKit and then run your code under it. It shows you the hotspots and you dive in to that code to figure out how to optimize it. This is a great approach for many cases. I've used it myself a lot, especially back when I did game programming.

    However, there are a lot of times where a much easier approach is equally effective. And for some cases, much more effective. It's fast, it's simple, and it gets the job done. What is it?

    1. Start your program under the debugger.
    2. Every 10 seconds hit pause in the debugger. Record where you are in the program.
    3. After doing this 5 – 10 times, stop.

    For a great many situations you will find that of the 10 times you broke into the program, it is in the same code each time. You now know where the code is spending its time. And you did this without installing a profiler, without running it, without having to dive into its results.

    Continued at Windward Wrocks

    Threaded Messages (3)

  2. The Lazy Man’s Profiler[ Go to top ]

    Or you could use a light-weight sampling profiler like the one I built for MessAdmin, my open-source monitoring tool.

    In addition to CPU profiling, you will also get tons of information on your application, including when you leave your dev box and go in production.

    (Disclaimer: the CPU profiler is unreleased yet as of this writing. Send me an email should you want to have a copy before I release it to the world.)

  3. The Lazy Man’s Profiler[ Go to top ]

    Antoher option is to use jstack utility to generate thread dumps each few seconds and then see what your code was doing.

  4. The Lazy Man’s Profiler[ Go to top ]

    Or just use the VisualVM sampler, conveniently included with every JDK.

    The sampler samples call stacks every 100 ms by default when turned on and gives you a rough idea where time is spent