Last active
September 3, 2019 16:53
-
-
Save JGrossholtz/a206952f8f01454b3466af69f5fec65c to your computer and use it in GitHub Desktop.
Quick CPU/process consumption analysis using mpstat&top
This file contains 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
# run mpstat and top for 5 minutes, at then end, get a loadaverage value | |
export DURATION=300 # run for 5 minutes | |
rm -rf /tmp/analysis; mkdir -p /tmp/analysis; $(timeout -t $DURATION -s2 sh -c './mpstat 1 >/tmp/analysis/mpstat.txt') & $(timeout -t $DURATION -s2 sh -c 'top -b -d1 >/tmp/analysis/top.txt') & sleep $DURATION; cat /proc/loadavg >/tmp/analysis/loadavg.txt | |
# Filter top output (necessary as the top binary on my embedded system lack many options) | |
export PROCESS_NAME=communication | |
cat /tmp/analysis/top.txt | grep $PROCESS_NAME | awk '{ print $7 }' | sed 's/%//g' > /tmp/analysis/top_filtered.txt | |
awk '{ total += $1 } END { print total/NR }' /tmp/analysis/top_filtered.txt > /tmp/analysis/top_avg.txt | |
cat /tmp/analysis/top_filtered.txt | sort -nr | uniq -c > /btmp/analysis/top_weighted_categories.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment