This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
tpch_runone
executable file
·90 lines (71 loc) · 2.47 KB
/
tpch_runone
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
#!/bin/bash
###
# This script runs a single query
# * 1) Gather execution time using '/usr/bin/time'
# * 2) Collect data with perf to generate callgraph
# * 3) Collect a set of basic statistics, again using perf. For now we obtain
# the default given by perf, but this can be modified later to extract
# statistics of interest to us.
###
BASEDIR=$(dirname "$0")
BASEDIR=$(cd "$BASEDIR"; pwd)
. "$BASEDIR/pgtpch_defaults"
if [ $# -lt 1 ]; then
echo "Please provide the number of the query you wish to run, e.g.:"
echo "$0 6 [dir-sufix]"
exit 1
fi
# Set up a custom directory for this query run
PERFDATADIR="$PERFDATADIR-${SCALE}GB"
if [ $# -eq 2 ]; then
PERFDATADIR="$PERFDATADIR-$2"
fi
perf_set_kernel_params
# Start a new instance of Postgres
sudo -u $PGUSER taskset -c 2 $PGBINDIR/postgres -D "$PGDATADIR" -p $PGPORT &
PGPID=$!
while ! sudo -u $PGUSER $PGBINDIR/pg_ctl status -D $PGDATADIR | grep "server is running" -q; do
echo "Waiting for the Postgres server to start"
sleep 1
done
# wait for it to finish starting
sleep 5
echo "Postgres running, pid $PGPID"
ii=$(printf "%02d" $1)
dir="$PERFDATADIR/q${ii}"
mkdir -p $dir
cd "$dir"
chmod 777 .
### Query to be executed
f="queries/q$ii.sql"
fe="queries/q$ii.explain.sql"
fa="queries/q$ii.analyze.sql"
### Execute query with explain analyze to get query plan
echo "Execute query with explain analyze to get query plan"
sudo -u $PGUSER $PGBINDIR/psql -h /tmp -p $PGPORT -d $DB_NAME <"$BASEDIR/$fa" > analyze.txt
restart_drop_caches
### Collect data with perf to generate callgraph
echo "Collect data with perf to generate callgraph"
/usr/bin/time -f '%e\n%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k'\
sudo -u $PGUSER perf record -a -C 2 -s -g -m 512 --\
$PGBINDIR/psql -h /tmp -p $PGPORT -d $DB_NAME <"$BASEDIR/$f" 2> exectime.txt
restart_drop_caches
### Collect basic stats with perf
echo "Collect basic stats with perf"
sudo -u $PGUSER perf stat -a -C 2 -B --log-fd 2 --\
$PGBINDIR/psql -h /tmp -p $PGPORT -d $DB_NAME <"$BASEDIR/$f" 2> stats.txt
restart_drop_caches
sudo chown $USER:$USER *
chmod 775 .
cgf="../q${ii}-callgraph.pdf"
echo "Creating the call graph: $cgf"
perf script | python "$BASEDIR/gprof2dot.py" -f perf | dot -Tpdf -o $cgf &
# Statistics collection
perf script | python "$BASEDIR/gprof2dot.py" -f perf | python "$BASEDIR/collect_stats.py" $i > q${ii}-breakdown.csv
cd - >/dev/null
# Stop the server
sudo -u $PGUSER $PGBINDIR/pg_ctl stop -D $PGDATADIR
for p in $(jobs -p);
do
wait $p
done