James Moe | 8 Dec 03:15 2006

Stack space usage


Hello,
  Is there a way to monitor the current stack space within a program? And,
as a bonus, the heap and shared memory?
  I found getrusage() in <sys/resource.h> but the linker complains that
there is no object.

--
jimoe (at) sohnen-moe (dot) com
Knut St. Osmundsen | 8 Dec 18:47 2006
Picon

Re: Stack space usage

James Moe wrote:
> Hello,
>   Is there a way to monitor the current stack space within a program? And,
> as a bonus, the heap and shared memory?

The best way to monitor stack usage is by coloring (memset()) the stack 
and check how much of it is untouched. You can get the stack top/bottom 
addresses from DosGetInfoBlocks(&pTib, &pPib); pTib->tib_...stack.

I don't quite recall if there is a heap api for querying the amount 
memory it currently uses. grep -e 'heap.*stat' might find something... 
As for shared memory, there you have to ask OS/2, which means using the 
kernel debugger or Theseus (former is difficult, the latter I'm not very 
familiar with I'm afraid).

>   I found getrusage() in <sys/resource.h> but the linker complains that
> there is no object.

I don't think we've got a working getrusage() yet.

Kind Regards,
  knut
James Moe | 8 Dec 20:41 2006

Re: Stack space usage


Knut St. Osmundsen wrote:
> James Moe wrote:
>> Hello,
>>   Is there a way to monitor the current stack space within a program? And,
>> as a bonus, the heap and shared memory?
> 
> The best way to monitor stack usage is by coloring (memset()) the stack 
> and check how much of it is untouched. You can get the stack top/bottom 
> addresses from DosGetInfoBlocks(&pTib, &pPib); pTib->tib_...stack.
> 
  That's good.
  Is there a simple way to get the value of the Stack Pointer? All I'd
need is ESP. I seem to recall an _asm() directive. Is that supported by gcc?

--
jimoe (at) sohnen-moe (dot) com
Steven Levine | 8 Dec 23:05 2006
Picon
Picon

Re: Stack space usage

In <4579BFDA.2050707 <at> sohnen-moe.com>, on 12/08/06
   at 12:41 PM, James Moe <jimoe <at> sohnen-moe.com> said:

>  Is there a simple way to get the value of the Stack Pointer?

No need for _asm() here.  Just take the address of the last local
variable.

Regards,

Steven

--

-- 
----------------------------------------------------------------------
"Steven Levine" <steve53 <at> earthlink.net>  MR2/ICE 2.67 #10183 Warp/eCS/DIY/14.103a_W4
www.scoug.com irc.fyrelizard.com #scoug (Wed 7pm PST)
----------------------------------------------------------------------
Knut St. Osmundsen | 8 Dec 23:13 2006
Picon

Re: Stack space usage

Steven Levine wrote:
> In <4579BFDA.2050707 <at> sohnen-moe.com>, on 12/08/06
>    at 12:41 PM, James Moe <jimoe <at> sohnen-moe.com> said:
> 
>>  Is there a simple way to get the value of the Stack Pointer?
> 
> No need for _asm() here.  Just take the address of the last local
> variable.

Another option is to do a tiny dynamic stack allocation:
	void *pvTopOfStack = alloca(1);

The inline assembly for reading ESP goes like this:
	__asm__ __volatile__ ("movl %0,%%esp", "=r" (pvTopOfStack));

If you are going to color (memset) the stack, you have to add a safety 
area between the current stack pointer and where you start (stop 
actually considering the stack direction) the coloring. That goes for 
all three methods.

Kind Regards,
  knut
Steven Levine | 8 Dec 23:27 2006
Picon
Picon

Re: Stack space usage

In <4579A529.3070903 <at> anduin.net>, on 12/08/06
   at 06:47 PM, "Knut St. Osmundsen" <bird <at> anduin.net> said:

>I don't quite recall if there is a heap api for querying the amount 
>memory it currently uses. grep -e 'heap.*stat' might find something... 

It looks like ustats() might do the job.

>Theseus (former is difficult, the latter I'm not very 
>familiar with I'm afraid).

It's pretty easy with Theseus for a running app.  Select the app on the
main gui window.  Then it's Process->Memory Utilization.

Regards,

Steven

--

-- 
----------------------------------------------------------------------
"Steven Levine" <steve53 <at> earthlink.net>  MR2/ICE 2.67 #10183 Warp/eCS/DIY/14.103a_W4
www.scoug.com irc.fyrelizard.com #scoug (Wed 7pm PST)
----------------------------------------------------------------------
Steven Levine | 8 Dec 23:31 2006
Picon
Picon

Re: Stack space usage

In <4579E384.2010301 <at> anduin.net>, on 12/08/06
   at 11:13 PM, "Knut St. Osmundsen" <bird <at> anduin.net> said:

>If you are going to color (memset) the stack, you have to add a safety 
>area between the current stack pointer and where you start (stop 
>actually considering the stack direction) the coloring. That goes for 
>all three methods.

Also when coloring the stack for the main thread, it's a good idea to
start at the top of the area to be colored and work downward.

Regards,

Steven

--

-- 
----------------------------------------------------------------------
"Steven Levine" <steve53 <at> earthlink.net>  MR2/ICE 2.67 #10183 Warp/eCS/DIY/14.103a_W4
www.scoug.com irc.fyrelizard.com #scoug (Wed 7pm PST)
----------------------------------------------------------------------
kLIBC | 16 Dec 12:38 2006
Picon

[kLIBC] #133: _SC_PAGESIZE missing in sysconf()

#133: _SC_PAGESIZE missing in sysconf()
--------------------+-------------------------------------------------------
 Reporter:  cinc    |       Owner:  bird                
     Type:  defect  |      Status:  new                 
 Priority:  normal  |   Milestone:                      
Component:  libc    |     Version:  0.6.1               
 Severity:  normal  |    Keywords:  sysconf _SC_PAGESIZE
--------------------+-------------------------------------------------------
 The sysconf() function doesn't implement the _SC_PAGESIZE (and
 _SC_PAGE_SIZE) parameters. This breaks GLIB 2.12.4 compilation (a
 workaround is easy, though).

-- 
Ticket URL: <http://svn.netlabs.org/libc/ticket/133>
kLIBC <http://svn.netlabs.org/libc>
kLIBC
James Moe | 16 Dec 20:16 2006

Re: Stack space usage


Steven Levine wrote:
> 
>>  Is there a simple way to get the value of the Stack Pointer?
> 
> No need for _asm() here.  Just take the address of the last local
> variable.
> 
  How easy! Works a treat. Thanks.

--
jimoe (at) sohnen-moe (dot) com
Brendan Oakley | 19 Dec 06:30 2006
Picon

kmk

So let me be sure I have this straight. Can kmk be used as a drop-in
replacement for gmake?

Gmane