-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanalyzeheatmap
105 lines (91 loc) · 4.31 KB
/
scanalyzeheatmap
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
function dumpVSDL1()
{
local vsd="$1"
echo $vsd;
detail=$(sc vsd show display detail uuid $vsd)
cap=`sc vsd show display detail uuid $vsd | grep CapacityBytes | awk '{print $3}'`
headers=`sc vsd show display detail uuid $vsd | grep Headers | awk '{ print $3 }' | sed -e 's/,//g'`
echo "Headers are $headers"
l1=$(sc rsd interpret extent $headers-1024 | grep L1table | awk '{ print $4 }');
echo "Capacity:"
echo "$cap"
echo "L1 address: $l1"
ext=$(sc rsd interpret extent ${l1%,*}-$((16 * 1024)) | grep chunks) # read the L0
if [ -z "$ext" ]; then
# spoof a chunk for pre-L0 tables
ext="[0]${l1%,*}-$(( ($cap / 1048576) / 29 * 512 + 512))"
fi
for w in $(echo $ext); do # break into words
chunk=$(echo "$w" | egrep '\[[0-9]+\][0-9]:[0-9]+:[0-9]:0x'| gawk ' BEGIN { mb = 1048576 / 512} /VSD/ { print $0 } /:/{ match ($1, /(0:.*)(0x[0-9a-f]+)-([0-9]+)/, addr); c = addr[3] / 1048576; if (c == 1) { print $0 ; } else { for (i = 0; i < c; ++i) { printf "%s0x%x-1048576 %s\n", addr[1], strtonum(addr[2]) + i * mb, $2; }}} ') # chunks
if ! [ -z "$chunk" ]; then
addr=${chunk%%-*};
addr=${addr##*]};
length=${chunk##*-};
echo "Found L1 extent $addr-$length"
sc rsd interpret extent $addr-$length
fi
done
}
function get_percentile
{
awk "BEGIN { print int (.$2 * $1); }"
}
function analyzeVSDHeatmap()
{
local uuid="$1"
vmguid="$(sc vsd show display attachments uuid $uuid | awk '{ print $2 }' | tail -n +3)"
vmname="$(sc vm show display detail guid $vmguid | grep Name | cut -d ":" -f 2)"
if ! [ -z "$vmguid" ]; then
echo ""
echo -e "From VM: $vmname\n"
fi
echo "--- Analyzing Heatmap for VSD $uuid ---"
echo ""
if [ -z "$(sc vsd show | grep ONLINE | grep "$uuid")" ]; then
echo "No ONLINE vsd with uuid $1";
return 1
fi
echo "Counting entry allocations..."
entryCount="$(dumpVSDL1 "$uuid" | gawk ' /^ address/ { match($1, "([0-9]+)", ary); if (ary[1] % 2 == 0) print $0; }' | grep -v '0:0:0:0x0' | wc -l)"
echo "Total allocated entries: $entryCount";
if [ $entryCount == "0" ]; then
echo "No allocated entries; skipping VSD $uuid";
return 0
fi
echo "Getting complete heatmap..."
distribution="$(sc vsdheatmap show display data uuid $uuid edge 0 | sed -s 's/\] \[/\]X\[/g' | tr 'X' '\n' | gawk ' BEGIN { FS=","; top=0; } /^\[/ { match($1, "([0-9]+)", h); match($2, "([0-9]+)", e); dist[e[1]]=h[1]; if (e[1] > top) { top = e[1]; } } END { for (i = 0; i <= top; ++i) { count=dist[i]; if (count == "") { count = 0; } printf "%5d: %5d ", count, i; for (j = 0; j < count; ++j) { printf "#"; } printf "\n"; } }' | sort -n)"
totalHeat="$(echo "$distribution" | gawk '{ total += $1 } END { print total; } ')";
maxHeat="$(echo "$distribution" | tail -1 | gawk '{ total += $1 } END { print total; } ')";
echo "Total heat: $totalHeat";
echo "Getting heat distributions:"
for i in 60 70 80 90 95 96 97 98 99; do
hp="$(get_percentile $maxHeat $i)"
percCount="$(echo "$distribution" | awk "BEGIN { total = 0; } { if (int(\$1) >= $hp) total += 1; } END { print total; } ")"
if [ -z "$percCount" ]; then
percCount=0;
fi
entryPercent="$(awk "BEGIN { print ($percCount / $entryCount) * 100; }")"
echo " Percentile $i: entries with heat >= $hp: $percCount ($entryPercent%)"
done;
echo "Getting entry distributions:"
for i in 1 2 3 5 8 10; do
numInPerc="$(awk " BEGIN { print int($entryCount * ($i / 100)); } ")"
heatInPerc="$(echo "$distribution" | tail -n $numInPerc | awk " { total += int(\$1); } END { print total }")"
if [ -z "$heatInPerc" ]; then
heatInPerc=0;
fi
heatSharePerc="$(awk " BEGIN { print ($heatInPerc / $totalHeat) * 100; } ")"
gigs="$(awk " BEGIN { print ($numInPerc * 2) / 1024 } ")"
echo " There are $numInPerc entries, or ${gigs}GB, (at replicationFactor=2), in the hottest $i%, which account for $heatSharePerc% of all heat ($heatInPerc/$totalHeat)"
done;
}
if [ -z "$1" ]; then
# run on all online VSDs
uuids="$(sc vsd show | grep ONLINE | awk '{ print $1 }')"
else
uuids=$@;
fi
for i in $uuids; do
analyzeVSDHeatmap "$i";
done