#!/bin/sh if expr "$1" ':' '[0-9][0-9]*' > /dev/null then CMD=`cat /proc/$1/cmdline` PID=$1 else CMD="$1" "$@" & PID=$! fi while : do sleep 1 # echo -n 'time '; date +%s.%N cat /proc/$PID/msa echo 'DONE' done | awk -v cmd="$CMD" ' BEGIN { counter=0 interesting["ONCPU_USER"] = 1 interesting["ONCPU_SYS"] = 1 interesting["INTERRUPTIBLE"] = 1 interesting["UNINTERRUPTIBLE"] = 1 interesting["EXPIREDQUEUE"] = 1 interesting["ACTIVEQUEUE"] = 1 interesting["INTERRUPTED"] = 1 } /^Now/ { $2 /= 1.0e9 if (then == 0) start = $2; then = now; now=$2 counter=counter+1 timestamps[counter] = now next } /State:/ { next; } /DONE/ { if (counter == 1) { plotline = "plot " for (j in states) { if (j in interesting) { plotline = plotline "\"-\" title \"" j "\" with lines," } } gsub(/,$/, "", plotline); next; } print "set label \"" cmd "\"" | "gnuplot" print "set timestamp \"%Y-%m-%d\"" | "gnuplot" print plotline | "gnuplot" for (j in states) { if (j in interesting) { for (i=1; i < counter; i++) { print timestamps[i] - start, diffs[j, i] | "gnuplot" } print "e" | "gnuplot" } } next; } { times[$1, counter] = $2 if (counter >= 1) { diffs[$1, counter] = ($2 - times[$1, counter-1]) ; diffs[$1, counter] /= 1.0e9 * (timestamps[counter] - timestamps[counter-1]) } states[$1]= 1 } '