Skip to content

Instantly share code, notes, and snippets.

@etherealxx
Last active January 19, 2023 23:20
Show Gist options
  • Save etherealxx/c26f1f6fef39fd4bf274749b83dcb8ff to your computer and use it in GitHub Desktop.
Save etherealxx/c26f1f6fef39fd4bf274749b83dcb8ff to your computer and use it in GitHub Desktop.
Log the ram usage of Google Colab in background every 10 seconds.

About

This piece of code when ran in a single cell in Google Colab, will log the usage of the ram every 10 seconds into /content/process_ram_usage.txt. And you can use other cells while this cells is running (in background).

When you're done logging, use log_process.kill() on a new cell

#copy these code to a single cell then runs it. it will run on the background
import subprocess
import time
%cd /content
log_process = subprocess.Popen(['bash','-c', "while true; do echo '---------------' >> process_ram_usage.txt; echo `date` >> process_ram_usage.txt; ps aux --sort -rss | awk '{print $11, $1, $6}' | xargs -d '\n' -I{} echo {} >> process_ram_usage.txt; sleep 10; done"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#changed the date settings to Jakarta (WIB)
import subprocess
import time
%cd /content
log_process = subprocess.Popen(['bash','-c', "while true; do echo '---------------' >> process_ram_usage.txt; echo `TZ='Asia/Jakarta' date` >> process_ram_usage.txt; ps aux --sort -rss | awk '{print $11, $1, $6}' | xargs -d '\n' -I{} echo {} >> process_ram_usage.txt; sleep 10; done"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment