-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch-flush
83 lines (79 loc) · 1.88 KB
/
watch-flush
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
#!/bin/bash
timeorig=$(date '+%s')
deltat=5 # checking time interval
if [ $# -eq 2 ]
then
echo "'${0##*/}' watches flushing buffered alias 'dirty' data"
tailfile="$2"
dirtorig="$1" # total file size [bytes] to be cloned
dirtorig=$((dirtorig/1000))
if [ "$dirtorig" == "0" ]
then
dirtorig=$(grep -e 'Dirty:' /proc/meminfo | tr -s ' ' '\t' | cut -f2)
fi
echo "dirty = $dirtorig kB - total file size to be cloned"
echo "0
# file size : $dirtorig kB - to be cloned" > "$tailfile"
else
echo "'${0##*/}' watches flushing 'dirty' data - quit with 'q'"
dirtorig=$(grep -e 'Dirty:' /proc/meminfo | tr -s ' ' '\t' | cut -f2)
echo "dirty = $dirtorig kB - when starting to watch"
fi
dirt0=$dirtorig
run=true
ratsum=0
numsum=0
while $run
do
if [ $# -eq 2 ]
then
sleep "$deltat"
else
read -n 1 -s -t "$deltat" tdum
if [ "$tdum" == "q" ]
then
run=false
fi
fi
dirty=$(grep -e 'Dirty:' /proc/meminfo | tr -s ' ' '\t' | cut -f2)
deltad=$((dirt0-dirty))
if [ $deltad -gt 0 ]
then
eta="$((dirty*deltat/deltad)) s"
rate=$(((deltad+500)/deltat/1000))
ratsum=$((ratsum+rate))
numsum=$((numsum+1))
rate="$rate MB/s"
elif [ $deltad -lt 0 ]
then
eta="n.a."
rate=$(((deltad+500)/deltat/1000))
# ratsum=$((ratsum+rate))
# numsum=$((numsum+1))
rate="$rate MB/s"
else
eta="n.a."
rate="n.a."
fi
echo -en "\0033[2K\0033[1G"
echo -n "dirty = $dirty kB -- watching -- rate = $rate -- eta = $eta"
dirt0="$dirty"
if [ $# -eq 2 ]
then
percent=$((100-(100*dirty+50)/dirtorig))
echo "$percent
# buffered data : $dirty kB -- watching -- rate : $rate -- eta : $eta" >> "$tailfile"
fi
done
echo -e "\0033[2K\0033[1GDone watching :-)"
timefinal=$(date '+%s')
timeused=$((timefinal-timeorig))
if [ $numsum -gt 0 ]
then
rate="$(( (ratsum + numsum/2) / numsum))"
else
rate="n.a."
fi
echo "ratsum=$ratsum"
echo "numsum=$numsum"
echo "watching time = $timeused s -- average rate = $rate MB/S"