| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Benchmark example |
| 4 | # |
| 5 | # Copyright (c) 2019 Virtuozzo International GmbH. |
| 6 | # |
| 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. |
| 11 | # |
| 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. |
| 16 | # |
| 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/>. |
| 19 | # |
| 20 | |
| 21 | import simplebench |
| 22 | from results_to_text import results_to_text |
| 23 | from bench_block_job import bench_block_copy, drv_file, drv_nbd |
| 24 | |
| 25 | |
| 26 | def bench_func(env, case): |
| 27 | """ Handle one "cell" of benchmarking table. """ |
| 28 | return bench_block_copy(env['qemu_binary'], env['cmd'], {}, |
| 29 | case['source'], case['target']) |
| 30 | |
| 31 | |
| 32 | # You may set the following five variables to correct values, to turn this |
| 33 | # example to real benchmark. |
| 34 | ssd_source = '/path-to-raw-source-image-at-ssd' |
| 35 | ssd_target = '/path-to-raw-target-image-at-ssd' |
| 36 | hdd_target = '/path-to-raw-source-image-at-hdd' |
| 37 | nbd_ip = 'nbd-ip-addr' |
| 38 | nbd_port = 'nbd-port-number' |
| 39 | |
| 40 | # Test-cases are "rows" in benchmark resulting table, 'id' is a caption for |
| 41 | # the row, other fields are handled by bench_func. |
| 42 | test_cases = [ |
| 43 | { |
| 44 | 'id': 'ssd -> ssd', |
| 45 | 'source': drv_file(ssd_source), |
| 46 | 'target': drv_file(ssd_target) |
| 47 | }, |
| 48 | { |
| 49 | 'id': 'ssd -> hdd', |
| 50 | 'source': drv_file(ssd_source), |
| 51 | 'target': drv_file(hdd_target) |
| 52 | }, |
| 53 | { |
| 54 | 'id': 'ssd -> nbd', |
| 55 | 'source': drv_file(ssd_source), |
| 56 | 'target': drv_nbd(nbd_ip, nbd_port) |
| 57 | }, |
| 58 | ] |
| 59 | |
| 60 | # Test-envs are "columns" in benchmark resulting table, 'id is a caption for |
| 61 | # the column, other fields are handled by bench_func. |
| 62 | test_envs = [ |
| 63 | { |
| 64 | 'id': 'backup-1', |
| 65 | 'cmd': 'blockdev-backup', |
| 66 | 'qemu_binary': '/path-to-qemu-binary-1' |
| 67 | }, |
| 68 | { |
| 69 | 'id': 'backup-2', |
| 70 | 'cmd': 'blockdev-backup', |
| 71 | 'qemu_binary': '/path-to-qemu-binary-2' |
| 72 | }, |
| 73 | { |
| 74 | 'id': 'mirror', |
| 75 | 'cmd': 'blockdev-mirror', |
| 76 | 'qemu_binary': '/path-to-qemu-binary-1' |
| 77 | } |
| 78 | ] |
| 79 | |
| 80 | result = simplebench.bench(bench_func, test_envs, test_cases, count=3) |
| 81 | print(results_to_text(result)) |