1############################################################################
2#  misc/diskbench.mk
3#
4#  Part of the STXXL. See http://stxxl.sourceforge.net
5#
6#  Copyright (C) 2008-2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
7#
8#  Distributed under the Boost Software License, Version 1.0.
9#  (See accompanying file LICENSE_1_0.txt or copy at
10#  http://www.boost.org/LICENSE_1_0.txt)
11############################################################################
12
13HOST		?= unknown
14FILE_SIZE	?= $(or $(SIZE),100)	# GiB
15BLOCK_SIZE	?= $(or $(STEP),256)	# MiB
16BATCH_SIZE	?= 1	# blocks
17DIRECT_IO	?= yes	# unset to disable O_DIRECT
18SYNC_IO		?= no   # set to 'yes' to enable O_SYNC|O_DSYNC|O_RSYNC
19FILE_TYPE	?= syscall
20FILE_RESIZE	?= no
21
22disk2file	?= /stxxl/sd$1/stxxl
23
24DISKS_1by1	?= a b c d
25DISKS_a		?= a
26DISKS_ab	?= a b
27DISKS_abcd	?= a b c d
28
29DISKS_a_ro	?= a
30FLAGS_a_ro	?= R
31
32DISKS		?= abcd $(DISKS_1by1) ab a_ro
33
34SIP_NUM_BLOCKS	?= 0
35SIP_CHUNK_BLOCKS?= 1
36SIP_BLOCK_SIZE	?= 0
37
38DISKBENCH_TITLE	?= STXXL Disk Benchmark $(DISKNAME) B=$(strip $(BATCH_SIZE))x$(call format_block_size,$(BLOCK_SIZE)) @ $(HOST)
39DISKAVG_TITLE	?= STXXL Disk Benchmark $(DISKNAME) @ $(HOST)$(if $(DISKNAME2),\n$(DISKNAME2))
40
41ifndef MISC_BINDIR
42MISC_BINDIR	:= $(dir $(lastword $(MAKEFILE_LIST)))
43endif
44DISKBENCH_BINDIR?= $(MISC_BINDIR)/../io
45DISKBENCH	?= benchmark_disks.stxxl.bin
46SCATTERINPLACE	?= iobench_scatter_in_place.stxxl.bin
47
48ECHO		?= echo
49pipefail	?= set -o pipefail;
50
51$(foreach d,$(DISKS_1by1),$(eval DISKS_$d ?= $d))
52
53ifeq ($(SHELL),/bin/sh)
54SHELL		 = bash
55endif
56
57DISKBENCH_FLAGS	+= $(if $(filter y yes Y YES,$(DIRECT_IO)),,--no-direct)
58DISKBENCH_FLAGS	+= $(if $(filter y yes Y YES,$(SYNC_IO)),--sync)
59DISKBENCH_FLAGS	+= --file-type=$(strip $(FILE_TYPE))
60DISKBENCH_FLAGS	+= $(if $(filter y yes Y YES,$(FILE_RESIZE)),--resize)
61
62define do-some-disks
63	$(if $(filter ???,$(strip $(BLOCK_SIZE))),$(error ERROR: BLOCK_SIZE=$(strip $(BLOCK_SIZE))))
64	-$(pipefail) \
65	$(if $(IOSTAT_PLOT_RECORD_DATA),$(IOSTAT_PLOT_RECORD_DATA) -p $(@:.log=)) \
66	$(DISKBENCH_BINDIR)/$(DISKBENCH) $(DISKBENCH_FLAGS) 0 $(strip $(FILE_SIZE)) $(strip $(BLOCK_SIZE)) $(strip $(BATCH_SIZE)) $(FLAGS_$*) $(FLAGS_EX) $(foreach d,$(DISKS_$*),$(call disk2file,$d)) | tee $@
67
68endef
69
70define do-some-disks-sip
71	-$(pipefail) \
72	$(if $(IOSTAT_PLOT_RECORD_DATA),$(IOSTAT_PLOT_RECORD_DATA) -p $(@:.log=)) \
73	$(DISKBENCH_BINDIR)/$(SCATTERINPLACE) $(strip $(SIP_NUM_BLOCKS)) $(strip $(SIP_CHUNK_BLOCKS)) $(strip $(SIP_BLOCK_SIZE)) $(foreach d,$(DISKS_$*),$(call disk2file,$d)) | tee $@
74
75endef
76
77$(HOST)-%.cr.log:
78	$(if $(keep-old-file),,$(RM) $(foreach d,$(DISKS_$*),$(call disk2file,$d)))
79	$(do-some-disks)
80
81$(HOST)-%.crx.log: FLAGS_EX = W
82$(HOST)-%.crx.log:
83	$(if $(keep-old-file),,$(RM) $(foreach d,$(DISKS_$*),$(call disk2file,$d)))
84	$(do-some-disks)
85
86# interleaved write-read-test
87$(HOST)-%.wr.log:
88	$(do-some-disks)
89
90# scanning write
91$(HOST)-%.wrx.log: FLAGS_EX = W
92$(HOST)-%.wrx.log:
93	$(do-some-disks)
94
95# scanning read
96$(HOST)-%.rdx.log: FLAGS_EX = R
97$(HOST)-%.rdx.log:
98	$(do-some-disks)
99
100# scatter-in-place
101$(HOST)-%.sip.log:
102	$(do-some-disks-sip)
103
104all: crx wr ex
105
106crx: $(foreach d,$(DISKS_1by1),$(HOST)-$d.crx.log)
107cr: $(foreach d,$(DISKS_1by1),$(HOST)-$d.cr.log)
108cr+: $(foreach d,$(DISKS),$(HOST)-$d.crx.log)
109wr: $(foreach d,$(DISKS),$(HOST)-$d.wr.log)
110wrx: $(foreach d,$(DISKS_1by1),$(HOST)-$d.wrx.log)
111wr+: $(foreach d,$(DISKS),$(HOST)-$d.wrx.log)
112rdx: $(foreach d,$(DISKS_1by1),$(HOST)-$d.rdx.log)
113rd+: $(foreach d,$(DISKS),$(HOST)-$d.rdx.log)
114ex: $(foreach d,$(DISKS_1by1),$(HOST)-$d.wrx.log $(HOST)-$d.rdx.log)
115ex+: $(foreach d,$(DISKS),$(HOST)-$d.wrx.log $(HOST)-$d.rdx.log)
116sip: $(foreach d,$(DISKS_1by1),$(HOST)-$d.sip.log)
117
118all-sizes-targets	?= cr+ wr ex+
119all-sizes:
120	for d in $(wildcard 0016iMB 0064MB 0004MB 0256MB 0001MB 1024MB *MB) ; do make -C $$d $(all-sizes-targets) ; done
121
122all-sizes-raw: keep-old-file=1
123all-sizes-raw: all-sizes
124
125plot: $(HOST).gnuplot
126	gnuplot $<
127
128dotplot: $(HOST).d.gnuplot
129	gnuplot $<
130
131avgplot: $(HOST)-avg.gnuplot
132	gnuplot $<
133
134avg3plot: $(HOST)-avg3.gnuplot
135	gnuplot $<
136
137# $1 = logfile, $2 = column
138extract_average	= $(if $(wildcard $1),$(shell grep ' Average over ' $1 | awk '{ print $$($2+1) }'),......)
139
140# $1 = logfile, $2 = disk, $3 = column, $4 = label
141# (does not plot if avg = nan)
142define plotline
143	$(if $(wildcard $1),$(if $(filter nan,$(call extract_average,$1,$3)),,$(ECHO) '        "$1" using ($$3/1024):($$$3) w l title "$2 $4 ($(call extract_average,$1,$3))", \' >> $@))
144
145endef
146
147# $1 = logfile, $2 = disk
148define plotline-cr1
149	$(call plotline,$1,$2,7,cr1)
150endef
151define plotline-cr
152	$(call plotline,$1,$2,7,cr)
153endef
154define plotline-crx
155	$(call plotline,$1,$2,7,crx)
156endef
157define plotline-wr
158	$(call plotline,$1,$2,7,wr)
159endef
160define plotline-rd
161	$(call plotline,$1,$2,14,rd)
162endef
163define plotline-wrx
164	$(call plotline,$1,$2,7,wrx)
165endef
166define plotline-rdx
167	$(call plotline,$1,$2,14,rdx)
168endef
169
170# $1 = disk letter
171disk2label	?= sd$1
172disks2label	?= sd[$1]
173
174DISKNAME	?= unknown disk
175DISKNAME2	?=# optional second line describing the test environment
176PLOTXMAX	?= 475
177PLOTYMAX	?= 120
178AVGPLOTYMAX	?= $(PLOTYMAX)
179
180fmt_block_size_2560000B		?= 2.5
181fmt_block_size_12800000B	?= 12.5
182fmt_block_size_51200000B	?= 50
183format_block_size = $(or $(fmt_block_size_$(strip $1)),$(strip $1))MiB
184
185$(HOST).gnuplot: $(MAKEFILE_LIST) $(wildcard *.log)
186	$(RM) $@
187	$(ECHO) 'set title "$(DISKBENCH_TITLE)"' >> $@
188	$(ECHO) 'set xlabel "Disk offset [GiB]"' >> $@
189	$(ECHO) 'set ylabel "Bandwidth per disk [MiB/s]"' >> $@
190	$(ECHO) '' >> $@
191
192	$(ECHO) 'plot [0:$(PLOTXMAX)] [0:$(PLOTYMAX)] \' >> $@
193	$(foreach d,$(DISKS_1by1),\
194		$(call plotline-cr1,$(HOST)-$d.cr1.log,$(call disk2label,$d)) \
195		$(call plotline-crx,$(HOST)-$d.crx.log,$(call disk2label,$d)) \
196		$(call plotline-cr,$(HOST)-$d.cr.log,$(call disk2label,$d)) \
197		$(call plotline-wr,$(HOST)-$d.wr1.log,$(call disk2label,$d)) \
198		$(call plotline-rd,$(HOST)-$d.wr1.log,$(call disk2label,$d)) \
199		$(call plotline-wr,$(HOST)-$d.wr.log,$(call disk2label,$d)) \
200		$(call plotline-rd,$(HOST)-$d.wr.log,$(call disk2label,$d)) \
201		$(call plotline-wrx,$(HOST)-$d.wrx.log,$(call disk2label,$d)) \
202		$(call plotline-rdx,$(HOST)-$d.rdx.log,$(call disk2label,$d)) \
203	)
204	$(foreach d,$(filter-out $(DISKS_1by1),$(DISKS)),\
205		$(call plotline-crx,$(HOST)-$d.crx.log,$(call disks2label,$d)) \
206		$(call plotline-wr,$(HOST)-$d.wr.log,$(call disks2label,$d)) \
207		$(call plotline-rd,$(HOST)-$d.wr.log,$(call disks2label,$d)) \
208		$(call plotline-wrx,$(HOST)-$d.wrx.log,$(call disks2label,$d)) \
209		$(call plotline-rdx,$(HOST)-$d.rdx.log,$(call disks2label,$d)) \
210	)
211	$(ECHO) '        "nothing" notitle' >> $@
212
213	$(ECHO) '' >> $@
214	$(ECHO) 'pause -1' >> $@
215	$(ECHO) '' >> $@
216	$(ECHO) 'set title "$(call GNUPLOT_PS_STRING_ESCAPE,$(DISKBENCH_TITLE))"' >> $@
217	$(ECHO) 'set term postscript enhanced $(GNUPLOT_PS_COLOR) 10' >> $@
218	$(ECHO) 'set output "$(HOST).ps"' >> $@
219	$(ECHO) '$(GNUPLOTFILEINFO)' >> $@
220	$(ECHO) 'replot' >> $@
221
222$(HOST).d.gnuplot: $(HOST).gnuplot
223	sed -e 's/ w l / w d lw 2 /' $< > $@
224
225$(HOST)-avg.dat: $(MISC_BINDIR)/diskbench-avgdat.sh $(wildcard *KB/*.log *MB/*.log)
226	$(MISC_BINDIR)/diskbench-avgdat.sh $(wildcard *KB *MB) > $@
227
228$(HOST)-avg.gnuplot: $(HOST)-avg.dat $(MAKEFILE_LIST)
229	$(RM) $@
230	$(ECHO) 'set title "$(DISKAVG_TITLE)"' >> $@
231	$(ECHO) 'set xlabel "Block Size [MiB]"' >> $@
232	$(ECHO) 'set ylabel "Average Sequential Bandwidth [MiB/s]"' >> $@
233	$(ECHO) 'set key bottom' >> $@
234	$(ECHO) '' >> $@
235
236	$(ECHO) 'plot [] [0:$(AVGPLOTYMAX)] \' >> $@
237	$(ECHO) '        "$(HOST)-avg.dat" using 0:2:xtic(1) w lp lt 1 pt 1 title "crx", \' >> $@
238	$(ECHO) '        "$(HOST)-avg.dat" using 0:3:xtic(1) w lp lt 2 pt 2 title "wr", \' >> $@
239	$(ECHO) '        "$(HOST)-avg.dat" using 0:4:xtic(1) w lp lt 3 pt 3 title "rd", \' >> $@
240	$(ECHO) '        "$(HOST)-avg.dat" using 0:5:xtic(1) w lp lt 4 pt 4 title "wrx", \' >> $@
241	$(ECHO) '        "$(HOST)-avg.dat" using 0:6:xtic(1) w lp lt 5 pt 5 title "rdx", \' >> $@
242	$(ECHO) '        "nothing" notitle' >> $@
243
244	$(ECHO) '' >> $@
245	$(ECHO) 'pause -1' >> $@
246	$(ECHO) '' >> $@
247	$(ECHO) 'set term png size 800,600' >> $@
248	$(ECHO) 'set output "$(HOST)-avg.png"' >> $@
249	$(ECHO) 'replot' >> $@
250	$(ECHO) '' >> $@
251	$(ECHO) 'set title "$(call GNUPLOT_PS_STRING_ESCAPE,$(DISKAVG_TITLE))"' >> $@
252	$(ECHO) 'set term postscript enhanced $(GNUPLOT_PS_COLOR)' >> $@
253	$(ECHO) 'set output "$(HOST)-avg.ps"' >> $@
254	$(ECHO) '$(GNUPLOTFILEINFO)' >> $@
255	$(ECHO) 'replot' >> $@
256
257$(HOST)-avg3.gnuplot: $(HOST)-avg.gnuplot
258	grep -v -E '0:[34]:xtic' $< | sed -e 's/"crx"/"create"/g;s/"wrx"/"write"/g;s/"rdx"/"read"/g;/set output/s/-avg\./-avg3./g' > $@
259
260-include iostat-plot.mk
261
262