Skip to content

Commit

Permalink
Update the test criteria for test_read_random_region_cpu_memleak
Browse files Browse the repository at this point in the history
Signed-off-by: Gigon Bae <gbae@nvidia.com>
  • Loading branch information
gigony committed Apr 18, 2024
1 parent 3e67c2f commit 10d5bf7
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_read_region_cpu_memleak(testimg_tiff_stripe_4096x4096_256):


def test_read_random_region_cpu_memleak(testimg_tiff_stripe_4096x4096_256):
import gc
import os
import random

Expand All @@ -81,23 +82,39 @@ def test_read_random_region_cpu_memleak(testimg_tiff_stripe_4096x4096_256):

img = open_image_cucim(testimg_tiff_stripe_4096x4096_256)

iteration = 1000
iteration = 10000
mem_usage_history = [process.memory_info().rss] * iteration
level_count = img.resolutions["level_count"]

memory_increment_count = 0

for i in range(iteration):
location = (
random.randrange(-2048, 4096 + 2048),
random.randrange(-2048, 4096 + 2048),
)
level = random.randrange(0, level_count)
_ = img.read_region(location, (256, 256), level)
if i == 0 or i == iteration - 1:
gc.collect()
mem_usage_history[i] = process.memory_info().rss
if i > 0:
if mem_usage_history[i] - mem_usage_history[i - 1] > 0:
memory_increment_count += 1
print(
f"mem increase (iteration: {i:3d}): "
f"{mem_usage_history[i] - mem_usage_history[i - 1]:4d} "
"bytes"
)

print(mem_usage_history)

# Memory usage difference should be smaller than (iteration) * 100 bytes
assert mem_usage_history[-1] - mem_usage_history[1] < iteration * 100
# The expected memory usage difference should be smaller than
# <iteration> * 256 * 3 bytes
# (one line of pixels in the tile image is 256 * 3 bytes)
assert mem_usage_history[-1] - mem_usage_history[1] < iteration * 256 * 3
# The memory usage increment should be less than 1% of the iteration count.
assert memory_increment_count < iteration * 0.01


def test_tiff_iterator(testimg_tiff_stripe_4096x4096_256):
Expand Down

0 comments on commit 10d5bf7

Please sign in to comment.