-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Glances - An eye on your system | ||
# | ||
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <[email protected]> | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0-only | ||
# | ||
|
||
"""Glances unitary tests suite for Glances memory leak.""" | ||
|
||
import tracemalloc | ||
|
||
|
||
def test_memoryleak(glances_stats_no_history, logger): | ||
""" | ||
Test Glances memory leak. | ||
""" | ||
tracemalloc.start() | ||
# First iterations just to init the stats and fill the memory | ||
logger.info('Please wait test is filling memory with stats') | ||
iteration = 100 | ||
for _ in range(iteration): | ||
glances_stats_no_history.update() | ||
|
||
# Then iteration to measure memory leak | ||
logger.info('Please wait test if a memory leak is detected') | ||
iteration = 20 | ||
snapshot_begin = tracemalloc.take_snapshot() | ||
for _ in range(iteration): | ||
glances_stats_no_history.update() | ||
snapshot_end = tracemalloc.take_snapshot() | ||
snapshot_diff = snapshot_end.compare_to(snapshot_begin, 'filename') | ||
memory_leak = sum([s.size_diff for s in snapshot_diff]) // iteration | ||
assert memory_leak < 1000, f'Memory leak: {memory_leak} bytes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters