Identifying resource-intensive methods
A method may be a candidate for optimization if it is:
- Called more frequently than required. Performance can be enhanced
by finding ways to either make fewer calls or to make small improvements to a
method that is frequently used.
- Has a long execution time. Alternately, performance can be enhanced by identifying the
classes that take up the most execution time and then optimizing those methods
that spend a long time on the stack. Such methods may not necessarily be executing but may
instead be
calling other methods for tasks such as sorting or delegating.
To locate frequently-called methods, do the following:
- Ensure that the collection of execution flow information has been
enabled, which you do when launching or attaching to the application to be
profiled. Select the profiling option, My
application is too slow then, from the Details options, select
Show Execution flow graphical details.
- In the Profiling Monitor view select either a monitor or an agent.
- Right click, then select Open With > Execution Flow. The Execution Flow view opens.
- Click the Zoom In button
to enlarge
a sequence of method calls.
- Right-click, then select
Detect All Repetitions. You see Xs appear where there are
repeated patterns.
- Zoom in on those areas to see the repeated patterns and
the number of repetitions of the method.
To locate methods with long execution time, do the following:
- Launch or attach a process for a particular resource, then open the
Execution Flow view.
Note: You can open the view from the agent, the process,
the host, or the monitor. Realize, however, that the information
from these resources is quite different. For example, the Execution Flow view from the agent
shows the execution of
the specific JVM (Java virtual machine) to which the agent is attached.
In contrast, selecting the view from the monitor shows the execution of all of JVMs that have
profiling agents under the selected monitor.
- Notice the length of each method's stripe. The longer the stripe, the
longer the execution time.
- To see a method in greater detail, open the Method Statistics view, select the
method, right click, and then select Show Method Invocation.
- To see the execution time of the method's caller, right click then select Show Method Invocation.
This view shows a representation of the same method as a labeled line.
- From
the local toolbar, click Show Caller
to see the callers of
the selected method in the view. Each time you click this button, one method
higher up in the calling sequence is displayed.
- Select a method. The vertical length of the selected area indicates the
base time for the method. You can determine the execution time for this
method by checking the vertical time scale on the right side of the view. The
status line gives you the cumulative time for the method.
To get a wide view of execution time, do the following:
- Open the Execution Flow view: From the pop-up menu of the monitor in the
Profiling Monitor view, select Open With > Execution Flow.
- This view, like the Method Invocation view, this view has a vertical time
scale along its right side.
- Use the Zoom In
button to enlarge a particular
section of the view to highlight the method that you want to examine.
- Click the method name (or on white space below it) to select it. The
vertical length of the highlighted area is an indication of the base time for
the method. The exact value for the base time is displayed in the status
line.
- Use the Zoom Out button
to view a larger
portion of the entire program while still being able to see the highlighted
area of the method (that is, you can still see the yellow rectangular area).
Even if the entire execution representation is not seen, you can still
determine how much time this method consumes in relation to the entire
program.
Related concepts
Overview of the Profiling Tool
Execution flow view and table
Statistical views
Related tasks
Profiling an application
Launching or attaching a Java process
Studying garbage collection
Analyzing performance and memory usage - overview
(C) Copyright IBM Corporation 2000, 2003. All Rights Reserved.