1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-04 08:22:13 +03:00

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 <siddhesh@sourceware.org>
This commit is contained in:
Naohiro Tamura
2021-09-13 09:04:21 +05:30
committed by Siddhesh Poyarekar
parent abd383584b
commit 3886eaff9d

View File

@@ -31,6 +31,7 @@ import json
import matplotlib as mpl import matplotlib as mpl
import numpy as np import numpy as np
import os import os
import sys
try: try:
import jsonschema as validator import jsonschema as validator
@@ -331,8 +332,11 @@ def main(args):
for filename in args.bench: for filename in args.bench:
bench = None bench = None
with open(filename, "r") as f: if filename == '-':
bench = json.load(f) bench = json.load(sys.stdin)
else:
with open(filename, "r") as f:
bench = json.load(f)
validator.validate(bench, schema) validator.validate(bench, schema)
@@ -354,7 +358,8 @@ if __name__ == "__main__":
# Required parameter # Required parameter
parser.add_argument("bench", nargs="+", 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 # Optional parameters
parser.add_argument("-b", "--baseline", type=str, parser.add_argument("-b", "--baseline", type=str,