From nobody Wed Dec 17 21:47:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163172980322367.1510062528007; Wed, 15 Sep 2021 11:16:43 -0700 (PDT) Received: from localhost ([::1]:45872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQZSa-000429-Ma for importer@patchew.org; Wed, 15 Sep 2021 14:16:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQZ6o-0006vd-5X for qemu-devel@nongnu.org; Wed, 15 Sep 2021 13:54:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQZ6k-0006yo-Cs for qemu-devel@nongnu.org; Wed, 15 Sep 2021 13:54:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-JFOYivlhPoKjWS5WcJ2Nbg-1; Wed, 15 Sep 2021 13:54:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3246C1084683; Wed, 15 Sep 2021 17:53:59 +0000 (UTC) Received: from localhost (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3ACB77BF5; Wed, 15 Sep 2021 17:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631728445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tp9T3gUpiqm09jJvfntCGMWWH/0DFA5yq3rv2TX7cNc=; b=fVf6YvLY5+mUimaAi+vHUDP0VItLkrb6iWue1SmYO05G3JPHph2FAawAssQGFN0UiuXBC3 4BgOneedw91oU6ynun+PC7gOsWuvksRWfVi/rJlP/l1td9K7ZZJZtTVJurhLuCgsj3i5SM bj5Lr9AL/jH8Jm6Ohepwgc3W6jAZgr8= X-MC-Unique: JFOYivlhPoKjWS5WcJ2Nbg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PULL 18/32] simplebench: add img_bench_templater.py Date: Wed, 15 Sep 2021 19:53:04 +0200 Message-Id: <20210915175318.853225-19-hreitz@redhat.com> In-Reply-To: <20210915175318.853225-1-hreitz@redhat.com> References: <20210915175318.853225-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Hanna Reitz , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631729804954100001 From: Vladimir Sementsov-Ogievskiy Add simple grammar-parsing template benchmark. New tool consume test template written in bash with some special grammar injections and produces multiple tests, run them and finally print a performance comparison table of different tests produced from one template. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210824101517.59802-2-vsementsov@virtuozzo.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- scripts/simplebench/img_bench_templater.py | 95 ++++++++++++++++++++++ scripts/simplebench/table_templater.py | 62 ++++++++++++++ 2 files changed, 157 insertions(+) create mode 100755 scripts/simplebench/img_bench_templater.py create mode 100644 scripts/simplebench/table_templater.py diff --git a/scripts/simplebench/img_bench_templater.py b/scripts/simpleben= ch/img_bench_templater.py new file mode 100755 index 0000000000..f8e1540ada --- /dev/null +++ b/scripts/simplebench/img_bench_templater.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# +# Process img-bench test templates +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + + +import sys +import subprocess +import re +import json + +import simplebench +from results_to_text import results_to_text +from table_templater import Templater + + +def bench_func(env, case): + test =3D templater.gen(env['data'], case['data']) + + p =3D subprocess.run(test, shell=3DTrue, stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, universal_newlines=3DTr= ue) + + if p.returncode =3D=3D 0: + try: + m =3D re.search(r'Run completed in (\d+.\d+) seconds.', p.stdo= ut) + return {'seconds': float(m.group(1))} + except Exception: + return {'error': f'failed to parse qemu-img output: {p.stdout}= '} + else: + return {'error': f'qemu-img failed: {p.returncode}: {p.stdout}'} + + +if __name__ =3D=3D '__main__': + if len(sys.argv) > 1: + print(""" +Usage: img_bench_templater.py < path/to/test-template.sh + +This script generates performance tests from a test template (example belo= w), +runs them, and displays the results in a table. The template is read from +stdin. It must be written in bash and end with a `qemu-img bench` invocat= ion +(whose result is parsed to get the test instance=E2=80=99s result). + +Use the following syntax in the template to create the various different t= est +instances: + + column templating: {var1|var2|...} - test will use different values in + different columns. You may use several {} constructions in the test, in = this + case product of all choice-sets will be used. + + row templating: [var1|var2|...] - similar thing to define rows (test-cas= es) + +Test template example: + +Assume you want to compare two qemu-img binaries, called qemu-img-old and +qemu-img-new in your build directory in two test-cases with 4K writes and = 64K +writes. The template may look like this: + +qemu_img=3D/path/to/qemu/build/qemu-img-{old|new} +$qemu_img create -f qcow2 /ssd/x.qcow2 1G +$qemu_img bench -c 100 -d 8 [-s 4K|-s 64K] -w -t none -n /ssd/x.qcow2 + +When passing this to stdin of img_bench_templater.py, the resulting compar= ison +table will contain two columns (for two binaries) and two rows (for two +test-cases). + +In addition to displaying the results, script also stores results in JSON +format into results.json file in current directory. +""") + sys.exit() + + templater =3D Templater(sys.stdin.read()) + + envs =3D [{'id': ' / '.join(x), 'data': x} for x in templater.columns] + cases =3D [{'id': ' / '.join(x), 'data': x} for x in templater.rows] + + result =3D simplebench.bench(bench_func, envs, cases, count=3D5, + initial_run=3DFalse) + print(results_to_text(result)) + with open('results.json', 'w') as f: + json.dump(result, f, indent=3D4) diff --git a/scripts/simplebench/table_templater.py b/scripts/simplebench/t= able_templater.py new file mode 100644 index 0000000000..950f3b3024 --- /dev/null +++ b/scripts/simplebench/table_templater.py @@ -0,0 +1,62 @@ +# Parser for test templates +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import itertools +from lark import Lark + +grammar =3D """ +start: ( text | column_switch | row_switch )+ + +column_switch: "{" text ["|" text]+ "}" +row_switch: "[" text ["|" text]+ "]" +text: /[^|{}\[\]]+/ +""" + +parser =3D Lark(grammar) + +class Templater: + def __init__(self, template): + self.tree =3D parser.parse(template) + + c_switches =3D [] + r_switches =3D [] + for x in self.tree.children: + if x.data =3D=3D 'column_switch': + c_switches.append([el.children[0].value for el in x.childr= en]) + elif x.data =3D=3D 'row_switch': + r_switches.append([el.children[0].value for el in x.childr= en]) + + self.columns =3D list(itertools.product(*c_switches)) + self.rows =3D list(itertools.product(*r_switches)) + + def gen(self, column, row): + i =3D 0 + j =3D 0 + result =3D [] + + for x in self.tree.children: + if x.data =3D=3D 'text': + result.append(x.children[0].value) + elif x.data =3D=3D 'column_switch': + result.append(column[i]) + i +=3D 1 + elif x.data =3D=3D 'row_switch': + result.append(row[j]) + j +=3D 1 + + return ''.join(result) --=20 2.31.1