3 # Bench backup block-job
5 # Copyright (c) 2020 Virtuozzo International GmbH.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from results_to_text
import results_to_text
26 from bench_block_job
import bench_block_copy
, drv_file
, drv_nbd
29 def bench_func(env
, case
):
30 """ Handle one "cell" of benchmarking table. """
31 cmd_options
= env
['cmd-options'] if 'cmd-options' in env
else {}
32 return bench_block_copy(env
['qemu-binary'], env
['cmd'],
34 case
['source'], case
['target'])
43 label
, path
= d
.split(':') # paths with colon not supported
44 sources
[label
] = drv_file(path
+ '/test-source')
45 targets
[label
] = drv_file(path
+ '/test-target')
48 nbd
= args
.nbd
.split(':')
50 port
= '10809' if len(nbd
) == 1 else nbd
[1]
51 drv
= drv_nbd(host
, port
)
56 src
, dst
= t
.split(':')
60 'source': sources
[src
],
61 'target': targets
[dst
]
64 binaries
= [] # list of (<label>, <path>, [<options>])
65 for i
, q
in enumerate(args
.env
):
66 name_path
= q
.split(':')
67 if len(name_path
) == 1:
69 path_opts
= name_path
[0].split(',')
71 assert len(name_path
) == 2 # paths with colon not supported
73 path_opts
= name_path
[1].split(',')
75 binaries
.append((label
, path_opts
[0], path_opts
[1:]))
80 for i
, q
in enumerate(args
.env
):
86 # path with colon inside is not supported
87 label
, path
= label_path
.split(':')
88 bin_paths
[label
] = path
89 elif label_path
in bin_paths
:
91 path
= bin_paths
[label
]
95 bin_paths
[label
] = path
102 elif opt
== 'copy-range=on':
103 x_perf
['use-copy-range'] = True
104 elif opt
== 'copy-range=off':
105 x_perf
['use-copy-range'] = False
106 elif opt
.startswith('max-workers='):
107 x_perf
['max-workers'] = int(opt
.split('=')[1])
112 'id': f
'mirror({label})',
113 'cmd': 'blockdev-mirror',
118 'id': f
'backup({label})\n' + '\n'.join(opts
),
119 'cmd': 'blockdev-backup',
120 'cmd-options': {'x-perf': x_perf
} if x_perf
else {},
124 result
= simplebench
.bench(bench_func
, test_envs
, test_cases
, count
=3)
125 with
open('results.json', 'w') as f
:
126 json
.dump(result
, f
, indent
=4)
127 print(results_to_text(result
))
130 class ExtendAction(argparse
.Action
):
131 def __call__(self
, parser
, namespace
, values
, option_string
=None):
132 items
= getattr(namespace
, self
.dest
) or []
134 setattr(namespace
, self
.dest
, items
)
137 if __name__
== '__main__':
138 p
= argparse
.ArgumentParser('Backup benchmark', epilog
='''
141 (LABEL:PATH|LABEL|PATH)[,max-workers=N][,use-copy-range=(on|off)][,mirror]
143 LABEL short name for the binary
144 PATH path to the binary
145 max-workers set x-perf.max-workers of backup job
146 use-copy-range set x-perf.use-copy-range of backup job
147 mirror use mirror job instead of backup''',
148 formatter_class
=argparse
.RawTextHelpFormatter
)
149 p
.add_argument('--env', nargs
='+', help='''\
150 Qemu binaries with labels and options, see below
151 "ENV format" section''',
153 p
.add_argument('--dir', nargs
='+', help='''\
154 Directories, each containing "test-source" and/or
155 "test-target" files, raw images to used in
156 benchmarking. File path with label, like
157 label:/path/to/directory''',
159 p
.add_argument('--nbd', help='''\
160 host:port for remote NBD image, (or just host, for
161 default port 10809). Use it in tests, label is "nbd"
162 (but you cannot create test nbd:nbd).''')
163 p
.add_argument('--test', nargs
='+', help='''\
164 Tests, in form source-dir-label:target-dir-label''',
167 bench(p
.parse_args())