1. A method in a data processing system for collecting a plurality of metrics, the method comprising: initializing a plurality of counters to count events associated with metrics of interest; counting occurrences of events associated with metrics of interest during a single execution of a computer program; and responsive to a determination that a branch has been taken, generating a trace record for the branch taken, wherein the trace record contains a count of events associated with the metrics of interest.