summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-04-13 08:29:14 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-04-13 08:29:14 (GMT)
commit0e871188e8cd9a4e41be7c734e250bfce2d92d56 (patch)
treec7ef141919fceb1f741a27825ceafb093c546021
parentb7ba7433126bff12dd638f11f831fa7bfd0bbf4a (diff)
downloadcpython-0e871188e8cd9a4e41be7c734e250bfce2d92d56.zip
cpython-0e871188e8cd9a4e41be7c734e250bfce2d92d56.tar.gz
cpython-0e871188e8cd9a4e41be7c734e250bfce2d92d56.tar.bz2
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Added code to call this when PYMALLOC_DEBUG is enabled, and envar PYTHONMALLOCSTATS is set, whenever a new arena is obtained and once late in the Python shutdown process.
-rw-r--r--Include/objimpl.h2
-rw-r--r--Objects/obmalloc.c12
-rw-r--r--Python/pythonrun.c5
3 files changed, 14 insertions, 5 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h
index ed7042f..3f72d67 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -97,7 +97,7 @@ DL_IMPORT(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
DL_IMPORT(void) _PyObject_DebugFree(void *p);
DL_IMPORT(void) _PyObject_DebugDumpAddress(const void *p);
DL_IMPORT(void) _PyObject_DebugCheckAddress(const void *p);
-DL_IMPORT(void) _PyObject_DebugDumpStats(void);
+DL_IMPORT(void) _PyObject_DebugMallocStats(void);
#define PyObject_MALLOC _PyObject_DebugMalloc
#define PyObject_Malloc _PyObject_DebugMalloc
#define PyObject_REALLOC _PyObject_DebugRealloc
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 1371141..aef6b9f 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -448,6 +448,11 @@ new_arena(void)
if (bp == NULL)
return NULL;
+#ifdef PYMALLOC_DEBUG
+ if (Py_GETENV("PYTHONMALLOCSTATS"))
+ _PyObject_DebugMallocStats();
+#endif
+
/* arenabase <- first pool-aligned address in the arena
nfreepools <- number of whole pools that fit after alignment */
arenabase = bp;
@@ -1216,7 +1221,7 @@ printone(const char* msg, ulong value)
/* Print summary info to stderr about the state of pymalloc's structures. */
void
-_PyObject_DebugDumpStats(void)
+_PyObject_DebugMallocStats(void)
{
uint i;
const uint numclasses = SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT;
@@ -1245,8 +1250,6 @@ _PyObject_DebugDumpStats(void)
fprintf(stderr, "Small block threshold = %d, in %u size classes.\n",
SMALL_REQUEST_THRESHOLD, numclasses);
- fprintf(stderr, "pymalloc malloc+realloc called %lu times.\n",
- serialno);
for (i = 0; i < numclasses; ++i)
numpools[i] = numblocks[i] = numfreeblocks[i] = 0;
@@ -1312,6 +1315,7 @@ _PyObject_DebugDumpStats(void)
quantization += p * ((POOL_SIZE - POOL_OVERHEAD) % size);
}
fputc('\n', stderr);
+ (void)printone("# times object malloc called", serialno);
PyOS_snprintf(buf, sizeof(buf),
"%u arenas * %d bytes/arena", narenas, ARENA_SIZE);
@@ -1320,12 +1324,12 @@ _PyObject_DebugDumpStats(void)
fputc('\n', stderr);
total = printone("# bytes in allocated blocks", allocated_bytes);
+ total += printone("# bytes in available blocks", available_bytes);
PyOS_snprintf(buf, sizeof(buf),
"%u unused pools * %d bytes", numfreepools, POOL_SIZE);
total += printone(buf, (ulong)numfreepools * POOL_SIZE);
- total += printone("# bytes in available blocks", available_bytes);
total += printone("# bytes lost to pool headers", pool_header_bytes);
total += printone("# bytes lost to quantization", quantization);
total += printone("# bytes lost to arena alignment", arena_alignment);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f0727d3..0ca1f42 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -276,6 +276,11 @@ Py_Finalize(void)
PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
+#ifdef PYMALLOC_DEBUG
+ if (Py_GETENV("PYTHONMALLOCSTATS"))
+ _PyObject_DebugMallocStats();
+#endif
+
call_ll_exitfuncs();
#ifdef Py_TRACE_REFS