mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Improve object stats (#92845)
* Add incref/decref stats * Show ratios for allocation in summary
This commit is contained in:
parent
f6fd8aac13
commit
fa2b8b75eb
10 changed files with 106 additions and 55 deletions
|
|
@ -51,6 +51,8 @@ A standard interface exists for objects that contain an array of items
|
|||
whose size is determined when the object is allocated.
|
||||
*/
|
||||
|
||||
#include "pystats.h"
|
||||
|
||||
/* Py_DEBUG implies Py_REF_DEBUG. */
|
||||
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
|
||||
# define Py_REF_DEBUG
|
||||
|
|
@ -490,6 +492,7 @@ PyAPI_FUNC(void) _Py_DecRef(PyObject *);
|
|||
|
||||
static inline void Py_INCREF(PyObject *op)
|
||||
{
|
||||
_Py_INCREF_STAT_INC();
|
||||
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
|
||||
// Stable ABI for Python 3.10 built in debug mode.
|
||||
_Py_IncRef(op);
|
||||
|
|
@ -506,7 +509,6 @@ static inline void Py_INCREF(PyObject *op)
|
|||
# define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
|
||||
// Stable ABI for limited C API version 3.10 of Python debug build
|
||||
static inline void Py_DECREF(PyObject *op) {
|
||||
|
|
@ -517,6 +519,7 @@ static inline void Py_DECREF(PyObject *op) {
|
|||
#elif defined(Py_REF_DEBUG)
|
||||
static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
|
||||
{
|
||||
_Py_DECREF_STAT_INC();
|
||||
_Py_RefTotal--;
|
||||
if (--op->ob_refcnt != 0) {
|
||||
if (op->ob_refcnt < 0) {
|
||||
|
|
@ -532,6 +535,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
|
|||
#else
|
||||
static inline void Py_DECREF(PyObject *op)
|
||||
{
|
||||
_Py_DECREF_STAT_INC();
|
||||
// Non-limited C API and limited C API for Python 3.9 and older access
|
||||
// directly PyObject.ob_refcnt.
|
||||
if (--op->ob_refcnt == 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue