1. A computer implemented method for collecting information about threads, the computer implemented method comprising: detecting a thread entering a wait state; selectively obtaining information about a set of threads in the wait state using a policy in response to the thread entering the wait state, wherein the policy comprises a set of one or more rules that identify when information about the thread is to be collected; counting a number of times that the thread has gone into an idle state, wherein a count is formed, and wherein the count is stored in a node of a tree data structure; placing a unique identifier in the node; generating a trace record, wherein the trace record contains the unique identifier and the count; generating a report based on a combination of the trace record and the tree data structure; and analyzing the report to determine why a processor became idle during execution of code that included the thread.