Skip to content

Instantly share code, notes, and snippets.

@markuman
Created June 17, 2015 18:33
Show Gist options
  • Save markuman/25a5809b2bcaea40489e to your computer and use it in GitHub Desktop.
Save markuman/25a5809b2bcaea40489e to your computer and use it in GitHub Desktop.
#!/bin/bash
## usage
# ./track <PID> <logname>
## info
# <logname> will be saved in /tmp/ (logging format is simple csv)
# track the memory usage of a process ID + zram usage
# zramOD_B is original datasize in bytes
# zramCD_B is compressed datasize in bytes
# averageQueue are the number of R processes in the last 60 seconds
PID=$1
echo "time, totalMemory_kB, dataStack_kB, memAvailable_kB, zramOD_B, zramCD_B, swapCache_kB, averageQueue" > /tmp/$2
while true
do
time=$(date +%s)
totalMemory=$(awk '{ print $1 }' /proc/$PID/statm)
dataStack=$(awk '{ print $6 }' /proc/$PID/statm)
memAvailable=$(grep MemAvailable /proc/meminfo| awk '{ print $2 }')
zramOD=$(cat /sys/block/zram0/orig_data_size)
zramCD=$(cat /sys/block/zram0/compr_data_size)
swapCache=$(grep SwapCached: /proc/meminfo| awk '{ print $2 }')
averageQueue=$(awk '{ print $1 }' /proc/loadavg)
echo $time "," $totalMemory "," $dataStack "," $memAvailable "," $zramOD "," $zramCD "," $swapCache "," $averageQueue >> /tmp/$2
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment