Skip to content

Instantly share code, notes, and snippets.

@brunokim
Created June 9, 2022 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunokim/482bfb459306a84302afb18e23583be3 to your computer and use it in GitHub Desktop.
Save brunokim/482bfb459306a84302afb18e23583be3 to your computer and use it in GitHub Desktop.
def memory_usage() -> int:
with open('/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes') as f:
return int(f.read())
def memory_limit() -> int:
with open('/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes') as f:
return int(f.read())
def memory_stats() -> dict[str, int]:
stats: dict[str, int] = {}
with open('/sys/fs/cgroup/memory/memory.stat') as f:
for line in f:
name, value_str = line.strip().split(' ')
stats[name] = int(value_str)
return stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment