Commit 3c0481d4 authored by Victor Stinner's avatar Victor Stinner

Close #19798: replace "maximum" term with "peak" in get_traced_memory()

documentation. Use also the term "current" for the current size.
parent cced0762
...@@ -276,8 +276,8 @@ Functions ...@@ -276,8 +276,8 @@ Functions
.. function:: get_traced_memory() .. function:: get_traced_memory()
Get the current size and maximum size of memory blocks traced by the Get the current size and peak size of memory blocks traced by the
:mod:`tracemalloc` module as a tuple: ``(size: int, max_size: int)``. :mod:`tracemalloc` module as a tuple: ``(current: int, peak: int)``.
.. function:: get_tracemalloc_memory() .. function:: get_tracemalloc_memory()
......
...@@ -182,19 +182,19 @@ class TestTracemallocEnabled(unittest.TestCase): ...@@ -182,19 +182,19 @@ class TestTracemallocEnabled(unittest.TestCase):
obj_size = 1024 * 1024 obj_size = 1024 * 1024
tracemalloc.clear_traces() tracemalloc.clear_traces()
obj, obj_traceback = allocate_bytes(obj_size) obj, obj_traceback = allocate_bytes(obj_size)
size, max_size = tracemalloc.get_traced_memory() size, peak_size = tracemalloc.get_traced_memory()
self.assertGreaterEqual(size, obj_size) self.assertGreaterEqual(size, obj_size)
self.assertGreaterEqual(max_size, size) self.assertGreaterEqual(peak_size, size)
self.assertLessEqual(size - obj_size, max_error) self.assertLessEqual(size - obj_size, max_error)
self.assertLessEqual(max_size - size, max_error) self.assertLessEqual(peak_size - size, max_error)
# destroy the object # destroy the object
obj = None obj = None
size2, max_size2 = tracemalloc.get_traced_memory() size2, peak_size2 = tracemalloc.get_traced_memory()
self.assertLess(size2, size) self.assertLess(size2, size)
self.assertGreaterEqual(size - size2, obj_size - max_error) self.assertGreaterEqual(size - size2, obj_size - max_error)
self.assertGreaterEqual(max_size2, max_size) self.assertGreaterEqual(peak_size2, peak_size)
# clear_traces() must reset traced memory counters # clear_traces() must reset traced memory counters
tracemalloc.clear_traces() tracemalloc.clear_traces()
...@@ -202,8 +202,8 @@ class TestTracemallocEnabled(unittest.TestCase): ...@@ -202,8 +202,8 @@ class TestTracemallocEnabled(unittest.TestCase):
# allocate another object # allocate another object
obj, obj_traceback = allocate_bytes(obj_size) obj, obj_traceback = allocate_bytes(obj_size)
size, max_size = tracemalloc.get_traced_memory() size, peak_size = tracemalloc.get_traced_memory()
self.assertGreater(size, 0) self.assertGreaterEqual(size, obj_size)
# stop() also resets traced memory counters # stop() also resets traced memory counters
tracemalloc.stop() tracemalloc.stop()
......
...@@ -106,9 +106,9 @@ typedef struct { ...@@ -106,9 +106,9 @@ typedef struct {
Protected by TABLES_LOCK(). */ Protected by TABLES_LOCK(). */
static size_t tracemalloc_traced_memory = 0; static size_t tracemalloc_traced_memory = 0;
/* Maximum size in bytes of traced memory. /* Peak size in bytes of traced memory.
Protected by TABLES_LOCK(). */ Protected by TABLES_LOCK(). */
static size_t tracemalloc_max_traced_memory = 0; static size_t tracemalloc_peak_traced_memory = 0;
/* Hash table used as a set to to intern filenames: /* Hash table used as a set to to intern filenames:
PyObject* => PyObject*. PyObject* => PyObject*.
...@@ -464,8 +464,8 @@ tracemalloc_log_alloc(void *ptr, size_t size) ...@@ -464,8 +464,8 @@ tracemalloc_log_alloc(void *ptr, size_t size)
if (res == 0) { if (res == 0) {
assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size); assert(tracemalloc_traced_memory <= PY_SIZE_MAX - size);
tracemalloc_traced_memory += size; tracemalloc_traced_memory += size;
if (tracemalloc_traced_memory > tracemalloc_max_traced_memory) if (tracemalloc_traced_memory > tracemalloc_peak_traced_memory)
tracemalloc_max_traced_memory = tracemalloc_traced_memory; tracemalloc_peak_traced_memory = tracemalloc_traced_memory;
} }
TABLES_UNLOCK(); TABLES_UNLOCK();
...@@ -674,7 +674,7 @@ tracemalloc_clear_traces(void) ...@@ -674,7 +674,7 @@ tracemalloc_clear_traces(void)
TABLES_LOCK(); TABLES_LOCK();
_Py_hashtable_clear(tracemalloc_traces); _Py_hashtable_clear(tracemalloc_traces);
tracemalloc_traced_memory = 0; tracemalloc_traced_memory = 0;
tracemalloc_max_traced_memory = 0; tracemalloc_peak_traced_memory = 0;
TABLES_UNLOCK(); TABLES_UNLOCK();
_Py_hashtable_foreach(tracemalloc_tracebacks, traceback_free_traceback, NULL); _Py_hashtable_foreach(tracemalloc_tracebacks, traceback_free_traceback, NULL);
...@@ -1266,26 +1266,26 @@ tracemalloc_get_tracemalloc_memory(PyObject *self) ...@@ -1266,26 +1266,26 @@ tracemalloc_get_tracemalloc_memory(PyObject *self)
PyDoc_STRVAR(tracemalloc_get_traced_memory_doc, PyDoc_STRVAR(tracemalloc_get_traced_memory_doc,
"get_traced_memory() -> (int, int)\n" "get_traced_memory() -> (int, int)\n"
"\n" "\n"
"Get the current size and maximum size of memory blocks traced\n" "Get the current size and peak size of memory blocks traced\n"
"by the tracemalloc module as a tuple: (size: int, max_size: int)."); "by the tracemalloc module as a tuple: (current: int, peak: int).");
static PyObject* static PyObject*
tracemalloc_get_traced_memory(PyObject *self) tracemalloc_get_traced_memory(PyObject *self)
{ {
Py_ssize_t size, max_size; Py_ssize_t size, peak_size;
PyObject *size_obj, *max_size_obj; PyObject *size_obj, *peak_size_obj;
if (!tracemalloc_config.tracing) if (!tracemalloc_config.tracing)
return Py_BuildValue("ii", 0, 0); return Py_BuildValue("ii", 0, 0);
TABLES_LOCK(); TABLES_LOCK();
size = tracemalloc_traced_memory; size = tracemalloc_traced_memory;
max_size = tracemalloc_max_traced_memory; peak_size = tracemalloc_peak_traced_memory;
TABLES_UNLOCK(); TABLES_UNLOCK();
size_obj = PyLong_FromSize_t(size); size_obj = PyLong_FromSize_t(size);
max_size_obj = PyLong_FromSize_t(max_size); peak_size_obj = PyLong_FromSize_t(peak_size);
return Py_BuildValue("NN", size_obj, max_size_obj); return Py_BuildValue("NN", size_obj, peak_size_obj);
} }
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment