This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnancy_describe.sh
executable file
·249 lines (238 loc) · 7.82 KB
/
nancy_describe.sh
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/bash
#
# 2018–2019 © Postgres.ai
#
# Describe one or more experimental runs, taking
# collection(s) of artifacts as input.
DEBUG=false
VERBOSE_OUTPUT_REDIRECT=''
ARTIFACTS_PATH=''
#######################################
# Print a help
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
function help() {
echo -e "Describe results of nancy run tests. To start use:
nancy describe %artifacts_directory_path%
" | less -RFX
}
#######################################
# Print an error/warning/notice message to STDERR
# Globals:
# None
# Arguments:
# (text) Error message
# Returns:
# None
#######################################
function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $@" >&2
}
#######################################
# Print a debug-level message to STDOUT
# Globals:
# DEBUG
# Arguments:
# (text) Message
# Returns:
# None
#######################################
function dbg() {
if $DEBUG ; then
msg "DEBUG: $@"
fi
}
#######################################
# Print an message to STDOUT
# Globals:
# None
# Arguments:
# (text) Message
# Returns:
# None
#######################################
function msg() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $@"
}
#######################################
# Print an 5 top slowest queries
# Globals:
# ARTIFACTS_PATH
# Arguments:
# (int) count of slowest queries
# Returns:
# None
#######################################
function out_top_slowest() {
local top_count=$1
local i=0
local j=1
while : ; do
let j=$i+1
echo -e " Slowest query #$j."
duration=$(cat $FILE_PATH | jq '.top_slowest | .['$i'] | .[0]')
duration="${duration/\"/}"
duration="${duration/\"/}"
query=$(cat $FILE_PATH | jq '.top_slowest | .['$i'] | .[2]')
query="${query//'\\n'/}"
query="${query//'\\\"'/'"'}" #'
echo -e " Duration is: $duration ms"
echo -e " Query text: $query\n"
let i=$i+1
[[ "$i" -eq "$top_count" ]] && break;
done
}
#######################################
# Print an durations of slowest queries in different runs
# Globals:
# ARTIFACTS_PATH
# Arguments:
# (int) count of slowest queries to analyze
# Returns:
# (int) 1 if is not series experiment
#######################################
function compare_series_slowest() {
local top_count=$1
# Check is series experiment
if [[ ! -f "$ARTIFACTS_PATH/pgbadger.1.json" ]]; then
msg "Experiment is not series."
return 1
fi
local file_path=$ARTIFACTS_PATH/pgbadger.1.json
local i=0
local j=1
while : ; do
let j=$i+1
echo -e " Slowest query #$j."
duration=$(cat $file_path | jq '.top_slowest | .['$i'] | .[0]')
duration="${duration/\"/}"
duration="${duration/\"/}"
query=$(cat $file_path | jq '.top_slowest | .['$i'] | .[2]')
query_text="${query//'\\n'/}"
query_text="${query_text//'\\\"'/'"'}" #'
echo -e " Slowest query text: $query_text"
echo -e " Run 1 duration is:\t$duration ms"
local fi=2
while : ; do
if [[ ! -f "$ARTIFACTS_PATH/pgbadger.$fi.json" ]]; then
dbg "File $ARTIFACTS_PATH/pgbadger.$fi.json not found"
break
fi
local qi=0
local fcount=$(cat $ARTIFACTS_PATH/pgbadger.$fi.json | jq '.top_slowest | length')
while : ; do
qduration=$(cat $ARTIFACTS_PATH/pgbadger.$fi.json | jq '.top_slowest | .['$qi'] | .[0]')
qduration="${qduration/\"/}"
qduration="${qduration/\"/}"
qquery=$(cat $ARTIFACTS_PATH/pgbadger.$fi.json | jq '.top_slowest | .['$qi'] | .[2]')
if [[ "$query" == "$qquery" ]]; then
echo -e " Run $fi duration is:\t$qduration ms"
fi
let qi=$qi+1
[[ "$qi" -eq "$fcount" ]] && break;
done
let fi=$fi+1
done
let i=$i+1
[[ "$i" -eq "$top_count" ]] && break;
done
}
while [ $# -gt 0 ]; do
case "$1" in
help )
help
exit ;;
-d | --debug )
DEBUG=true
VERBOSE_OUTPUT_REDIRECT=''
shift ;;
* )
option=$1
option="${option##*( )}"
option="${option%%*( )}"
if [[ ! -d $option ]]; then
err "Artifacts directory not given"
exit 1
else
ARTIFACTS_PATH=$option
fi
break ;;
esac
done
if [[ -z "$ARTIFACTS_PATH" ]]; then
err "Artifacts directory not given"
exit 1
fi
#if [[ -f "$ARTIFACTS_PATH/pgreplay.txt" ]]; then
# cat "$ARTIFACTS_PATH/pgreplay.txt"
#fi
if [[ -f "$ARTIFACTS_PATH/pgbadger.json" ]]; then
FILE_PATH=$ARTIFACTS_PATH/pgbadger.json
echo -e "------------------------------------------------------------------------------"
echo -e "Artifacts (collected in \"$ARTIFACTS_PATH\"):"
echo -e " Postgres config: postgresql.conf"
echo -e " Postgres logs: postgresql.prepare.log.gz (preparation),"
echo -e " postgresql.workload.log.gz (workload)"
echo -e " pgBadger reports: pgbadger.html (for humans),"
echo -e " pgbadger.json (for robots)"
echo -e " Stat stapshots: pg_stat_statements.csv,"
echo -e " pg_stat_***.csv"
echo -e " pgreplay report: pgreplay.txt"
echo -e "------------------------------------------------------------------------------"
echo -e "Workload:"
echo -e " Total query time: "$(cat $FILE_PATH | jq '.overall_stat.queries_duration') " ms"
echo -e " Queries: "$(cat $FILE_PATH | jq '.overall_stat.queries_number')
echo -e " Query groups: "$(cat $FILE_PATH | jq '.normalyzed_info | length')
echo -e " Errors: "$(cat $FILE_PATH | jq '.overall_stat.errors_number')
echo -e " Errors groups: "$(cat $FILE_PATH | jq '.error_info | length')
echo -e "------------------------------------------------------------------------------"
elif [[ -f "$ARTIFACTS_PATH/pgbadger.1.json" ]]; then
FILE_PATH=$ARTIFACTS_PATH/pgbadger.1.json
SERIES_COUNT=2
while : ; do
if [[ ! -f "$ARTIFACTS_PATH/pgbadger.$SERIES_COUNT.json" ]]; then
let SERIES_COUNT=$SERIES_COUNT-1
break
fi
let SERIES_COUNT=$SERIES_COUNT+1
done
echo -e "------------------------------------------------------------------------------"
echo -e "Runs count: $SERIES_COUNT"
echo -e "Experiment artifacts collected in \"$ARTIFACTS_PATH/\"."
echo -e "Postgres prepare log: postgresql.prepare.log.gz (preparation),"
echo -e "------------------------------------------------------------------------------"
local i=1;
while : ; do
FILE_PATH="$ARTIFACTS_PATH/pgbadger.$i.json"
echo -e "\n"
echo -e "Run $i"
echo -e "------------------------------------------------------------------------------"
echo -e "Run artifacts (collected in \"$ARTIFACTS_PATH\"):"
echo -e " Postgres config: postgresql.$i.conf"
echo -e " Postgres log: postgresql.workload.$i.log.gz (workload)"
echo -e " pgBadger reports: pgbadger.$i.html (for humans),"
echo -e " pgbadger.$i.json (for robots)"
echo -e " Stat stapshots: pg_stat_statements.$i.csv,"
echo -e " pg_stat_***.$i.csv"
echo -e " pgreplay report: pgreplay.$i.txt"
echo -e "------------------------------------------------------------------------------"
echo -e "Workload:"
echo -e " Total query time: "$(cat $FILE_PATH | jq '.overall_stat.queries_duration') " ms"
echo -e " Queries: "$(cat $FILE_PATH | jq '.overall_stat.queries_number')
echo -e " Query groups: "$(cat $FILE_PATH | jq '.normalyzed_info | length')
echo -e " Errors: "$(cat $FILE_PATH | jq '.overall_stat.errors_number')
echo -e " Errors groups: "$(cat $FILE_PATH | jq '.error_info | length')
echo -e "------------------------------------------------------------------------------"
let i=$i+1
[[ "$i" -eq "$SERIES_COUNT" ]] && break;
done
fi
compare_series_slowest 5
if [ $? -ne 0 ]; then
out_top_slowest 5
fi