A method and system for tracing profiling information using per thread
metric variables with reused kernel threads is disclosed. In one
embodiment kernel thread level metrics are stored by the operating system
kernel. A profiler request metric information for the operating system
kernel in response to an event. After the kernel thread level metrics are
read by the operating system for a profiler, their values are reset to
zero by the operating system kernel. The profiler then applies the metric
values to base metric values to appropriate Java threads that are stored
in nodes in a tree structure base on the type of event and whether or not
the kernel thread has been reused. In another embodiment non-zero values
of thread level metrics are entered on a liked list. In response to a
request from a profiler, the operating system kernel reads each kernel
thread's entry in the linked list and zeros each entry. The profiler can
then update the intermediate full tree snapshots of profiling information
with the collection of non-zero metric variables.