473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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
Jul 22 '05 #1
3 1590
Since I don't read alt.comp.lang.learn.c-c++, I removed it from crosspost
list of newsgroups.

"Wim Deprez" <wi**********************@student.luc.ac.be> wrote...
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).
Read about 'clock' function.
After some google'ing I found some (nice) examples[2] but they are all
windows based. Does universal code for this problem exist?
Probably not. The best thing is to utilise system-specific ways
of gathering those data (CPU usage) or even use a system-specific
utility (if memory serves me right, it's called "profiler").
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.
And?
So I am looking for something OS independant, but examples for windows or
*nix can help me out for now as well.


Well, again, look into using 'clock'. But you'd be much better off
if you don't reinvent the wheel but look into using some kind of
profiling library (or libraries, if no multi-platform one exists).

You should be able to find plenty of interesting libraries in the
"Available C++ Libraries FAQ" published here about monthly by Nikki
Locke.

Victor
Jul 22 '05 #2
Wim Deprez wrote:
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.
I'm trying to travel to Tierra del Fuego by sitting perfectly still in my
steno chair.

Your question is a non-sequitur. Cell phones (that support C++) have a fixed
amount of memory of at least three types - flash, ROM, and volatile. My
notebook has a swap file for a huge address space within a finite amount of
volatile storage. Universal code to cover all these situations is
impossible.

In an old-fashioned MS-DOS program, one could spot-check storage by
allocating blocks of memory until malloc() returned NULL. Available storage
equaled the sum of sizes of successfully allocated blocks. A protected-mode
application using virtual memory can't do that, because the swapping system
will continue creating new blocks long after all available memory is
over-committed.
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.


Conditional compilation is your friend.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #3
Victor Bazarov wrote:
"Wim Deprez" <wi**********************@student.luc.ac.be> wrote...
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 niceif 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).
Does universal code for this problem exist?

Probably not. The best thing is to utilise system-specific ways
of gathering those data (CPU usage) or even use a system-specific
utility (if memory serves me right, it's called "profiler").


Yeah, I kind of gave up the search to some kind of "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.

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.

[...]
look into using 'clock'. But you'd be much better off
don't reinvent the wheel but look into using some kind of
profiling library (or libraries, if no multi-platform one exists).

You should be able to find plenty of interesting libraries in the
"Available C++ Libraries FAQ" published here about monthly by Nikki
Locke.

ok, I got the clock-function (from time.h:
http://www.cplusplus.com/ref/ctime/clock.html). I probably overlook
something, because I don't exactly get your point, it is not the /time/ that
it takes to run the program, but the amount cpu it uses, it is possible that
other programs are running in the background and such.

So I am looking through the Libraries FAQ, but I didn't find something of a
'profiler', only the 'mpatrol', but that is about debugging dynamically
allocated memory...

And I am still looking for something to measure the memory usage.

Victor


Thanks for the tips, I didn't know the Libraries FAQ (quite new to the
group).

Many kind greetings,

--wim
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: srijit | last post by:
Hi, I am looking for a good plotting package (preferably with 3D plotting capabilities) based on Python 2.3 (Windows 98). Unfortunately Dislin does not exist for Python 2.3. I look forward to...
3
by: Erik Lechak | last post by:
Hello All, I am creating a visual programming environment for python (similar to Matlab's simulink, but for python). For several reasons I have decided not to go with OGL. I am writing a wxOGL...
6
by: Gerrit Holl | last post by:
Hi, I have a dictionairy containing DateTime objects as keys and integers as values. What would be the easiest way to create a simple plot of these, with a number axis versus a time axis? What...
6
by: DG | last post by:
I'm interesting in finding the ultimate cross-platform python plotting module. So far I've used scipy.gplt and biggles which both have disadvantages. There is no python 2.3 binary package for...
7
by: Russell E. Owen | last post by:
Can anyone recommend a fast cross-platform plotting package for 2-D plots? Our situation: We are driving an instrument that outputs data at 20Hz. Control is via an existing Tkinter application...
7
by: Rolf Wester | last post by:
Hi, I have a Python console application that is intended to be used interactively and I have to add plotting capabilities (multiple XY plots and if possible 2D-surface plots). I'm loocking for a...
4
by: skorpio11 | last post by:
Hi, I've been having some problems trying some basic plotting commands with gnuplot.py. My setup is the Python 2.3 Enthought edition and my script looks as: from scipy import * from scipy...
1
by: T. Crane | last post by:
Hi, I am looking for a good plotting library. I intend to do 3D surface plots, 2D contour, 3D waterfall, etc. Right now I have access to National Instruments' Measurement Studio, and it's...
0
by: Helmut Michels | last post by:
Dear C/C++ programmers, I am pleased to announce version 9.4 of the data plotting software DISLIN. DISLIN is a high-level and easy to use plotting library for displaying data as curves, bar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.