Programmed Profiling

2. Your Code
When you are optimizing a code, it may be difficult to correlate the data in a trace with the code that was executing. One way to deal with that issue is to monitor only the sections of the code that particularly interest you. In this section I will describe a library I wrote that makes it possible to do that. Because the hardware counters are read only once/second, the section you are monitoring must run for at least that long. Because many counter objects are updated once per second, you must read them each second if you are to get a complete picture of what is happening. Since most codes do not reach any specific point once each second, the counter-reading operation will be carried out in a separate thread that wakes up once/second to take the readings.