Re: plotting cpu and mem consumption

From: Wim Deprez (wim.deprez+comp.lang.cpp_at_student.luc.ac.be)
Date: 06/18/04


Date: Fri, 18 Jun 2004 15:48:00 GMT

Victor Bazarov wrote:

> "Wim Deprez" <wim.deprez+comp.lang.cpp@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).
>> 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/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.

[...]

> 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



Relevant Pages

  • Re: Windows Task Manager
    ... > tab, but I am have a little trouble understanding the other two. ... 100% cpu usage means that the cpu is being used to the fullest extent. ... and mem usage is the amount of memory being used. ...
    (microsoft.public.win2000.general)
  • Helpsvc
    ... more than 90% cpu usage and a huge amount of memory! ... Prev by Date: ...
    (microsoft.public.windowsxp.general)
  • Re: size?
    ... The amount of memory that the code takes may vary at runtime, ... The amount of memory taken by shared libraries (which may be used ... recursion depth depends on user input. ...
    (comp.lang.c)
  • Re: W3WP memory usage
    ... You may be correct regarding the libraries using the lion's share of memory. ... > I am quite aware that Sharepoint files are stored in the database. ... >>> public class SPVersion ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: Error Using Remoting, System.OutOfMemoryException anyone ever seen this?
    ... it to transfer the DataSet to the client like I wanted. ... >> As Integer, ByVal pnUserID As Integer, ByVal piView As Short) As DataSet ... >> As for memory use, the client which is hung is not peaked out of memory, ... >> it is running 1% cpu usage and barely any memory used. ...
    (microsoft.public.dotnet.framework.remoting)