954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

plotting cpu and mem consumption

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

vvim
Newbie Poster
3 posts since Jun 2004
Reputation Points: 12
Solved Threads: 0
 

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 :)

big_k105
PFO Founder
Team Colleague
357 posts since May 2003
Reputation Points: 36
Solved Threads: 2
 

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

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

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

vvim
Newbie Poster
3 posts since Jun 2004
Reputation Points: 12
Solved Threads: 0
 

You could try looking in *nix development fourms.Also try looking in google.You will definately find good info if you search properly.

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

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/debug/article.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

vvim
Newbie Poster
3 posts since Jun 2004
Reputation Points: 12
Solved Threads: 0
 

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.

zeah
Newbie Poster
8 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

hi
I have similar problem. Propably even more difficult:P 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?

codigo
Newbie Poster
1 post since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Stop posting in this thread o.0 its 4 years old.

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You