This is a basic MFC program that demonstrates how to retrieve the current CPU load percentage and set it using a high priority thread control loop. I created this project simply because I needed to test another fairly time/buffer critical application and wanted to simulate heavy amounts of CPU load and/or a slower computer. By using this app, you can successfully "steal" away certain amounts of processor instructions to emulate slower or more heavily loaded machines.
It only fully works on single core systems. I personally have a dual core machine, and therefore the one thread that runs in this program can never utilize more than 50% of the "Total Processor Load." I tried launching multiple threads that would hopefully use both cores, but it didn't work - I'm guessing you would have to somehow instruct a 2nd thread to use your second core. Anyway, it wasn't worth it for me to implement, so if anyone wants to add full support for multi-core machines, please post how it's done to others.
Included is a project built using VS 2005. The code is very simple and could be easily added to another project. To retrieve the CPU load percentage, you must include the dependency pdh.lib in your Project->Linker settings.
- 22nd February, 2007: Initial post