943,498 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5470
  • C++ RSS
Jun 16th, 2004
2

plotting cpu and mem consumption

Expand Post »
Hi Group,

for a project[1] I am trying to find an OS independant way to measure the amount of cpu usage and memory consumption of the program. It would be nice if I could do that in my C++ code, so I can show the results at runtime or even plot a nice graph (I got wild dreams).

After some google'ing I found some (nice) examples[2] but they are all windows based. Does universal code for this problem exist?

Of course I can make different classes (one for windows and another for *nix), I do something similar to assign sockets. But then I also need code for *nix, without using bash-scripting of course.

So I am looking for something OS independant, but examples for windows or *nix can help me out for now as well.

Goodnight everyone and thanks in advance,

--wim
______
[1] I am trying to compare some differint multicast protocols, and yes, also cpu usage and memory consumption is an important part of that :-)
[2] if anybody wants them, I can always post links, just ask
Reputation Points: 12
Solved Threads: 0
Newbie Poster
vvim is offline Offline
3 posts
since Jun 2004
Jun 17th, 2004
1

Re: plotting cpu and mem consumption

im not thinking you will find universal code for what you want to do. but good luck on your search i will keep an eye open for you
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Jun 17th, 2004
1

Re: plotting cpu and mem consumption

Hello,

There are some ways to do this.

For CPU monitoring (and network), you can look into a package called mrtg that can be setup to monitor CPU processes, and graph it out. It will require you to setup snmpd and other things in order to get it to function properly.

For code, and how much CPU you use, check out your compiler to see if it supports profiling. I did that for COBOL code on a VAX/VMS, and for C++ on my Macintosh. Found out what functions used the most CPU time, and how long it took to do them. I liked profiling sorts, and comparing quicksort vs. bubble sort and the like.

Now, I know it isn't cross-platform, but the profiling might be the most efficient and non-skewing of the techniques. Why? because it is built into the compiler environment, and I am sure that the program coders took that into account.

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
Jun 18th, 2004
0

Re: plotting cpu and mem consumption

BigK: Yeah, I kind of gave up the search to "universal code" (I just like the sound of it (-. I guess I'll have to write separate implementations for each OS and use conditional compile statements in the source code.

kc0arf: the problem is that I want to do it at run time, in the code itself. the idea is that my program plots a graph (or make a log file, whatever), so every (future) user can see how much resources a protocol uses, without needing to know to go to the /proc-dir

Another major problem is that I haven't found interesting code concerning the memory consumption. Until know, I only found ways to measure CPU-cycles and only for windows. Can anyone help me?

Many kind greetings and thanks in advance,

--wim deprez
Reputation Points: 12
Solved Threads: 0
Newbie Poster
vvim is offline Offline
3 posts
since Jun 2004
Jun 18th, 2004
0

Re: plotting cpu and mem consumption

You could try looking in *nix development fourms.Also try looking in google.You will definately find good info if you search properly.
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Jun 18th, 2004
0

Re: plotting cpu and mem consumption

Well I guess that is my problem then, I first started looking in to Google, but didn't find anything satisfacting to my needs, that is why I started posting on forums. Maybe I do not use the right words to query.

I found some examples for the windowssystem:
http://www.codeproject.com/system/cpuusage.asp and
http://www.codeguru.com/Cpp/V-S/debu...cle.php/c4415/ . Now I am
wondering if it would be a bad idea to use a filepointer to read the
/proc/stat in *nix systems. For now, it is the only posibility I can come up
with. If somebody has a better idea, you're welcome.

And then I still need to find a good solution to check the memory usage. At comp.lang.c++ they referred me to the "Available C++ Libraries FAQ" by Nikki Locke (http://www.trumphurst.com/cpplibs/cpplibs.phtml) but I couldn't find a solution.

Thanks for your help, but I am still on my quest :-)

Many kind greetings,

--wim deprez
Reputation Points: 12
Solved Threads: 0
Newbie Poster
vvim is offline Offline
3 posts
since Jun 2004
Apr 6th, 2008
0

Re: plotting cpu and mem consumption

hi
i need to compute the cpu usage time for my function calls...how do i do that in linux with C++ as my programming language.
Thanks in advance.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zeah is offline Offline
8 posts
since Mar 2008
Aug 7th, 2008
0

Re: plotting cpu and mem consumption

hi
I have similar problem. Propably even more difficult I'd like to measure processor usage while my application is working but on windows mobile. Moreover I'd like to write my own class to do it. Have you got some ideas?
Last edited by codigo; Aug 7th, 2008 at 6:49 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
codigo is offline Offline
1 posts
since Aug 2008
Aug 7th, 2008
0

Re: plotting cpu and mem consumption

Stop posting in this thread o.0 its 4 years old.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Display more than 1 file
Next Thread in C++ Forum Timeline: C++ Extracting data from text files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC