Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 59 lines (50 sloc) 1.506 kB
22b433a @fperrin Don't assume that bash is in /bin
fperrin authored
1 #!/usr/bin/env bash
2
3 set -e
fccc685 Initial open-source release
MLstate authored
4
5 skip=1
6
7 while [ $# -gt 0 ]; do
8 case $1 in
9 --help)
10 echo "plotpipe: plots data from stdin in real-time using gnuplot"
11 echo "Usage: <command> | $0 [options] <regex>"
12 echo "Options:"
13 echo " -s <int> only take one out of <int> values, skip the rest"
14 echo ""
15 echo "The regexp should match the first group with the value to"
16 echo 'plot (for instance, "^Stack usage: \([0-9]\+\)")'
17 exit 0;;
18 -s)
19 shift
20 skip=$1
21 shift;;
22
23 *)
24 regex=$1
25 shift
26 esac
27 done
28
29 data=$(mktemp -t plotpipe-XXXXX)
30 trap "rm -f $data" EXIT
31
32 t=$(date +%s%N)
33
34 (
35 echo 'set xlabel "Time (seconds)"'
36
37 first=2 # wait until we have two points to plot
38 i=0
39 while read line; do
40 if echo "$line" | grep "$regex" >/dev/null; then
41 if [ $i -gt 0 ]; then i=$((i - 1))
42 else
43 i=$((skip - 1))
44 echo "$line" | sed "s/$regex/$(date +%s%N) \1/" >>$data
45 if [ $first -eq 0 ]; then
46 echo "replot";
47 else
48 if [ $first -eq 1 ]; then
49 echo "plot \"$data\" using ((\$1 - $t.)/1e9):2 with lines notitle"
50 fi
51 first=$((first - 1))
52 fi
53 fi
54 else
55 echo "$line" >&2
56 fi
57 done
58 ) | gnuplot >/dev/null 2>&1
Something went wrong with that request. Please try again.