Sorry, but no, at least not for most practical purposes - this is simply not possible with most conventional OS. For example, quite a few operating systems do not use the full context switch to handle the interrupt, so the time spent servicing the interrupt can and will often be displayed in time, regardless of what process was running when the interrupt occurred.
"Not for practical purposes" would mean the ability to run your program under the exact loop simulator. They are available, but mainly for processors, used mainly in real-time embedded systems, and not for something like a full-blown PC. Worse, they (usually) do not run anything like a full-blown OS, but for code that runs on bare metal.
In theory, you can do something with a virtual machine running on Windows or Linux, but I donβt know about any existing virtual machine that is trying, and that would be clearly non-trivial and probably have quite serious performance consequences (to put it mildly).
source share