Skip to content

Commit

Permalink
Refactor memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Dec 29, 2024
1 parent bd35c77 commit acb206e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/test_memoryleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

"""Glances unitary tests suite for Glances memory leak."""

import time
import tracemalloc


Expand All @@ -19,18 +20,20 @@ def test_memoryleak(glances_stats_no_history, logger):
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
iteration = 10
for _ in range(iteration):
glances_stats_no_history.update()
time.sleep(1)

# 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()
time.sleep(1)
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
logger.info('Memory consume per iteration: {memory_leak} bytes')
logger.info(f'Memory consume per iteration: {memory_leak} bytes')
assert memory_leak < 1000, f'Memory leak: {memory_leak} bytes'

0 comments on commit acb206e

Please sign in to comment.