Patent attributes
An embodiment of a method of virtualizing a counter in a computer system comprises a first step and iterative performance of second through fifth steps. In the first step, a virtual machine monitor programs a hardware event counter with an initial count for a profiling event for a virtual machine. In the second step, the virtual machine monitor saves a suspension count and disables the hardware event counter upon suspending operation of the virtual machine. In the third step, the virtual machine monitor programs the hardware event counter with the suspension count upon resuming the operation of the virtual machine. Upon receiving an interrupt from the hardware event counter that provides notification of reaching the initial count, the virtual machine monitor performs the fourth and fifth steps. In the fourth step, the virtual machine monitor saves a sample that comprises an event identifier and a code-in-execution indicator. In the fifth step, the virtual machine monitor reprograms the hardware event counter with the initial count.