mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-40630: Add tracemalloc.reset_peak (GH-20102)
The reset_peak function sets the peak memory size to the current size, representing a resetting of that metric. This allows for recording the peak of specific sections of code, ignoring other code that may have had a higher peak (since the most recent `tracemalloc.start()` or tracemalloc.clear_traces()` call).
This commit is contained in:
parent
bfaf5275ad
commit
8b62644831
7 changed files with 138 additions and 1 deletions
|
@ -1643,6 +1643,30 @@ _tracemalloc_get_traced_memory_impl(PyObject *module)
|
|||
return Py_BuildValue("nn", size, peak_size);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_tracemalloc.reset_peak
|
||||
|
||||
Set the peak size of memory blocks traced by tracemalloc to the current size.
|
||||
|
||||
Do nothing if the tracemalloc module is not tracing memory allocations.
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_tracemalloc_reset_peak_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=140c2870f691dbb2 input=18afd0635066e9ce]*/
|
||||
{
|
||||
if (!_Py_tracemalloc_config.tracing) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
TABLES_LOCK();
|
||||
tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
|
||||
TABLES_UNLOCK();
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
_TRACEMALLOC_IS_TRACING_METHODDEF
|
||||
|
@ -1654,6 +1678,7 @@ static PyMethodDef module_methods[] = {
|
|||
_TRACEMALLOC_GET_TRACEBACK_LIMIT_METHODDEF
|
||||
_TRACEMALLOC_GET_TRACEMALLOC_MEMORY_METHODDEF
|
||||
_TRACEMALLOC_GET_TRACED_MEMORY_METHODDEF
|
||||
_TRACEMALLOC_RESET_PEAK_METHODDEF
|
||||
/* sentinel */
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue