A method and system for profiling a program using periodic trace sampling
is provided. During the execution of the program, sample-based profiling
of the executing program is performed--for a predetermined period, a
profiler performs trace processing for the program, after which the
profiler pauses and does not perform trace processing for a predetermined
period or only performs lightweight processing for a predetermined period.
The periods controlling the profiler may be selected by a user, and the
periods may be measured by temporal or non-temporal metrics. The user may
also specify parameters that are used to filter events so that profiling
is performed only for specified threads or methods. The profiler cycles
through these periods, during which selected events are processed to
generate a profile of the execution flows within the program. For each
sample period, a tree data structure is generated in which nodes of the
tree data structure represent the routines of the program that execute
during the sample period, as may be indicated by entry and exit events
caused by the execution of the routines. At the start of each sample
period, execution flow information may be used to create an initial tree
data structure. When the execution of the program is complete, the tree
data structures from each sample period are merged into a resulting tree
data structure.