New submission from Dave Malcolm <[email protected]>:
I'm attaching a patch which generalizes the at-exit PYTHONMALLOCSTATS memory
usage report, so that it's available in a regular build and can be triggered
from Python, by calling:
sys._debugmallocstats()
This can be useful when debugging memory usage issues: a script can call the
debug hook before and after certain activities, and the before/after amounts
can be compared.
The patch moves this arena-accouting code when a new arena is allocated:
++ntimes_arena_allocated;
if (narenas_currently_allocated > narenas_highwater)
narenas_highwater = narenas_currently_allocated;
from out of the #ifdef PYMALLOC_DEBUG guard and into all PYMALLOC
configurations, so that this data is available within the dump. Given how much
activity happens when a new arena is allocated, I believe this doesn't impact
performance.
It changes _PyObject_DebugMallocStats() to take an arbitrary FILE*, rather than
assuming stderr (which was handy for my original use-case of debugging a web
server). This function is already marked with PyAPI_FUNC() but not documented
(albeit only present in a debug build).
Tested with --with-pymalloc, --without-pymalloc, and --with-pydebug
FWIW, Red Hat has been using a version of this patch in RHEL 5 as of RHEL 5.6
(http://rhn.redhat.com/errata/RHSA-2011-0027.html), and also in Fedora since
September 2011 with python-2.7.2-15 and python3-3.2.2-6 (for the forthcoming
Fedora 17).
----------
files: add-debug-malloc-stats.patch
keywords: needs review, patch
messages: 160459
nosy: dmalcolm
priority: normal
severity: normal
stage: patch review
status: open
title: Add sys._debugmallocstats()
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file25545/add-debug-malloc-stats.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14785>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com