From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 1885D3858425; Thu, 23 Sep 2021 00:44:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1885D3858425 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/unnest] benchtests: Enable scripts/plot_strings.py to read stdin X-Act-Checkin: glibc X-Git-Author: Naohiro Tamura X-Git-Refname: refs/heads/maskray/unnest X-Git-Oldrev: abd383584b16dd0fb1bbf40e4ece65ebe7b839ec X-Git-Newrev: 3886eaff9d5a807732284a562f2d051e5d54fefa Message-Id: <20210923004449.1885D3858425@sourceware.org> Date: Thu, 23 Sep 2021 00:44:49 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2021 00:44:49 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3886eaff9d5a807732284a562f2d051e5d54fefa commit 3886eaff9d5a807732284a562f2d051e5d54fefa Author: Naohiro Tamura Date: Mon Sep 13 09:04:21 2021 +0530 benchtests: Enable scripts/plot_strings.py to read stdin This patch enables scripts/plot_strings.py to read a benchmark result file from stdin. To keep backward compatibility, that is to keep accepting multiple of benchmark result files in argument, blank argument doesn't mean stdin, but '-' does. Therefore nargs parameter of ArgumentParser.add_argument() method is not changed to '?', but keep '+'. ex: $ jq '.' bench-memset.out | plot_strings.py - $ jq '.' bench-memset.out | plot_strings.py - bench-memset-large.out $ plot_strings.py bench-memset.out bench-memset-large.out error ex: $ jq '.' bench-memset.out | plot_strings.py Reviewed-by: Siddhesh Poyarekar Diff: --- benchtests/scripts/plot_strings.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/benchtests/scripts/plot_strings.py b/benchtests/scripts/plot_strings.py index c71f0804e4..ec634692d9 100755 --- a/benchtests/scripts/plot_strings.py +++ b/benchtests/scripts/plot_strings.py @@ -31,6 +31,7 @@ import json import matplotlib as mpl import numpy as np import os +import sys try: import jsonschema as validator @@ -331,8 +332,11 @@ def main(args): for filename in args.bench: bench = None - with open(filename, "r") as f: - bench = json.load(f) + if filename == '-': + bench = json.load(sys.stdin) + else: + with open(filename, "r") as f: + bench = json.load(f) validator.validate(bench, schema) @@ -354,7 +358,8 @@ if __name__ == "__main__": # Required parameter parser.add_argument("bench", nargs="+", - help="benchmark results file(s) in json format") + help="benchmark results file(s) in json format, " \ + "and/or '-' as a benchmark result file from stdin") # Optional parameters parser.add_argument("-b", "--baseline", type=str,