Runtime performance monitoring made easy

Known proprietary solutions

Here are two proprietary solutions as seen in code (more or less copied from existing projects).

Example 1: System.out and System.currentTimeMillis().
long time = System.currentTimeMillis();

//
// some business code
//

System.out.println("Elapsed time" + (System.currentTimeMillis() - time));
Example 2: Logging Framework extension.
private static Log tlog = LogFactory.getLog(Constants.TIME_LOG_CATEGORY);

public void someMethod() {
  long tStart = 0;
  long tEnd = 0;

  if (tlog.isDebugEnabled()) {
    tStart = System.currentTimeMillis();
  }

  //
  // some business code
  //

  if (tlog.isDebugEnabled()) {
    tEnd = System.currentTimeMillis();
    tlog.debug("Executed someMethod() in " + (tEnd - tStart));
  }
}

What are the issues with the examples above?

The code fragments do measure execution performance. But do they help to locating and understanding application performance problems? Probably not, because:

1. Gained statistics are hard to analyse
Would you consider a log entry a good basis to judge over current application performance? Especially under high load, with hundreds or even thousand measurements per second?

2. Collected data don't offer basis of comparison
What does it mean to be fast? Is 2 ms too much for a simple execution? Or is it ok? And does it even matter?
To answer these questions more than plain execution time is needed. You need to know how often a method was called, what the min/max and average execution times were and how those numbers relate the to rest of the application.

3. Collected data don't offer interval based analysis
Knowing exactly how long the execution of a code fragment took might be important in certain cases. However this doesn't help to understand the load signature of your application. Therefore you need to know how your application performed within the last minute, hour or day. And you need to be able to start and stop measurements on demand, with direct access to a aggregated statistics afterwards. Do you think log file parsing in the best way to achieve this?

Summary:
Applications performance analysis can only be successful and correct, if - and only if - the collected data can be easily aggregated and visualized based on a chosen measurement interval.