This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dmalcolm
Recipients dmalcolm
Date 2012-05-11.22:40:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1336776030.63.0.471450530302.issue14785@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2012-05-11 22:40:31dmalcolmsetrecipients: + dmalcolm
2012-05-11 22:40:30dmalcolmsetmessageid: <1336776030.63.0.471450530302.issue14785@psf.upfronthosting.co.za>
2012-05-11 22:40:30dmalcolmlinkissue14785 messages
2012-05-11 22:40:29dmalcolmcreate