2
0

bench-example.py 2.4 KB

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