Click here to Skip to main content
11,412,578 members (72,932 online)
Click here to Skip to main content

CPU Load Control

, 22 Feb 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Demonstration to control the amount of CPU load used by your computer
Screenshot - img.png

Introduction

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.

History

  • 22nd February, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jkhax0r

United States United States
No Biography provided

Comments and Discussions

 
Questiongood Pin
bleachli at 9-Nov-11 6:13
memberbleachli9-Nov-11 6:13 
GeneralXP is showing two processors Pin
Lokanatha Reddy at 16-May-07 0:38
memberLokanatha Reddy16-May-07 0:38 
GeneralCPU Load Ported on Visual C++ 6.0 Pin
cristitomi at 16-Mar-07 0:54
membercristitomi16-Mar-07 0:54 
GeneralNot work in one core PC with Windows2000 Professional Pin
AleksMain at 27-Feb-07 3:24
memberAleksMain27-Feb-07 3:24 
GeneralRe: Not work in one core PC with Windows2000 Professional Pin
jkhax0r at 2-Apr-07 7:38
memberjkhax0r2-Apr-07 7:38 
GeneralMulticore Pin
Joergen Sigvardsson at 22-Feb-07 12:00
memberJoergen Sigvardsson22-Feb-07 12:00 
GeneralRe: Multicore Pin
Vasudevan Deepak Kumar at 22-Feb-07 19:08
memberVasudevan Deepak Kumar22-Feb-07 19:08 
QuestionRe: Multicore Pin
jkhax0r at 26-Feb-07 6:16
memberjkhax0r26-Feb-07 6:16 
AnswerRe: Multicore Pin
Joergen Sigvardsson at 26-Feb-07 8:29
memberJoergen Sigvardsson26-Feb-07 8:29 
Do the new duo-chips have hyperthreading enabled? Windows reports each "hyper unit" as a processor of its own (at least XP does). Maybe you have to adjust for that.

Also, what does SetThreadAffinityMask() return? Anything of significance?

--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören

GeneralRe: Multicore Pin
Great-er at 27-Feb-07 0:54
memberGreat-er27-Feb-07 0:54 
GeneralRe: Multicore Pin
Joergen Sigvardsson at 27-Feb-07 3:36
memberJoergen Sigvardsson27-Feb-07 3:36 
GeneralRe: Multicore [modified] Pin
Great-er at 27-Feb-07 9:56
memberGreat-er27-Feb-07 9:56 
GeneralRe: Multicore Pin
jkhax0r at 28-Feb-07 17:46
memberjkhax0r28-Feb-07 17:46 
QuestionMaybe this would work? Pin
Ivo Beltchev at 22-Feb-07 11:59
memberIvo Beltchev22-Feb-07 11:59 
AnswerRe: Maybe this would work? Pin
Vasudevan Deepak Kumar at 22-Feb-07 19:09
memberVasudevan Deepak Kumar22-Feb-07 19:09 
GeneralRe: Maybe this would work? Pin
dongbaek at 19-Jul-09 23:21
memberdongbaek19-Jul-09 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150427.1 | Last Updated 22 Feb 2007
Article Copyright 2007 by jkhax0r
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid