mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-46072: Add some object layout and allocation stats (GH-31051)
This commit is contained in:
parent
913e340a32
commit
48be46ec1f
5 changed files with 51 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_pymem.h" // _PyTraceMalloc_Config
|
||||
#include "pycore_code.h" // stats
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // malloc()
|
||||
|
@ -695,6 +696,7 @@ PyObject_Malloc(size_t size)
|
|||
/* see PyMem_RawMalloc() */
|
||||
if (size > (size_t)PY_SSIZE_T_MAX)
|
||||
return NULL;
|
||||
OBJECT_STAT_INC(allocations);
|
||||
return _PyObject.malloc(_PyObject.ctx, size);
|
||||
}
|
||||
|
||||
|
@ -704,6 +706,7 @@ PyObject_Calloc(size_t nelem, size_t elsize)
|
|||
/* see PyMem_RawMalloc() */
|
||||
if (elsize != 0 && nelem > (size_t)PY_SSIZE_T_MAX / elsize)
|
||||
return NULL;
|
||||
OBJECT_STAT_INC(allocations);
|
||||
return _PyObject.calloc(_PyObject.ctx, nelem, elsize);
|
||||
}
|
||||
|
||||
|
@ -719,6 +722,7 @@ PyObject_Realloc(void *ptr, size_t new_size)
|
|||
void
|
||||
PyObject_Free(void *ptr)
|
||||
{
|
||||
OBJECT_STAT_INC(frees);
|
||||
_PyObject.free(_PyObject.ctx, ptr);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue