Last active
April 20, 2019 22:29
-
-
Save aflc/40bbef1542274df68f04d165402b25f4 to your computer and use it in GitHub Desktop.
Linux+glibcで何故かメモリ消費が増える現象(Linux+glib)
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
import copy | |
import os | |
import random | |
import subprocess | |
import tracemalloc | |
pid = os.getpid() | |
buffer = b"0" * 100000000 | |
def get_large_object(n): | |
s = random.randint(0, 10000) | |
e = random.randint(1000000, 30000000) | |
b = copy.deepcopy(buffer[s:e]) | |
return b | |
def get_rss(): | |
result = subprocess.run(["ps", "-p", str(pid), "-o", "rss="], stdout=subprocess.PIPE) | |
return result.stdout.decode("utf-8").strip() | |
tracemalloc.start() | |
print("start", "rss:", get_rss(), "malloc(current, peak):", tracemalloc.get_traced_memory()) | |
for i in range(10): | |
for j in range(100): | |
b = get_large_object(j) | |
print(i, "rss:", get_rss(), "malloc(current, peak):", tracemalloc.get_traced_memory()) | |
while True: | |
print("finish", "rss:", get_rss(), "malloc(current, peak):", tracemalloc.get_traced_memory()) | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment