Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Created November 1, 2023 22:21
Show Gist options
  • Save ThomasParistech/3befa6f691806eb672af046a3a416197 to your computer and use it in GitHub Desktop.
Save ThomasParistech/3befa6f691806eb672af046a3a416197 to your computer and use it in GitHub Desktop.
import psutil
def get_total_ram_available_bytes() -> int:
"""Return the total number of bytes available on the platform."""
return int(psutil.virtual_memory().total)
def get_total_ram_used_bytes() -> int:
"""Return the number of bytes currently used on the platform."""
return int(psutil.virtual_memory().used)
def get_pid_ram_used_bytes(pid: int) -> int:
"""Return the number of bytes currently used by a given process.
(Use os.getpid() to get current process ID)"""
return int(psutil.Process(pid).memory_info().rss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment