To enable the Performance Monitor to monitor a section of your Java code:

For details about the Performance Monitor’s startOperation, endOperation, and cancelOperation methods, see Methods for Storing Performance Data.

For example:

String opName = "render jhtml";
String parameter = "foo.jhtml";
boolean exception = false;
PerformanceMonitor.startOperation(opName, parameter);
try {
  ... code to actually render foo.jhtml
} catch (Exception e) {
  PerformanceMonitor.cancelOperation(opName, parameter);
  exception = true;
} finally {
  if (! exception)
    PerformanceMonitor.endOperation(opName, parameter);

These methods can be nested with different or the same opNames. For example:

private final String RENDER_JHTML = "Render JHTML page";
private final String EXECUTE_SQL = "Execute SQL Query";
private String mPageName = "page.jhtml";
private String mSQLQuery = "select * from table";

PerformanceMonitor.startOperation(RENDER_JHTML, mPageName);
... source code to start render
  PerformanceMonitor.startOperation(EXECUTE_SQL, mSQLQuery);
  ... source code to read from table 1 in database
    ... source code to read from database
  ... more source code to read from table 1 in database
  PerformanceMonitor.endOperation(EXECUTE_SQL, mSQLQuery);
... more source code to finish render
PerformanceMonitor.endOperation(RENDER_JHTML, mPageName);

Note that the calls to startOperation are nested within other calls to startOperation. You must place the endOperation and cancelOperation calls in the code in opposite order that the startOperation calls were placed. If this requirement is not followed, then the endOperation or cancelOperation call throws a PerfStackMismatchException. This exception tells you that the calls to endOperation are not being matched up. Either they were not called in the correct order or the arguments were not exactly the same as those that were passed into the methods.

To ensure that endOperation is always called, wrap the Performance Monitor methods in a try ... finally block, as in this example:

boolean exception = false;
try {
  performOperation (pParameter);
} catch (Exception e) {
  exception = true;
} finally {
  try {
    if (!exception)
  } catch (PerfStackMismatchException e) {
loading table of contents...