?
Solved

Having a Program Monitor Its Own CPU Usage

Posted on 2006-03-30
2
Medium Priority
?
229 Views
Last Modified: 2010-04-15
I am looking for a way to have a program monitor its own CPU usage.  Can anyone describe how I may do this (code would be appreciated as well)?  I am trying to write the program in C using Microsoft Visual .Net.  Thanks.
0
Comment
Question by:jtrades
2 Comments
 
LVL 11

Accepted Solution

by:
x4u earned 2000 total points
ID: 16338655
You can call GetCurrentProcess() to get your your own process handle and then use GetProcessTimes() to find out how much time was spent by your process.
http://msdn.microsoft.com/library/en-us/dllproc/base/getprocesstimes.asp

If you want to get a percentage value similar to those displayed in task manager you can use the Performance Data Helper API:
http://support.microsoft.com/kb/262938/en-us
There is a discusssion about this and a code sample at the end of this articte:
http://www-128.ibm.com/developerworks/websphere/techjournal/0310_braithwaite/braithwaite.html
see here how to get the value with PdhGetFormattedCounterValue directly:
http:Q_20085897.html
0
 
LVL 6

Expert Comment

by:Prashant Sabnekar
ID: 16343841
>>>jtrades, if you want it in Linux i can give you. But for windows I should try.

All the best
Prashant Sabnekar
 
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question