Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e87118

Browse files
committed
_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.
1 parent b7ba743 commit 0e87118

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

Include/objimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ DL_IMPORT(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
9797
DL_IMPORT(void) _PyObject_DebugFree(void *p);
9898
DL_IMPORT(void) _PyObject_DebugDumpAddress(const void *p);
9999
DL_IMPORT(void) _PyObject_DebugCheckAddress(const void *p);
100-
DL_IMPORT(void) _PyObject_DebugDumpStats(void);
100+
DL_IMPORT(void) _PyObject_DebugMallocStats(void);
101101
#define PyObject_MALLOC _PyObject_DebugMalloc
102102
#define PyObject_Malloc _PyObject_DebugMalloc
103103
#define PyObject_REALLOC _PyObject_DebugRealloc

Objects/obmalloc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ new_arena(void)
448448
if (bp == NULL)
449449
return NULL;
450450

451+
#ifdef PYMALLOC_DEBUG
452+
if (Py_GETENV("PYTHONMALLOCSTATS"))
453+
_PyObject_DebugMallocStats();
454+
#endif
455+
451456
/* arenabase <- first pool-aligned address in the arena
452457
nfreepools <- number of whole pools that fit after alignment */
453458
arenabase = bp;
@@ -1216,7 +1221,7 @@ printone(const char* msg, ulong value)
12161221

12171222
/* Print summary info to stderr about the state of pymalloc's structures. */
12181223
void
1219-
_PyObject_DebugDumpStats(void)
1224+
_PyObject_DebugMallocStats(void)
12201225
{
12211226
uint i;
12221227
const uint numclasses = SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT;
@@ -1245,8 +1250,6 @@ _PyObject_DebugDumpStats(void)
12451250

12461251
fprintf(stderr, "Small block threshold = %d, in %u size classes.\n",
12471252
SMALL_REQUEST_THRESHOLD, numclasses);
1248-
fprintf(stderr, "pymalloc malloc+realloc called %lu times.\n",
1249-
serialno);
12501253

12511254
for (i = 0; i < numclasses; ++i)
12521255
numpools[i] = numblocks[i] = numfreeblocks[i] = 0;
@@ -1312,6 +1315,7 @@ _PyObject_DebugDumpStats(void)
13121315
quantization += p * ((POOL_SIZE - POOL_OVERHEAD) % size);
13131316
}
13141317
fputc('\n', stderr);
1318+
(void)printone("# times object malloc called", serialno);
13151319

13161320
PyOS_snprintf(buf, sizeof(buf),
13171321
"%u arenas * %d bytes/arena", narenas, ARENA_SIZE);
@@ -1320,12 +1324,12 @@ _PyObject_DebugDumpStats(void)
13201324
fputc('\n', stderr);
13211325

13221326
total = printone("# bytes in allocated blocks", allocated_bytes);
1327+
total += printone("# bytes in available blocks", available_bytes);
13231328

13241329
PyOS_snprintf(buf, sizeof(buf),
13251330
"%u unused pools * %d bytes", numfreepools, POOL_SIZE);
13261331
total += printone(buf, (ulong)numfreepools * POOL_SIZE);
13271332

1328-
total += printone("# bytes in available blocks", available_bytes);
13291333
total += printone("# bytes lost to pool headers", pool_header_bytes);
13301334
total += printone("# bytes lost to quantization", quantization);
13311335
total += printone("# bytes lost to arena alignment", arena_alignment);

Python/pythonrun.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ Py_Finalize(void)
276276

277277
PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
278278

279+
#ifdef PYMALLOC_DEBUG
280+
if (Py_GETENV("PYTHONMALLOCSTATS"))
281+
_PyObject_DebugMallocStats();
282+
#endif
283+
279284
call_ll_exitfuncs();
280285

281286
#ifdef Py_TRACE_REFS

0 commit comments

Comments
 (0)