 |
|
 |
I've been trying to figure out the implementation of your example here by throwing away the things included but not really used to produce the expected result.
In the end i ended up with about 10% from the original code that actually does the job, and the one i needed to calculate the CPU usage. The implementation is so convoluted with things that just got nothing to do with the subject - it is a mess, really.
An article is supposed to be concise, showing exactly what you are talking about, and this is by far not the case at all.
|
|
|
|
 |
|
 |
This article got me started to implement CPU usage the right way.
I'm running it on Vista, and seeing always 0 for the Process, but correct values for the CPU usage.
Did you do any further research in this direction after the article?
This is still a problem even today how to get CPU usage properly.
Just studying your code, and the first thing i noticed: you call LoadLibrary + FreeLibrary for kernel32.dll. You shouldn't do that, because kernel32.dll is always residing withing any process, so you must call GetModuleHandle instead, and never call FreeLibrary, that is the right way.
If you ever made any improvement to this example, i would be very nice to see here
I appreciate if you come back to me on this, as i'm working on an article with similar subject, about CPU information in general.
Regards,
Vitaly
|
|
|
|
 |
|
 |
No I've not improve this article;
I will be very interesting to read your work.
GetModuleHandle is fine but there is no problem to use LoadLibrary / FreeLibrary because there is a reference counter in LoadLibrary
EricJ
-----------------------------
ejor @ http://dev.jesover.net
|
|
|
|
 |
|
 |
Hi ejor,
I appreciate such quick responce!
I'm trying to incorporate CPU usage into my ProSysLib project as just of the CPU parameters. I appreciate if you can provide any useful tips in this area.
I've looked at this issue in the past, and the only reliable method that i found was one of WMI. But right now i cannot use WMI, i'm looking for a much lighter method like the one that you showed in your article here.
I, however, need to do lots of changes to it. First of all, i need to support Windows 2000, and then to figure out what's that Processor parameter that's always zero for me, 'cos i don't think i need it anyway
I think your article would be much better if you privided for support of Windows 2000 as well. Anyways, this is what i'm going to write, methinks
Regards,
Vitaly
|
|
|
|
 |
|
 |
The source code does not compile. Complains of a mismatched ) in one of the header files.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
 |
|
 |
Anyone know how to use the above "sanctioned" functions to figure out the percent cpu load for a process?
Currently the code described in this article gets the overall cpu load of the system which is great, but trying to figure out how much of that is due to your process seems more tricky.
This is since it returns "100", meaning the process in question is running and not idle.
Thanks for any pointers.
|
|
|
|
 |
|
|
 |
|
 |
CPU::~CPU()
{
if( s_hKernel == NULL )
{
FreeLibrary( s_hKernel ); s_hKernel = NULL;
}
::DeleteCriticalSection( &m_lock );
}
Shouldn't it be != NULL?
|
|
|
|
 |
|
 |
yes of course ...
Thank you.
but anyway you can't releasing Kernel
-----------------------------
ejor @ http://dev.jesover.net
|
|
|
|
 |
|
 |
Hi,
In your conclusion, you mentioned "For multiple processor system, you don't have the right information". Could you please explain this or give me a pointer to get more info about this?
Thanks,
T.
|
|
|
|
 |
|
 |
today with this solution you can't have the cpu usage for each processor.
We need an other function GetSystemTimes is fo all the computer
-----------------------------
ejor @ http://dev.jesover.net
|
|
|
|
 |
|
 |
Dear Ejor,
first of all : thanks for your work.
I want to implement a simple cpu usage monitoring in a software called max/msp and i plan to do this from scratch, with your sources.
But, as i am using cygwin / eclipse cdt platform, i wonder how to resolve crtdbg.h / tchar.h missing headers ?
Any clues ?
Best regards
f.e
|
|
|
|
 |
|
 |
TCHAR is for UNICODE
end crtdbg is for ASSERT
Best Regards
-----------------------------
ejor @ http://dev.jesover.net
-- modified at 5:31 Sunday 26th February, 2006
|
|
|
|
 |
|
 |
Hi. In your article you said
> idleTime is the rest because "System Idle" process is taking 100 % of CPU.
Looking at the values Windows is returning, this seems logical, but I was wondering how you figured this out. Is it documented some place (and if so where), or did you figure it out some other way? Thanks.
|
|
|
|
 |
|
 |
Yes it is documented ...
And if you look in your task manager you'll see "System Idle Process" (on english system) wich are taking the rest of your cpu ( 97% for me now )
-----------------------------
ejor @ http://dev.jesover.net
-- modified at 16:05 Friday 20th January, 2006
|
|
|
|
 |
|
 |
This is what am looking for. But I need to implement it it windows CE, since CE doesnt support Kernel32.lib.
Does anyone know how CE based applications (like RhinoStats CPU Usage utility) calculate CPU usage??
Thanks!
|
|
|
|
 |
|
 |
Hey even i am looking for the same can anyone help me....
thanks in advance...
One & Only
NRVSundar
|
|
|
|
 |
|
 |
Is there a way to use this program to get info off of a remote computer?
|
|
|
|
 |
|
 |
no this is only local
try WMI
-----------------------------
ejor @ http://dev.jesover.net
|
|
|
|
 |
|
 |
i want to show current cpu usage in my application.My application displays status with 10 sec intervals.i use the calculation referred in this thread but i am confused at the point that
should i get last times before each interval like this;
GetSystemTimes((LPFILETIME)&last_idleTime, (LPFILETIME)&last_kernelTime,
(LPFILETIME)&last_userTime);
sleep(1000);
GetSystemTimes((LPFILETIME)&idleTime,(LPFILETIME)&kernelTime,
(LPFILETIME)&userTime);
//do the calculation...
or should i get them just once at the beginning of my program and do the calculation accordingly?
|
|
|
|
 |
|
 |
well .....
look in cpu.cpp
I've written a class to do the job as a sample
GetSystemTimes give you the amount of time that the system has spent from the boot
-----------------------------
ejor @ http://dev.jesover.net
|
|
|
|
 |
|
 |
All is said in the subject
|
|
|
|
 |
|
 |
Very good code, simple, and quiet nice. In fact, the TaskManager uses also times in order to calculate CPU usage , the difference is that it makes it with NtQuerySystemInformation wich return directly System Time and Idle Time. So this is a very good alternative solution to NtQuerySystemInformation.
Thank you very much and congrats... and HAPPY CODE!
{And sorry if my english is too poor, but I'm learning }
|
|
|
|
 |
|
 |
hi,
when i execute GetCpu.exe the output comes out as below:
Process : 0 System : 0
Process : 0 System : 0
Process : 0 System : 0
.
.
.
keeps on coming..........did i miss on something,
or did i do something wrong?
|
|
|
|
 |
|
 |
hi,
I use Windows XP- pro.
There is no error shown, of any kind while executing GetCpu.exe.
what did you exactly mean by saying "Are you looking in task manager if your computer is not too fast"?
|
|
|
|
 |