473,797 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get statistics about memory usage ?

Hi,

Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.

For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?

I have tried "getrusage( )". However values returned are not really
relevant for my needs.

I also looked at "mallinfo() ", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it's more or less a C++ code. So, are the "new" counted in
mallinfo() ?)

Then, how can my program know its "resident set size" and especially its
"virtual memory size"?

Thanks.
Christophe
Dec 2 '05 #1
26 19145
Christophe Lohr wrote:
Hi,

Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.

For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?

I have tried "getrusage( )". However values returned are not really
relevant for my needs.

I also looked at "mallinfo() ", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it's more or less a C++ code. So, are the "new" counted in
mallinfo() ?)

Then, how can my program know its "resident set size" and especially its
"virtual memory size"?

Thanks.
Christophe


The C language itself knows not of such things. Is is likely, however,
that your platform provides some way of getting such information (likely
in a reasonable way) <hint, hint>. See your documentation or post to a
relevant newsgroup.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Dec 2 '05 #2
Christophe Lohr wrote:
Hi,

Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.

For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?

I have tried "getrusage( )". However values returned are not really
relevant for my needs.

I also looked at "mallinfo() ", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it's more or less a C++ code. So, are the "new" counted in
mallinfo() ?)

Then, how can my program know its "resident set size" and especially its
"virtual memory size"?

Thanks.
Christophe


This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>

-David

Dec 2 '05 #3
"David Resnick" <ln********@gma il.com> writes:
[...]
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>


<STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 2 '05 #4
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.or g> wrote:
"David Resnick" <ln********@gma il.com> writes:
[...]
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>


<STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>


That should have been:

<WRONG>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</WRONG>

Solaris has /proc, as do (I believe) over Unix flavors.

Dec 2 '05 #5
In article <dm**********@m atell.enst-bretagne.fr>,
Christophe Lohr <ch************ *@enst-bretagne.fr> wrote:
Hi,

Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.

For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?


Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.

Dec 2 '05 #6
ga*****@yin.int eraccess.com (Kenny McCormack) writes:
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.or g> wrote:
"David Resnick" <ln********@gma il.com> writes:
[...]
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>


<STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>


That should have been:

<WRONG>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</WRONG>

Solaris has /proc, as do (I believe) over Unix flavors.


With a *very* different interface, the details of which are, of
course, best discussed elsewhere. Followups to /dev/null.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 2 '05 #7
Kenny McCormack wrote:
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.or g> wrote:
"David Resnick" <ln********@gma il.com> writes:
[...]
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT> <STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>


That should have been:

<WRONG>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</WRONG>


No, what Keith said is correct.
Solaris has /proc, as do (I believe) over Unix flavors.


Are you claiming that these Unix flavours are not like Unix?
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 2 '05 #8
Kenny McCormack wrote:
[usual crap]

You're still alive Kenny? I thought someone would have killfiled you by now.

Joe
Dec 2 '05 #9

"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
news:dk******** ****@news.flash-gordon.me.uk...
Kenny McCormack wrote:
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.or g> wrote:
"David Resnick" <ln********@gma il.com> writes:
[...]
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.progr ammer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>
<STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>


That should have been:

<WRONG>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</WRONG>


No, what Keith said is correct.


Actually, what Keith said is most definately NOT correct.
Solaris has /proc, as do (I believe) over Unix flavors.


Are you claiming that these Unix flavours are not like Unix?


No, his claim is that: /proc is NOT linux specific... and he is right.
Many systems (which predate Linux) also use(d) a /proc file system.

Dec 2 '05 #10

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

Similar topics

4
2501
by: Anand Pillai | last post by:
Hi Folks (posting after a loooong time...) I have been contracted by an Indian publisher to author an introductory text book on Python. As a part of the introductory chapter, I thought it would be a good idea to present a number, a round-about figure on the approximate *actual* usage of Python out there in number of developers and/or installations.
3
4152
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
1
2428
by: Jason | last post by:
Greetings, Is there a reliable and portable way of getting malloc statistics within a running C program? I have tried to use the mallinfo() command, but it isn't portable (reports different things on linux and HP), and Purify reports memory access violations with it. At any given point in a program, I would like to grab total used memory for the process. Does anyone have a good way of doing this? Thanks Jason
4
3561
by: serge | last post by:
I am running a query in SQL 2000 SP4, Windows 2000 Server that is not being shared with any other users or any sql connections users. The db involves a lot of tables, JOINs, LEFT JOINs, UNIONS etc... Ok it's not a pretty code and my job is to make it better. But for now one thing I would like to understand with your help is why the same SP on the same server and everything the same without me changing anything at all in terms of SQL...
17
5103
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area. And it is easy to come up with many more examples, where such kind of statistics can be very...
5
1747
by: Allan Ebdrup | last post by:
Hi We have a large class library of different classes, now we are going to implement a lot of usage statistics that we need, stuff like how many times a user has logged in, how many times a message has been read, how many times a ad has been shown and so on. Now I'm wondering what would be a good OO organization of this data, should the statistics be part of the objects they are for, or should statistics be seperate. Perhaps each object...
2
2680
by: Quasar | last post by:
Hi everybody! I''ve created a script that enable the statistics for a specific DB: #!/bin/sh if ; then echo Enabling monitoring switches for ${1} db2 connect to ${1} db2 update monitor switches using TABLE on UOW on TIMESTAMP on STATEMENT on BUFFERPOOL on LOCK on SORT on
1
2050
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after the objects for which that memory was allocated are no longer live in the process. This is only a leak if peak memory goes up again each time you create any new objects. Try repeated allocations of a large dictionary and observe how memory...
10
6544
by: w.l.fischer | last post by:
Is it possible to have statistics on temporary tables? I frequently put 10000 or more rows in a temporary table and would like to know it the queries become faster with statistics on those tables.
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9063
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.