diff options
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/visualize_stats.sh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/contrib/visualize_stats.sh b/contrib/visualize_stats.sh new file mode 100755 index 000000000..87d8fc6c4 --- /dev/null +++ b/contrib/visualize_stats.sh | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # This script polls gnunet-stats repeatedly to create statistics plots. | ||
4 | # Use 'collect' to collect statistics and 'plot' to plot whats been | ||
5 | # collected. All plots will be written to $STATDIR as separate .png files. | ||
6 | # | ||
7 | # WARNING: calling 'collect' will delete all files in $STATDIR. | ||
8 | # | ||
9 | # Requires: gnuplot | ||
10 | # | ||
11 | # Note: gnuplot syntax has changed across versions. This | ||
12 | # script perhaps will not produce color images with older gnuplots. | ||
13 | # The script should work atleast with gnuplot 3.8k patchlevel 1. | ||
14 | # | ||
15 | |||
16 | SLEEP=120 | ||
17 | GNUNET=$HOME/ | ||
18 | STATDIR=$GNUNET/stats | ||
19 | IMAGEVIEWER='display' | ||
20 | TMP=/tmp/.gnuplot_error | ||
21 | |||
22 | ########################################################################## | ||
23 | |||
24 | mkdir -p $STATDIR | ||
25 | |||
26 | case "$1" in | ||
27 | collect) | ||
28 | rm -f $STATDIR/* | ||
29 | |||
30 | STARTTIME=`date +%s` | ||
31 | IFS=":" | ||
32 | |||
33 | while true; do | ||
34 | NOW=`date +%s` | ||
35 | RELAT=$[$NOW-$STARTTIME] | ||
36 | gnunet-statistics | while read KEY VALUE; do | ||
37 | |||
38 | # Collect stats of previous round | ||
39 | if [ -e "$STATDIR/$KEY.dat" ]; then | ||
40 | PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"` | ||
41 | else | ||
42 | PREV=$VALUE | ||
43 | fi | ||
44 | |||
45 | # Write new stats | ||
46 | echo $RELAT $VALUE >>"$STATDIR/$KEY.dat" | ||
47 | echo $RELAT $PREV $VALUE >>"$STATDIR/$KEY.diff" | ||
48 | |||
49 | done | ||
50 | sleep $SLEEP | ||
51 | done | ||
52 | ;; | ||
53 | plot) | ||
54 | # Plot incremental | ||
55 | ls -1 $STATDIR/*.dat | while read FILENAME; do | ||
56 | BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"` | ||
57 | echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - incr';plot '$FILENAME' using (\$1/60):(\$2) title '' with lines;" | nice gnuplot 2> $TMP | ||
58 | EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l` | ||
59 | if test $EC -ge 1 | ||
60 | then | ||
61 | rm "$FILENAME.png" | ||
62 | fi | ||
63 | done | ||
64 | |||
65 | # Plot diff | ||
66 | ls -1 $STATDIR/*.diff | while read FILENAME; do | ||
67 | BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"` | ||
68 | echo "set terminal png;set output '$FILENAME.png';set title '$BASENAME - diff';plot '$FILENAME' using (\$1/60):(\$3-\$2) title '' with lines;" | nice gnuplot 2> $TMP | ||
69 | EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l` | ||
70 | if test $EC -ge 1 | ||
71 | then | ||
72 | rm "$FILENAME.png" | ||
73 | fi | ||
74 | |||
75 | done | ||
76 | ;; | ||
77 | view) | ||
78 | $IMAGEVIEWER $STATDIR/*.png | ||
79 | ;; | ||
80 | *) | ||
81 | echo $"Usage: $0 {collect|plot|view}" | ||
82 | exit 1 | ||
83 | |||
84 | esac | ||
85 | |||
86 | |||