Last active
November 10, 2021 20:23
-
-
Save cowlicks/c7fdefe7639ec116a31f2933cc4e7861 to your computer and use it in GitHub Desktop.
Log memory of a process
This file contains hidden or 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
# Prints the time the log spans and how many bytes per second its memory has increased | |
import sys | |
logname = sys.argv[1] | |
with open(logname) as f: | |
first, *_, last = f | |
t0, m0 = map(int, first.split()); | |
t1, m1 = map(int, last.split()); | |
print(f'Time: [{(t1 - t0)/60:.2f}] at {((m1 - m0)/(t1 - t0)):.2f} B/s') |
This file contains hidden or 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
1636570520 12796 | |
1636570521 12796 | |
1636570522 13060 | |
1636570523 13060 | |
1636570525 13060 | |
1636570526 13060 | |
1636570527 13060 | |
1636570528 13060 | |
1636570529 13060 |
This file contains hidden or 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
#logs to a file with format | |
# seconds-since-epoch memory-used | |
# you can monitor the file with `tail -f $LOG` from another shell | |
LOG=log-name | |
CMDNAME=command-name | |
rm -f $LOG | |
while true; do | |
mem=$(ps -C $CMDNAME --no-headers -o rss) && echo "$(date +%s) $mem" >> $LOG | |
sleep 1 | |
# uncomment to print memory usage live | |
# python analyze-memlog.py $LOG | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment