Skip to content

Instantly share code, notes, and snippets.

@itiut
Created June 24, 2014 13:34
Show Gist options
  • Save itiut/d8cc0f46ad1eceb4937f to your computer and use it in GitHub Desktop.
Save itiut/d8cc0f46ad1eceb4937f to your computer and use it in GitHub Desktop.
pidstat -dtuh の出力からCPU利用率とI/Oスループットを抽出してプロットする
#!/bin/sh
set -eu
cd $(dirname $0)
if [ $# -ne 1 ]; then
echo "Usage: [$0] directory"
exit
fi
cd $1
select_and_project() {
local out=pidstat$1.out
local dat=pidstat$1.dat
echo '# seconds %user %system read[KB/s] write[KB/s]' > $dat
echo '0 0.00 0.00 0.00 0.00' >> $dat
cat $out \
| grep ' mysql' \
| awk '{ print NR " " $5 " " $6 " " $10 " " $11 }' \
>> $dat
echo "[$0] Write $PWD/$dat"
}
plot() {
local dat=pidstat$1.dat
local eps=pidstat$1.eps
local emf=pidstat$1.emf
gnuplot <<EOPLT
set key below;
set grid;
set ytics nomirror;
set y2tics;
set xlabel 'Elapsed Time [sec]';
set ylabel 'CPU Usage [%]';
set y2label 'I/O Throughput [KB/s]';
set yrange [0:150];
set y2range [0:150000];
set style fill solid 0.1;
set size 2,1;
set terminal postscript eps enhanced color solid;
set output '$eps';
plot '$dat' u 1:(\$2+\$3) w filledcurves x1 t '%system', \
'$dat' u 1:2 w filledcurves x1 t '%user', \
'$dat' u 1:4 w l t 'Read' axes x1y2, \
'$dat' u 1:5 w l t 'Write' axes x1y2;
set size 1,1;
set terminal emf size 960,480;
set output '$emf';
replot;
set terminal png size 960,480;
set output 'pidstat$1.png';
replot;
EOPLT
echo "[$0] Write $PWD/$eps"
echo "[$0] Write $PWD/$emf"
}
for i in $(seq 1 22); do
if [ ! -f pidstat$i.out ]; then
continue
fi
{
select_and_project $i
plot $i
} &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment