aboutsummaryrefslogtreecommitdiff
path: root/contrib/visualize_stats.sh
blob: 87d8fc6c4cfb69602bef6cf398c798a8b52a93dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
#
# This script polls gnunet-stats repeatedly to create statistics plots. 
# Use 'collect' to collect statistics and 'plot' to plot whats been
# collected. All plots will be written to $STATDIR as separate .png files.
#
# WARNING: calling 'collect' will delete all files in $STATDIR.
#
# Requires: gnuplot
#
# Note: gnuplot syntax has changed across versions. This
# script perhaps will not produce color images with older gnuplots.
# The script should work atleast with gnuplot 3.8k patchlevel 1.
#

SLEEP=120
GNUNET=$HOME/
STATDIR=$GNUNET/stats
IMAGEVIEWER='display'
TMP=/tmp/.gnuplot_error

##########################################################################

mkdir -p $STATDIR

case "$1" in
  collect)
    rm -f $STATDIR/*
  
    STARTTIME=`date +%s`
    IFS=":"
    
    while true; do
	NOW=`date +%s`
	RELAT=$[$NOW-$STARTTIME]
	gnunet-statistics | while read KEY VALUE; do
		
		# Collect stats of previous round
		if [ -e "$STATDIR/$KEY.dat" ]; then
			PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"`
		else
			PREV=$VALUE
		fi

		# Write new stats
		echo $RELAT $VALUE >>"$STATDIR/$KEY.dat"
		echo $RELAT $PREV $VALUE >>"$STATDIR/$KEY.diff"
	
	done
	sleep $SLEEP
    done
  ;;
  plot)
	# Plot incremental
        ls -1 $STATDIR/*.dat | while read FILENAME; do
	        BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
		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
         EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
         if test $EC -ge 1
	 then
	   rm "$FILENAME.png"
	 fi
	done
        
	# Plot diff
	ls -1 $STATDIR/*.diff | while read FILENAME; do
	        BASENAME=`basename "$FILENAME" | sed -e "s/ *\..*//g"`
		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
         EC=`cat $TMP | grep "empty" | grep "Warning" | wc -l`
         if test $EC -ge 1 
         then
          rm "$FILENAME.png"
         fi

  	done
  ;;
  view)
	$IMAGEVIEWER $STATDIR/*.png
  ;;
  *)
     echo $"Usage: $0 {collect|plot|view}"
     exit 1
    
esac