@@ -2299,80 +2299,6 @@ Example code:
22992299 'status': 'stopped',
23002300 'username': 'NT AUTHORITY\\LocalService'}
23012301
2302- Testing utilities
2303- =================
2304-
2305- The ``psutil.test `` subpackage includes a helper class to assist in writing
2306- memory-leak detection tests.
2307-
2308- .. class :: psutil.test.MemoryLeakTestCase
2309-
2310- A testing framework for detecting memory leaks in functions, typically those
2311- implemented in C that forget to ``free() `` heap memory, call ``Py_DECREF `` on
2312- Python objects, and so on. It works by comparing the process's memory usage
2313- before and after repeatedly calling the target function.
2314-
2315- Detecting memory leaks reliably is inherently difficult (and probably
2316- impossible) because of how the OS manages memory, garbage collection, and
2317- caching. Memory usage may even decrease between runs. So this is not meant to
2318- be bullet proof. To reduce false positives, when an increase in memory is
2319- detected (mem > 0), the test is retried up to 5 times, increasing the
2320- number of function calls each time. If memory continues to grow, the test is
2321- considered a failure.
2322- The test currently monitors RSS, VMS, and `USS <https://gmpy.dev/blog/2016/real-process-memory-and-environ-in-python >`__ memory.
2323- On supported platforms, it also monitors **heap metrics ** (``heap_used ``, ``mmap_used `` from
2324- :func: `heap_info `).
2325-
2326- In addition it also ensures that the target function does not leak
2327- file descriptors (UNIX) or handles (Windows).
2328-
2329- .. versionadded :: 7.2.0
2330-
2331- .. warning ::
2332- This class is experimental, meaning its API or internal algorithm may
2333- change in the future.
2334-
2335- Usage example::
2336-
2337- from psutil.test import MemoryLeakTestCase
2338-
2339- class TestLeaks(MemoryLeakTestCase):
2340- def test_fun(self):
2341- self.execute(some_function)
2342-
2343- Class attributes and methods:
2344-
2345- .. attribute :: times
2346- :value: 200
2347-
2348- Number of times to call the tested function in each iteration.
2349-
2350- .. attribute :: retries
2351- :value: 5
2352-
2353- Maximum number of retries if memory growth is detected.
2354-
2355- .. attribute :: warmup_times
2356- :value: 10
2357-
2358- Number of warm-up calls before measurements begin.
2359-
2360- .. attribute :: tolerance
2361- :value: 0
2362-
2363- Allowed memory difference (in bytes) before considering it a leak.
2364-
2365- .. attribute :: verbosity
2366- :value: 1
2367-
2368- 0 = no messages; 1 = print diagnostics when memory increases during the
2369- test run.
2370-
2371- .. method :: execute(fun, *, times=None, warmup_times=None, retries=None, tolerance=None)
2372-
2373- Run a full leak test on a callable. If specified, the optional arguments
2374- override the class attributes with the same name.
2375-
23762302Constants
23772303=========
23782304
0 commit comments