Skip to content

Commit 99922c1

Browse files
committed
Implement support for running benchmarks with perf
1 parent 37e3134 commit 99922c1

6 files changed

+55
-4
lines changed

Diff for: Dockerfile-pgapt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -19,6 +20,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
1920
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2021
openjdk-17-jdk maven sysbench
2122

23+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
24+
2225
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2326
ENV LANG en_US.UTF-8
2427
ENV LC_ALL en_US.UTF-8
@@ -76,7 +79,12 @@ printf "\n"\
7679
"host all all 0.0.0.0/0 md5\n"\
7780
"host all all ::1/128 trust\n" >> /etc/postgresql/$PG_VERSION/main/pg_hba.conf
7881

79-
RUN echo "/usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
82+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
83+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
84+
echo "/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl -w -D /var/lib/postgresql/$PG_VERSION/main stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
85+
else \
86+
echo "/usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
87+
fi
8088

8189
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-$version`` package when it was ``apt installed``
8290
USER postgres

Diff for: Dockerfile-proapt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -21,6 +22,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
2122
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2223
openjdk-17-jdk maven sysbench
2324

25+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
26+
2427
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2528
ENV LANG en_US.UTF-8
2629
ENV LC_ALL en_US.UTF-8
@@ -81,7 +84,12 @@ printf "\n"\
8184
"host all all 0.0.0.0/0 md5\n"\
8285
"host all all ::1/128 trust\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/pg_hba.conf
8386

84-
RUN echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
87+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
88+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
89+
echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/pg_ctl -w -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
90+
else \
91+
echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
92+
fi
8593

8694
# Run the rest of the commands as the ``postgres`` user created by the ``postgres*-$version`` package when it was ``apt installed``
8795
USER postgres

Diff for: Dockerfile-src

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -20,6 +21,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
2021
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2122
openjdk-17-jdk maven sysbench
2223

24+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
25+
2326
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2427
ENV LANG en_US.UTF-8
2528
ENV LC_ALL en_US.UTF-8
@@ -58,7 +61,12 @@ RUN cd /home/postgres/src/postgres && make -s install && \
5861

5962
ENV PATH "$PATH:/usr/local/pgsql/bin"
6063

61-
RUN echo "/usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
64+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
65+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
66+
echo "/usr/local/pgsql/bin/pg_ctl -w -D /var/lib/postgresql/main stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
67+
else \
68+
echo "/usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
69+
fi
6270

6371
COPY ./$PHASE2_ACTION /bin/
6472
RUN $PHASE2_ACTION

Diff for: config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<os version="23.04" />
3131
</instance>
3232
<xi:include href="private_instances.xml" />
33+
<instance id="pg-src-master-perf" disabled="true" type="src" features="perf" git_branch="master" />
3334
<instance id="pg-src-15" type="src" pg_version="15devel" git_branch="REL_15_STABLE" />
3435
<instance id="pg-src-master" type="src" pg_version="16devel" git_branch="master" />
3536
</pg_instances>

Diff for: prepare-instances.py

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def get_repo_url(instance):
142142
encoding='UTF-8') as dockerfile:
143143
dockerfile.write(df_contents)
144144

145+
if instance.get('features') is not None:
146+
build_args += ["--build-arg",
147+
(f'FEATURES={instance.get("features")}')]
148+
145149
if instance.get('pg_version') is not None:
146150
build_args += ['--build-arg',
147151
(f'PG_VERSION={instance.get("pg_version")}')]

Diff for: run-benchmarks.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
188188
f'-v {os.getcwd()}/resources:/home/postgres/resources '
189189
f'-v {os.getcwd()}/scripts:/home/postgres/scripts '
190190
f'-v {resultdir}:/home/postgres/results '
191-
f'--tty --cap-add=SYS_PTRACE '
191+
f'--tty --cap-add=SYS_PTRACE --cap-add=SYS_ADMIN '
192192
f'--shm-size=2g {envvars} {instance_id}',
193193
shell=True, check=True, stdout=subprocess.PIPE)
194194
container_id = res.stdout.decode('utf-8').strip()
@@ -247,6 +247,28 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
247247
print(output)
248248
raise Exception('Benchmark execution failed! (For details '
249249
'see benchmark-results/.)')
250+
251+
instance_features = instance.get('features')
252+
if re.match(r'\bperf\b', instance_features):
253+
res = run(f'docker exec -t {container_id} bash -c '
254+
f'pg_ctl_stop',
255+
shell=True, check=False, stdout=subprocess.PIPE)
256+
if res.returncode != 0:
257+
print(res.stdout.decode('utf-8'))
258+
raise Exception('Could not stop server.')
259+
sleep(10)
260+
res = run(f'docker exec -t {container_id} bash -c "'
261+
f'perf report --stdio -i'
262+
f' /home/postgres/results/perf.data'
263+
f' >/home/postgres/results/perf.out 2>&1; '
264+
f'perf script -i'
265+
f' /home/postgres/results/perf.data'
266+
f' >/home/postgres/results/perf.script 2>&1"',
267+
shell=True, check=False, stdout=subprocess.PIPE)
268+
if res.returncode != 0:
269+
print(res.stdout.decode('utf-8'))
270+
raise Exception('Could not get perf report.')
271+
250272
for metric in bench.findall('./results/metric'):
251273
mid = metric.get('id')
252274
mre = metric.get('regexp')

0 commit comments

Comments
 (0)