Skip to content

Commit

Permalink
memusage: Add a log option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jul 30, 2024
1 parent e735359 commit 44e4ae5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions memusage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import sys
import time
last = float("inf")
log = open("memusage.log") if "--log" in sys.argv else None
while True:
with open("/proc/meminfo") as mem:
for line in mem:
key, val = line.split(":")
if key == "MemAvailable":
memavail = int(val.replace("kB", ""))
if log: print(int(time.time()), memavail, file=log)
if memavail < last:
print(line.strip())
last = memavail
Expand Down

0 comments on commit 44e4ae5

Please sign in to comment.