Patent ID: 8855970

Claim:
A method for performing precise microprocessor performance counter readings, the method comprising: detecting a swap of a monitored process being executed by the microprocessor; reading, if the swap of the monitored process is detected, a value of a performance counter, wherein the value of the performance counter is output to a counter output register; storing the value of the performance counter in a first memory location; determining whether the value of the performance counter exceeds a defined overflow threshold; and detecting a swap back to the monitored process and in response to the detected swap back to the monitored process: if the value read from the performance counter does not exceed the defined overflow threshold, the value of the performance counter stored in the first memory location is restored to the performance counter, if the value read from the performance counter exceeds the defined overflow threshold, the performance counter is set to zero and the value of the performance counter stored in the first memory location is used to increment a second memory location storing an accumulated overflowed value of the performance counter for the monitored process, and if the value read from the performance counter exceeds the defined overflow threshold, detecting at least one performance counter reading instruction executed by the monitored process and in response to the detected at least one performance counter reading instruction, setting the counter output register to zero.