hanoidb/visualize-hanoi.sh

111 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
## ----------------------------------------------------------------------------
##
2012-04-21 19:20:39 +00:00
## hanoi: LSM-trees (Log-Structured Merge Trees) Indexed Storage
##
## Copyright 2011-2012 (c) Trifork A/S. All Rights Reserved.
## http://trifork.com/ info@trifork.com
##
## Copyright 2012 (c) Basho Technologies, Inc. All Rights Reserved.
## http://basho.com/ info@basho.com
##
## This file is provided to you under the Apache License, Version 2.0 (the
## "License"); you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
## License for the specific language governing permissions and limitations
## under the License.
##
## ----------------------------------------------------------------------------
2012-01-06 12:56:52 +00:00
function periodic() {
t=0
while sleep 1 ; do
let "t=t+1"
printf "%5d [" "$t"
2012-01-05 16:50:33 +00:00
for ((i=0; i<35; i++)) ; do
if ! [ -f "A-$i.data" ] ; then
echo -n " "
elif ! [ -f "B-$i.data" ] ; then
echo -n "-"
elif ! [ -f "C-$i.data" ] ; then
echo -n "#"
elif ! [ -f "X-$i.data" ] ; then
echo -n "="
else
echo -n "*"
fi
done
echo
2012-01-06 12:56:52 +00:00
done
}
merge_diff() {
SA=`ls -l A-${ID}.data 2> /dev/null | awk '{print $5}'`
SB=`ls -l B-${ID}.data 2> /dev/null | awk '{print $5}'`
SX=`ls -l X-${ID}.data 2> /dev/null | awk '{print $5}'`
if [ \( -n "$SA" \) -a \( -n "$SB" \) -a \( -n "$SX" \) ]; then
export RES=`expr ${SX}0 / \( $SA + $SB \)`
else
export RES="?"
fi
}
2012-01-06 12:56:52 +00:00
function dynamic() {
local old s t start now
t=0
start=`date +%s`
while true ; do
s=""
for ((i=8; i<22; i++)) ; do
if [ -f "C-$i.data" ] ; then
s="${s}C"
2012-04-22 13:14:14 +00:00
else
s="$s "
2012-04-22 13:14:14 +00:00
fi
if [ -f "B-$i.data" ] ; then
s="${s}B"
else
2012-04-22 13:14:14 +00:00
s="$s "
fi
if [ -f "A-$i.data" ] ; then
s="${s}A"
2012-04-22 13:14:14 +00:00
else
s="$s "
fi
if [ -f "X-$i.data" ] ; then
export ID="$i"
merge_diff
s="${s}$RES"
2012-04-22 13:14:14 +00:00
elif [ -f "M-$i.data" ] ; then
s="${s}M"
else
s="$s "
fi
2012-04-22 13:14:14 +00:00
s="$s|"
done
2012-01-06 12:56:52 +00:00
if [[ "$s" != "$old" ]] ; then
let "t=t+1"
now=`date +%s`
let "now=now-start"
free=`df -m . 2> /dev/null | tail -1 | awk '{print $4}'`
used=`du -m 2> /dev/null | awk '{print $1}' `
printf "%5d %6d [%s\n" "$t" "$now" "$s ${used}Mb (${free}Mb free)"
old="$s"
else
# Sleep a little bit:
sleep 1
fi
done
2012-01-06 12:56:52 +00:00
}
2012-01-06 12:56:52 +00:00
dynamic