2
0

bench-example.py 2.4 KB

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