From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
qemu-devel@nongnu.org, mreitz@redhat.com,
andrey.shinkevich@virtuozzo.com, den@openvz.org
Subject: [PATCH v3 2/3] scripts/simplebench: allow writing to non-empty image
Date: Sun, 12 Jul 2020 20:17:13 +0300 [thread overview]
Message-ID: <1594574234-73535-3-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1594574234-73535-1-git-send-email-andrey.shinkevich@virtuozzo.com>
Add 'empty_image' parameter to the function bench_write_req() and to
the test cases that will allow writing to the non-empty clusters of the
image if the 'empty_image' parameter set to False.
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
scripts/simplebench/bench_write_req.py | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/scripts/simplebench/bench_write_req.py b/scripts/simplebench/bench_write_req.py
index c61c8d2..ceb0ab6 100755
--- a/scripts/simplebench/bench_write_req.py
+++ b/scripts/simplebench/bench_write_req.py
@@ -29,7 +29,7 @@ def bench_func(env, case):
""" Handle one "cell" of benchmarking table. """
return bench_write_req(env['qemu_img'], env['image_name'],
case['block_size'], case['block_offset'],
- case['requests'])
+ case['requests'], case['empty_image'])
def qemu_img_pipe(*args):
@@ -45,7 +45,8 @@ def qemu_img_pipe(*args):
return subp.communicate()[0]
-def bench_write_req(qemu_img, image_name, block_size, block_offset, requests):
+def bench_write_req(qemu_img, image_name, block_size, block_offset, requests,
+ empty_image):
"""Benchmark write requests
The function creates a QCOW2 image with the given path/name and fills it
@@ -58,6 +59,7 @@ def bench_write_req(qemu_img, image_name, block_size, block_offset, requests):
block_size -- size of a block to write to clusters
block_offset -- offset of the block in clusters
requests -- number of write requests per cluster
+ empty_image -- if not True, fills image with random data
Returns {'seconds': int} on success and {'error': str} on failure.
Return value is compatible with simplebench lib.
@@ -107,6 +109,15 @@ def bench_write_req(qemu_img, image_name, block_size, block_offset, requests):
try:
qemu_img_pipe(*args_create)
+
+ if not empty_image:
+ dd = ['dd', 'if=/dev/urandom', f'of={image_name}',
+ f'bs={cluster_size}', f'seek={seek}',
+ f'count={dd_count}']
+ devnull = open('/dev/null', 'w')
+ subprocess.run(dd, stderr=devnull, stdout=devnull)
+ subprocess.run('sync')
+
except OSError as e:
os.remove(image_name)
return {'error': 'qemu_img create failed: ' + str(e)}
@@ -141,25 +152,29 @@ if __name__ == '__main__':
'id': '<simple case>',
'block_size': 0,
'block_offset': 0,
- 'requests': 10
+ 'requests': 10,
+ 'empty_image': True
},
{
'id': '<general case>',
'block_size': 4096,
'block_offset': 0,
- 'requests': 10
+ 'requests': 10,
+ 'empty_image': True
},
{
'id': '<cluster middle>',
'block_size': 4096,
'block_offset': 524288,
- 'requests': 10
+ 'requests': 10,
+ 'empty_image': True
},
{
'id': '<cluster overlap>',
'block_size': 524288,
'block_offset': 4096,
- 'requests': 2
+ 'requests': 2,
+ 'empty_image': True
},
]
--
1.8.3.1
next prev parent reply other threads:[~2020-07-12 17:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-12 17:17 [PATCH v3 0/3] scripts/simplebench: add bench_write_req.py test Andrey Shinkevich
2020-07-12 17:17 ` [PATCH v3 1/3] scripts/simplebench: compare write request performance Andrey Shinkevich
2020-07-12 17:17 ` Andrey Shinkevich [this message]
2020-07-12 17:17 ` [PATCH v3 3/3] scripts/simplebench: add unaligned data case to bench_write_req Andrey Shinkevich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1594574234-73535-3-git-send-email-andrey.shinkevich@virtuozzo.com \
--to=andrey.shinkevich@virtuozzo.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).