Skip to main content
gamedev.net
🔒 Locked

cpu usage %

Started by caesar4 Aug 14, 2006 at 12:10 PM 10 replies 2.8k views
Original Post
caesar4
caesar4
how can i find what fraction of the processor goes idle, and what fraction is being used by my process, and what fraction is being used by a specific thread in that process? i know this is possible without a profiler, since procexp from sysinternals can do it for other processes
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
FlaiseSaffron
FlaiseSaffron
Theoretically you could write your own code with timers, and to get the percentage, you would just divide the time elapsed by the time your thread is active.

But why are you trying to do this?
caesar4
caesar4
Quote:
Original post by Lukewarm
Theoretically you could write your own code with timers, and to get the percentage, you would just divide the time elapsed by the time your thread is active.


thats not what i need to do nor will it give what i need

Quote:


But why are you trying to do this?


i have a low priority background task that i wonna run such that it doesnt hog the cpu from other procs
for that i need to be able to find global processor usage, processor idleness, and etc.
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
Omid Ghavami
Omid Ghavami
Quote:
Original post by caesar4
i have a low priority background task that i wonna run such that it doesnt hog the cpu from other procs
for that i need to be able to find global processor usage, processor idleness, and etc.


Can't you just set your thread to low priority and let the OS handle the rest? That's what priorities are their for.
Best regards, Omid
Evil Steve
Evil Steve
So long as you use blocking wait functions wherever possible, or make frequent calls to Sleep(), there shouldn't be any problems. I believe it's possible to find out the processor usage overall via some system performance information call, but I don't know what the call is offhand.
Agony
Agony
GetProcessTimes()
GetThreadTimes()
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
caesar4
caesar4
Quote:
Original post by Agony
GetProcessTimes()
GetThreadTimes()



thank you thank you thank you


now, how can use that to get the idle percent?
i know i need to use the kernel and user times deltas, but how do i find the kernel and user times for ALL processes combined?
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
Spoonbender
Spoonbender
If you have a low-priority process, it pretty much by definition won't hog the CPU.
Windows always runs the available process with the highest priority. Your app will *only* run if everything else keeps yielding the cpu.
Michalson
Michalson
I would go with the low priority+frequent sleep approach.

Attempting to manually throttle your program to some desired CPU usage will always be a hack at best (and hacks are bad). As soon as you run it on a dual core processor, or down the road when some setup like dual cores acting as one CPU comes out, it will break and likely do the exact opposite of what you intended.
caesar4
caesar4
Quote:
Original post by Spoonbender
If you have a low-priority process, it pretty much by definition won't hog the CPU.
Windows always runs the available process with the highest priority. Your app will *only* run if everything else keeps yielding the cpu.


the thread sometimes needs to be background, sometimes, it needs to hog ondemmand


a low priority thread is out of the question, since this is regarding a memory manager that can and does move objects around, so a low priority will slow down other parts of code that need the manager to quickly finish its current operation

already implementing the sleep approach, but i need variable sleep, depending on cpu usage

no more anything about setting the thread to low priority please
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.