From patchwork Fri Jul 13 17:44:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leonardo Sandoval X-Patchwork-Id: 943754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-94271-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="C/xyJsPg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41S0YQ0Mm7z9s2M for ; Sat, 14 Jul 2018 03:44:25 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=mziNUIig0gUwhkIY01eiOggNG+EPnaNtohQ8IMiOb7QxfYZBPv/hO huhF3+d01iobrrtUeogbWM1bJ/NiAySewuzPXWIquIr3yxoEGIjf+ilfsqB3T3Dj GxewJeg5wMTwHI1+85pWqXQLixZuk8cg2Z971EdTo/88e3ieuMwtzM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=FsLDBHRYbjYqkkbFBSAPCgZ0nGI=; b=C/xyJsPgB+n41ZNJ/AsPsFV2642D kzqI3DZRUHtxdbgVTCAsgo3YMz8LI10TJxrfCCPBH589Fv1HuUziFQrMSDaUk+Ol R/bnIP0H1qXdSRXuLEIupWDcD7grNkwXkHGhwJR7rABcV9FKJQaCHrPTqI6kHS47 lFTXeP8tDOZlsrs= Received: (qmail 103166 invoked by alias); 13 Jul 2018 17:44:20 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 103072 invoked by uid 89); 13 Jul 2018 17:44:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=timing, HContent-Transfer-Encoding:8bit X-HELO: mga01.intel.com From: leonardo.sandoval.gonzalez@linux.intel.com To: libc-alpha@sourceware.org Cc: hjl.tools@gmail.com, siddhesh@gotplt.org, Leonardo Sandoval Subject: [PATCH] benchtests: improve argument parsing through argparse library Date: Fri, 13 Jul 2018 12:44:17 -0500 Message-Id: <20180713174417.13661-1-leonardo.sandoval.gonzalez@linux.intel.com> MIME-Version: 1.0 From: Leonardo Sandoval The argparse library is used on compare_bench script to improve command line argument parsing. The 'schema validation file' is now optional, reducing by one the number of required parameters. * benchtests/scripts/compare_bench.py (__main__): use the argparse library to improve command line parsing. (__main__): make schema file as optional parameter (--schema), defaulting to benchtests/scripts/benchout.schema.json. (main): move out of the parsing stuff to __main_  and leave it only as caller of main comparison functions. --- benchtests/scripts/compare_bench.py | 40 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/benchtests/scripts/compare_bench.py b/benchtests/scripts/compare_bench.py index ea25f778c09..88e8911d812 100755 --- a/benchtests/scripts/compare_bench.py +++ b/benchtests/scripts/compare_bench.py @@ -25,6 +25,7 @@ import sys import os import pylab import import_bench as bench +import argparse def do_compare(func, var, tl1, tl2, par, threshold): """Compare one of the aggregate measurements @@ -151,26 +152,9 @@ def plot_graphs(bench1, bench2): print('Writing out %s' % filename) pylab.savefig(filename) - -def main(args): - """Program Entry Point - - Take two benchmark output files and compare their timings. - """ - if len(args) > 4 or len(args) < 3: - print('Usage: %s [threshold in %%]' % sys.argv[0]) - sys.exit(os.EX_USAGE) - - bench1 = bench.parse_bench(args[1], args[0]) - bench2 = bench.parse_bench(args[2], args[0]) - if len(args) == 4: - threshold = float(args[3]) - else: - threshold = 10.0 - - if (bench1['timing_type'] != bench2['timing_type']): - print('Cannot compare benchmark outputs: timing types are different') - return +def main(bench1, bench2, schema, threshold): + bench1 = bench.parse_bench(bench1, schema) + bench2 = bench.parse_bench(bench2, schema) plot_graphs(bench1, bench2) @@ -181,4 +165,18 @@ def main(args): if __name__ == '__main__': - main(sys.argv[1:]) + parser = argparse.ArgumentParser(description='Take two benchmark and compare their timings.') + + # Required parameters + parser.add_argument('bench1', help='First bench to compare') + parser.add_argument('bench2', help='Second bench to compare') + + # Optional parameters + parser.add_argument('--schema', + default=os.path.join(os.path.dirname(os.path.realpath(__file__)),'benchout.schema.json'), + help='JSON file to validate source/dest files (default: %(default)s)') + parser.add_argument('--threshold', default=10.0, help='Only print those with equal or higher threshold (default: %(default)s)') + + args = parser.parse_args() + + main(args.bench1, args.bench2, args.schema, args.threshold)