Memory context usage

Started by Adriano Langeover 16 years ago6 messages
#1Adriano Lange
alange0001@gmail.com

Hi,

How can I get the used memory of a memory context?

Is there some function like:

int getMemoryUsage( MemoryContext )

?

I still working in a subplan cache for a query optimizer and I need to know
whether a temporary memory context is in certain limits.

Thanks

Adriano

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Adriano Lange (#1)
Re: Memory context usage

Adriano Lange <alange0001@gmail.com> writes:

How can I get the used memory of a memory context?

MemoryContextStats() might help. It just dumps the info to stderr
though.

regards, tom lane

#3Greg Smith
gsmith@gregsmith.com
In reply to: Tom Lane (#2)
Re: Memory context usage

On Fri, 28 Aug 2009, Tom Lane wrote:

MemoryContextStats() might help. It just dumps the info to stderr
though.

Which means it ends up in the database log files in the common
configuration where where the database's stderr is redirected to there.
I even script running this regularly against stuff I'm suspicious of,
using something like this passed the PID of the process I want to watch:

#!/bin/bash
gdb -p $1 <<EOF
p MemoryContextStats(TopMemoryContext)
detach
quit
EOF

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

#4Adriano Lange
alange0001@gmail.com
In reply to: Greg Smith (#3)
Re: Memory context usage

On Fri, Aug 28, 2009 at 5:18 AM, Greg Smith<gsmith@gregsmith.com> wrote:

On Fri, 28 Aug 2009, Tom Lane wrote:

MemoryContextStats() might help.  It just dumps the info to stderr
though.

Which means it ends up in the database log files in the common configuration
where where the database's stderr is redirected to there. I even script
running this regularly against stuff I'm suspicious of, using something like
this passed the PID of the process I want to watch:

#!/bin/bash
gdb -p $1 <<EOF
p MemoryContextStats(TopMemoryContext)
detach
quit
EOF

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

Is there another way to get it in the source code?
I need to control the size of a memory context on the fly and take
some actions when
the used memory exceeds a defined size.

Thanks

Adriano

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Adriano Lange (#4)
Re: Memory context usage

Adriano Lange <alange0001@gmail.com> writes:

I need to control the size of a memory context on the fly and take
some actions when
the used memory exceeds a defined size.

The existing places that do that sort of thing do their own counting
of how much they've allocated.

regards, tom lane

#6Adriano Lange
alange0001@gmail.com
In reply to: Tom Lane (#5)
Re: Memory context usage

Tom Lane escreveu:

Adriano Lange <alange0001@gmail.com> writes:

I need to control the size of a memory context on the fly and take
some actions when
the used memory exceeds a defined size.

The existing places that do that sort of thing do their own counting
of how much they've allocated.

I have seen that the AllocSet structure is hid by MemoryContext which
has only a stderr output interface for its stats. I would need these
stats internally but maybe this is only my demand for now.

Thanks for attention.

Adriano