From 06c8d6f98768f173854585e3c9b36c4fa6bfe753 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 5 Mar 2014 15:28:08 -0400 Subject: script to graph cpu/mem usage. Related: #5259 Use as: RESOURCE_TIME=5 make resource_graph where RESOURCE_TIME are the minutes to run for. --- .gitignore | 2 ++ Makefile | 8 ++++++++ pkg/scripts/monitor_resource.zsh | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100755 pkg/scripts/monitor_resource.zsh diff --git a/.gitignore b/.gitignore index eb44f637..e4b03d7a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.log *.lprof *.pstats +*.data *.*~ .* *_rc.py @@ -33,3 +34,4 @@ config/* CHANGELOG~ data/bitmask.pro +bitmask-resources.png diff --git a/Makefile b/Makefile index 25d2bcf5..2bd39eb0 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,10 @@ ifndef EDITOR export EDITOR=vim endif +ifndef RESOURCE_TIME + export RESOURCE_TIME=10 +endif + # all : resources ui @@ -77,5 +81,9 @@ do_lineprof: view_lineprof: @python -m line_profiler app.py.lprof | $(EDITOR) - +resource_graph: + ./pkg/scripts/monitor_resource.zsh `pgrep bitmask` $(RESOURCE_TIME) + display bitmask-resources.png + clean : $(RM) $(COMPILED_UI) $(COMPILED_RESOURCES) $(COMPILED_UI:.py=.pyc) $(COMPILED_RESOURCES:.py=.pyc) diff --git a/pkg/scripts/monitor_resource.zsh b/pkg/scripts/monitor_resource.zsh new file mode 100755 index 00000000..ac468e34 --- /dev/null +++ b/pkg/scripts/monitor_resource.zsh @@ -0,0 +1,26 @@ +#!/bin/zsh +if (( ! $# )); then + echo "Usage: $0:t " >&2 + return 1; +fi + +OUT="$1-usage.data" +GRAPH="bitmask-resources.png" +MAX=150 +let "ticks=$2*60/3" +echo "cpu mem" >> $OUT +for i in {1..$ticks}; do; + cpu=$(ps -p $1 -o pcpu | grep -v %) + mem=$(ps wuh -p $1 | awk '{print $4}') + echo "$cpu $mem" >> $OUT; + sleep 3; + echo $i / $ticks; +done; + +gnuplot -e "set term dumb; \ +set key outside; set yrange [0:$MAX]; \ +plot for [col=1:2] '$OUT' using 0:col title columnheader s c" + +gnuplot -e "set term png; set output '$GRAPH'; \ +set key outside; set yrange [0:$MAX]; \ +plot for [col=1:2] '$OUT' using 0:col with lines title columnheader" -- cgit v1.2.3