|
Home > Archive > Unix Programming > February 2007 > C++ Library call to gather process characteristics? pstat?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
C++ Library call to gather process characteristics? pstat?
|
|
| LTSnyder@x3ci.com 2007-02-07, 7:23 pm |
| I have a piece of code that needs fundamental leak analysis, dbx for
this current problem is non-functional.
The basic question is, is there a unix library that I can link into
the executable that will give me a structure of process
characteristics like resident memory, total memory etcetera?
I seem to remember "pstat()" being the call but I can find no
reference to this in the Solaris documentation.
What I really want to be able to do is have the process be able to
(through a function call) publish it's own memory usage
characteristics at mile-stone marks in the code so memory usage can be
tracked relative to code lines in the program.
Any help on this problem will be appreciated. Thanks in advance for
the help.
| |
| Giorgos Keramidas 2007-02-07, 7:23 pm |
| On 7 Feb 2007 12:11:53 -0800, LTSnyder@x3ci.com wrote:
> I have a piece of code that needs fundamental leak analysis, dbx for
> this current problem is non-functional.
> The basic question is, is there a unix library that I can link into
> the executable that will give me a structure of process
> characteristics like resident memory, total memory etcetera?
If you are using (or have access to) a fairly recent Solaris, try the
`libumem' allocator. It has very nice features for tracking down and
analyzing where memory allocation problems exist.
For a mini-guide about libumem and its use, see:
http://access1.sun.com/techarticles/libumem.html
| |
| Ivan Novick 2007-02-07, 7:23 pm |
| On Feb 7, 12:11 pm, LTSny...@x3ci.com wrote:
> I have a piece of code that needs fundamental leak analysis, dbx for
> this current problem is non-functional.
> The basic question is, is there a unix library that I can link into
> the executable that will give me a structure of process
> characteristics like resident memory, total memory etcetera?
>
> I seem to remember "pstat()" being the call but I can find no
> reference to this in the Solaris documentation.
> What I really want to be able to do is have the process be able to
> (through a function call) publish it's own memory usage
> characteristics at mile-stone marks in the code so memory usage can be
> tracked relative to code lines in the program.
>
> Any help on this problem will be appreciated. Thanks in advance for
> the help.
Whats the platform? On linux IIRC some of the information is in the /
proc filesystem and you can read it like a file.
Ivan Novick
http://www.0x4849.net
| |
| LTSnyder@x3ci.com 2007-02-08, 7:20 pm |
| On Feb 7, 7:36 pm, "Ivan Novick" <ivan.d.nov...@gmail.com> wrote:
> On Feb 7, 12:11 pm, LTSny...@x3ci.com wrote:
>
>
>
>
> Whats the platform? On linux IIRC some of the information is in the /
> proc filesystem and you can read it like a file.
>
> Ivan Novickhttp://www.0x4849.net
Sorry about missing the Details, this is on Solaris 9 on a Sunfire
box.
The reason I want a means to access the total memory footprint from a
library call is because there is a chance that this is a logical bug
in allocation as per our implementation of a STL list in which case it
is not any actual leak but rather just abusive use of memory by a
particular funtion/class/operation.
Being able to create milestones in the code with a memory usage report
woudl be a quick and dirty way to norrow down a logical memory use
flaw in the code.
> If you are using (or have access to) a fairly recent Solaris, try the
> `libumem' allocator. It has very nice features for tracking down and
> analyzing where memory allocation problems exist.
While `libumem' is very useful for tracking down code leaks, overruns,
etcetera it does not allow me to get the "memory footprint" I state I
want above in this message.
Leland T. Snyder
| |
| Ian Collins 2007-02-08, 7:20 pm |
| LTSnyder@x3ci.com wrote:
>
> Sorry about missing the Details, this is on Solaris 9 on a Sunfire
> box.
> The reason I want a means to access the total memory footprint from a
> library call is because there is a chance that this is a logical bug
> in allocation as per our implementation of a STL list in which case it
> is not any actual leak but rather just abusive use of memory by a
> particular funtion/class/operation.
> Being able to create milestones in the code with a memory usage report
> woudl be a quick and dirty way to norrow down a logical memory use
> flaw in the code.
>
Have you tried providing your own implementation of the global new and
delete operators? Assuming your application isn't doing anything nasty
like calling malloc, that should give you all the information you require.
--
Ian Collins.
| |
| LTSnyder@x3ci.com 2007-02-08, 7:20 pm |
| On Feb 8, 3:37 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> LTSny...@x3ci.com wrote:
>
>
> Have you tried providing your own implementation of the global new and
> delete operators? Assuming your application isn't doing anything nasty
> like calling malloc, that should give you all the information you require.
>
> --
> Ian Collins.
That could be done of course, a lot of code is libraries included as
archives that I do not with to recompile unless I need to.
I guess the answer is that there is no library method to provide a
memory footprint (res/total) of a particular pid.
I'll use the suggested solutions.
-Leland T. Snyder
| |
| Ian Collins 2007-02-08, 7:20 pm |
| LTSnyder@x3ci.com wrote:
> On Feb 8, 3:37 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>
>
> That could be done of course, a lot of code is libraries included as
> archives that I do not with to recompile unless I need to.
That won't be necessary, if you provide your own new/delete they will
replace the defaults at link time. I use my own version for all my
testing to check for leaks and to profile of allocation sizes.
--
Ian Collins.
| |
| LTSnyder@x3ci.com 2007-02-08, 7:20 pm |
| On Feb 8, 4:08 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> LTSny...@x3ci.com wrote:
>
>
>
>
>
> That won't be necessary, if you provide your own new/delete they will
> replace the defaults at link time. I use my own version for all my
> testing to check for leaks and to profile of allocation sizes.
>
> --
> Ian Collins.- Hide quoted text -
>
> - Show quoted text -
Sounds great, but how do you overload (or pick up an alternate
definition via shared object) if the "new" allocation routine/method/
wrapper if it is a keyword of the C++ ANSI spec?
Does this imply that new is being pulled from a shared object and that
I can "swap" in and out this rewrite of new by simply changing if the
true shared object defining new, or my hack, is found first?
Can you point me to an example of this?
-Leland T. Snyder
| |
| Eric Sosman 2007-02-08, 7:20 pm |
| LTSnyder@x3ci.com wrote On 02/08/07 15:24,:
> On Feb 7, 7:36 pm, "Ivan Novick" <ivan.d.nov...@gmail.com> wrote:
>
>
>
> Sorry about missing the Details, this is on Solaris 9 on a Sunfire
> box.
> The reason I want a means to access the total memory footprint from a
> library call is because there is a chance that this is a logical bug
> in allocation as per our implementation of a STL list in which case it
> is not any actual leak but rather just abusive use of memory by a
> particular funtion/class/operation.
> Being able to create milestones in the code with a memory usage report
> woudl be a quick and dirty way to norrow down a logical memory use
> flaw in the code.
One thing you could do is read /proc/self/map and add
up the address mappings ("man -s4 proc"). That's fairly
crude because it doesn't distinguish malloced/newed memory
from freed/deleted memory: it just reports what's mapped
in your address space. If you've got a leak, though, the
total mapped space should increase over time.
--
Eric.Sosman@sun.com
| |
| Ian Collins 2007-02-08, 7:20 pm |
| LTSnyder@x3ci.com wrote:
> On Feb 8, 4:08 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>
Please trim signatures, it make for less crud.[vbcol=seagreen]
>
> Sounds great, but how do you overload (or pick up an alternate
> definition via shared object) if the "new" allocation routine/method/
> wrapper if it is a keyword of the C++ ANSI spec?
> Does this imply that new is being pulled from a shared object and that
> I can "swap" in and out this rewrite of new by simply changing if the
> true shared object defining new, or my hack, is found first?
> Can you point me to an example of this?
>
The global new and delete operators are provide by the C++ runtime
library. They implemented as week symbols, so if you code contains
these operators, they will be used by the linker in preference to those
in the runtime library.
The exact implementation isn't defined by the standard, but the ability
to replace the global new and delete operators is.
--
Ian Collins.
| |
| LTSnyder@x3ci.com 2007-02-08, 7:20 pm |
| On Feb 8, 6:07 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> LTSny...@x3ci.com wrote:
>
>
>
>
> Please trim signatures, it make for less crud.
>
>
>
>
> The global new and delete operators are provide by the C++ runtime
> library. They implemented as week symbols, so if you code contains
> these operators, they will be used by the linker in preference to those
> in the runtime library.
>
> The exact implementation isn't defined by the standard, but the ability
> to replace the global new and delete operators is.
>
> --
> Ian Collins.
Overloading a weak symbol with a custom defined operator is ( at least
partially ) a compile time operation not solely a link time operation.
What your saying does not seem to imply that an archive file using
new, can have it's new operation overloaded just via the addition of a
shared object in it's path, in fact the compiler (when the archive was
compiled) probably just translated the call into it's (compiler
defined malloc wrapper ) definition thus no symbol for new would be
seen in the archive ( which seems to be the case when I examine my
archive files ).
If there is a reference elsewhere that shows archive files using a
alternate "new" definition just by swapping shared objects, please
point me to the reference, I would be very interested.
-Leland T. Snyder
| |
| Ian Collins 2007-02-08, 7:20 pm |
| LTSnyder@x3ci.com wrote:
> On Feb 8, 6:07 pm, Ian Collins <ian-n...@hotmail.com> wrote:
Please trim signatures, it make for less crud.[vbcol=seagreen]
>
> Overloading a weak symbol with a custom defined operator is ( at least
> partially ) a compile time operation not solely a link time operation.
> What your saying does not seem to imply that an archive file using
> new, can have it's new operation overloaded just via the addition of a
> shared object in it's path, in fact the compiler (when the archive was
> compiled) probably just translated the call into it's (compiler
> defined malloc wrapper ) definition thus no symbol for new would be
> seen in the archive ( which seems to be the case when I examine my
> archive files ).
>
> If there is a reference elsewhere that shows archive files using a
> alternate "new" definition just by swapping shared objects, please
> point me to the reference, I would be very interested.
>
As I said, the new and delete operators are part of the C++ runtime
library, they are not included in any user built archives.
Please refer to sections 3.7.3/2, 17.4.3.4/2 and last but not least,
18.4.1.1 of the C++ standard.
--
Ian Collins.
| |
| Vallabha 2007-02-09, 7:20 am |
| On Feb 9, 1:24 am, LTSny...@x3ci.com wrote:
> On Feb 7, 7:36 pm, "Ivan Novick" <ivan.d.nov...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
> Sorry about missing the Details, this is on Solaris 9 on a Sunfire
> box.
> The reason I want a means to access the total memory footprint from a
> library call is because there is a chance that this is a logical bug
> in allocation as per our implementation of a STL list in which case it
> is not any actual leak but rather just abusive use of memory by a
> particular funtion/class/operation.
> Being able to create milestones in the code with a memory usage report
> woudl be a quick and dirty way to norrow down a logical memory use
> flaw in the code.
>
>
> While `libumem' is very useful for tracking down code leaks, overruns,
> etcetera it does not allow me to get the "memory footprint" I state I
> want above in this message.
>
> Leland T. Snyder- Hide quoted text -
>
> - Show quoted text -
You can trap the malloc and free calls and print useful information.
For example:
void* malloc(size_t size)
{
void* (*fn)(size_t);
void* a;
fn = dlsym(RTLD_NEXT, "malloc");
a= fn(size);
printf("mallocing at 0%x\n", a);
return a;
}
Write a similar routine for "free"... this way you will know malloc/
free'ed space and leaks too....
Note, this piece of code is not easily portable...it will not work on
Solaris 8 or earlier versions...
Cheers
-Vallabha
S7 Software Solutions
http://www.s7solutions.com/
// These are my own opinions... my company has no control over my
opinions .. so 
| |
| LTSnyder@x3ci.com 2007-02-09, 1:17 pm |
| On Feb 8, 6:59 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> LTSny...@x3ci.com wrote:
>
>
>
> Please trim signatures, it make for less crud.
>
>
>
> As I said, the new and delete operators are part of the C++ runtime
> library, they are not included in any user built archives.
>
> Please refer to sections 3.7.3/2, 17.4.3.4/2 and last but not least,
> 18.4.1.1 of the C++ standard.
>
> --
> Ian Collins.
> As I said, the new and delete operators are part of the C++ runtime
> library, they are not included in any user built archives.
Yes, however if it was a symbol that was being references it's
undefined reference would be found in the symbol table of an user
defined archive using it.
This is obviously not what is happening.
Vallabha,
Thanks for the malloc/free example.
| |
| Ian Collins 2007-02-09, 7:19 pm |
| LTSnyder@x3ci.com wrote:
> On Feb 8, 6:59 pm, Ian Collins <ian-n...@hotmail.com> wrote:
*Please trim signatures!!*[vbcol=seagreen]
>
> Yes, however if it was a symbol that was being references it's
> undefined reference would be found in the symbol table of an user
> defined archive using it.
> This is obviously not what is happening.
>
I'm not sure what you are saying.
Put your own new and delete in an archive and make this the first file
in the link. That's how I build mine in.
--
Ian Collins.
|
|
|
|
|