Skip to content

Commit 0bb3261

Browse files
committed
requested changes
1 parent cfdaaee commit 0bb3261

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

Doc/library/tracemalloc.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ Functions
331331
:mod:`tracemalloc` module as a tuple: ``(current: int, peak: int)``.
332332

333333

334-
.. function:: get_traced_refs()
334+
.. function:: get_traced_allocs()
335335

336-
Get the current count of created and destroyed memory blocks.
337-
:mod:`tracemalloc` module as a tuple: ``(created: int, destroyed: int)``.
336+
Get the current unit counts of allocated and deallocated memory blocks.
337+
:mod:`tracemalloc` module as a tuple: ``(allocs: int, deallocs: int)``.
338338

339339

340340
.. function:: reset_peak()

Include/internal/pycore_tracemalloc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ struct _tracemalloc_runtime_state {
9494
/* domain (unsigned int) => traces (_Py_hashtable_t).
9595
Protected by TABLES_LOCK(). */
9696
_Py_hashtable_t *domains;
97-
/* Number of references created.
97+
/* Number of allocations.
9898
Protected by TABLES_LOCK(). */
99-
size_t refs_created;
100-
/* Number of references destroyed.
99+
Py_ssize_t allocations;
100+
/* Number of deallocations.
101101
Protected by TABLES_LOCK() and sometimes modified atomically. */
102-
size_t refs_destroyed;
102+
Py_ssize_t deallocations;
103103

104104
struct tracemalloc_traceback empty_traceback;
105105

@@ -162,7 +162,7 @@ extern size_t _PyTraceMalloc_GetMemory(void);
162162
extern PyObject* _PyTraceMalloc_GetTracedMemory(void);
163163

164164
/* Get the current number of references created and destroyed as a 2-tuple */
165-
extern PyObject* _PyTraceMalloc_GetTracedRefs(void);
165+
extern PyObject* _PyTraceMalloc_GetTracedAllocs(void);
166166

167167
/* Set the peak size of traced memory blocks to the current size */
168168
extern void _PyTraceMalloc_ResetPeak(void);

Lib/test/test_tracemalloc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,15 +1156,15 @@ def g():
11561156
try:
11571157
tracemalloc.clear_traces()
11581158
f()
1159-
refs = tracemalloc.get_traced_refs()
1159+
refs = tracemalloc.get_traced_allocs()
11601160
if refs == (1, 0):
11611161
warnings.warn("ceval Py_DECREF doesn't emit PyRefTracer_DESTROY in this build")
11621162
else:
11631163
self.assertEqual(refs, (1, 1))
11641164

11651165
tracemalloc.clear_traces()
11661166
g()
1167-
refs = tracemalloc.get_traced_refs()
1167+
refs = tracemalloc.get_traced_allocs()
11681168
if refs == (3, 2):
11691169
warnings.warn("ceval Py_DECREF doesn't emit PyRefTracer_DESTROY in this build")
11701170
else:

Modules/_tracemalloc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ _tracemalloc_get_traced_memory_impl(PyObject *module)
169169

170170

171171
/*[clinic input]
172-
_tracemalloc.get_traced_refs
172+
_tracemalloc.get_traced_allocs
173173
174174
Get the current count of created and destroyed refs.
175175
176176
Returns a tuple: (created: int, destroyed: int).
177177
[clinic start generated code]*/
178178

179179
static PyObject *
180-
_tracemalloc_get_traced_refs_impl(PyObject *module)
181-
/*[clinic end generated code: output=81d36fdeb3ffc362 input=d0652f2592733b0e]*/
180+
_tracemalloc_get_traced_allocs_impl(PyObject *module)
181+
/*[clinic end generated code: output=cb84cbd781fab85f input=336f38d37a5830ef]*/
182182
{
183-
return _PyTraceMalloc_GetTracedRefs();
183+
return _PyTraceMalloc_GetTracedAllocs();
184184
}
185185

186186

@@ -212,7 +212,7 @@ static PyMethodDef module_methods[] = {
212212
_TRACEMALLOC_GET_TRACEBACK_LIMIT_METHODDEF
213213
_TRACEMALLOC_GET_TRACEMALLOC_MEMORY_METHODDEF
214214
_TRACEMALLOC_GET_TRACED_MEMORY_METHODDEF
215-
_TRACEMALLOC_GET_TRACED_REFS_METHODDEF
215+
_TRACEMALLOC_GET_TRACED_ALLOCS_METHODDEF
216216
_TRACEMALLOC_RESET_PEAK_METHODDEF
217217
/* sentinel */
218218
{NULL, NULL}

Modules/clinic/_tracemalloc.c.h

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/tracemalloc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ typedef struct {
7676
#define tracemalloc_tracebacks _PyRuntime.tracemalloc.tracebacks
7777
#define tracemalloc_traces _PyRuntime.tracemalloc.traces
7878
#define tracemalloc_domains _PyRuntime.tracemalloc.domains
79-
#define tracemalloc_refs_created _PyRuntime.tracemalloc.refs_created
80-
#define tracemalloc_refs_destroyed _PyRuntime.tracemalloc.refs_destroyed
79+
#define tracemalloc_allocations _PyRuntime.tracemalloc.allocations
80+
#define tracemalloc_deallocations _PyRuntime.tracemalloc.deallocations
8181

8282

8383
#ifdef TRACE_DEBUG
@@ -1261,8 +1261,8 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
12611261
{
12621262
if (event != PyRefTracer_CREATE) {
12631263
/* we don't want bother here with the lock for performance reasons */
1264-
if (_Py_atomic_load_int32_relaxed(&tracemalloc_config.tracing)) {
1265-
_Py_atomic_add_ssize((Py_ssize_t *)&tracemalloc_refs_destroyed, 1);
1264+
if (_Py_atomic_load_int_relaxed(&tracemalloc_config.tracing)) {
1265+
_Py_atomic_add_ssize(&tracemalloc_deallocations, 1);
12661266
}
12671267
return 0;
12681268
}
@@ -1277,7 +1277,7 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
12771277
goto done;
12781278
}
12791279

1280-
tracemalloc_refs_created += 1;
1280+
tracemalloc_allocations += 1;
12811281

12821282
PyTypeObject *type = Py_TYPE(op);
12831283
const size_t presize = _PyType_PreHeaderSize(type);
@@ -1334,8 +1334,8 @@ _PyTraceMalloc_ClearTraces(void)
13341334
TABLES_LOCK();
13351335
if (tracemalloc_config.tracing) {
13361336
tracemalloc_clear_traces_unlocked();
1337-
tracemalloc_refs_created = 0;
1338-
tracemalloc_refs_destroyed = 0;
1337+
tracemalloc_allocations = 0;
1338+
tracemalloc_deallocations = 0;
13391339
}
13401340
TABLES_UNLOCK();
13411341
}
@@ -1476,21 +1476,21 @@ _PyTraceMalloc_GetTracedMemory(void)
14761476

14771477

14781478
PyObject *
1479-
_PyTraceMalloc_GetTracedRefs(void)
1479+
_PyTraceMalloc_GetTracedAllocs(void)
14801480
{
14811481
TABLES_LOCK();
1482-
Py_ssize_t created, destroyed;
1482+
Py_ssize_t allocations, deallocations;
14831483
if (tracemalloc_config.tracing) {
1484-
created = tracemalloc_refs_created;
1485-
destroyed = tracemalloc_refs_destroyed;
1484+
allocations = tracemalloc_allocations;
1485+
deallocations = tracemalloc_deallocations;
14861486
}
14871487
else {
1488-
created = 0;
1489-
destroyed = 0;
1488+
allocations = 0;
1489+
deallocations = 0;
14901490
}
14911491
TABLES_UNLOCK();
14921492

1493-
return Py_BuildValue("nn", created, destroyed);
1493+
return Py_BuildValue("nn", allocations, deallocations);
14941494
}
14951495

14961496
void

0 commit comments

Comments
 (0)