mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
New module to import and process benchmark output
This is the beginning of a module to import and process benchmark outputs. The module currently supports importing of a bench.out and validating it against a schema file. In future this could grow a set of routines that benchmark consumers may find useful to build their own analysis tools. I have altered validate_bench to use this module too. * benchtests/scripts/import_bench.py: New file. * benchtests/scripts/validate_benchout.py: Import import_bench instead of jsonschema. (validate_bench): Remove function. (main): Use import_bench.
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
2015-06-01 Siddhesh Poyarekar <siddhesh@redhat.com>
|
||||||
|
|
||||||
|
* benchtests/scripts/import_bench.py: New file.
|
||||||
|
* benchtests/scripts/validate_benchout.py: Import import_bench
|
||||||
|
instead of jsonschema.
|
||||||
|
(validate_bench): Remove function.
|
||||||
|
(main): Use import_bench.
|
||||||
|
|
||||||
2015-06-01 Steve Ellcey <sellcey@imgtec.com>
|
2015-06-01 Steve Ellcey <sellcey@imgtec.com>
|
||||||
|
|
||||||
* resolv/res_hconf.c (_res_hconf_reorder_addrs): Use a union to
|
* resolv/res_hconf.c (_res_hconf_reorder_addrs): Use a union to
|
||||||
|
45
benchtests/scripts/import_bench.py
Normal file
45
benchtests/scripts/import_bench.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Copyright (C) 2015 Free Software Foundation, Inc.
|
||||||
|
# This file is part of the GNU C Library.
|
||||||
|
#
|
||||||
|
# The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# The GNU C Library 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
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with the GNU C Library; if not, see
|
||||||
|
# <http://www.gnu.org/licenses/>.
|
||||||
|
"""Functions to import benchmark data and process it"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
try:
|
||||||
|
import jsonschema as validator
|
||||||
|
except ImportError:
|
||||||
|
print('Could not find jsonschema module.')
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def parse_bench(filename, schema_filename):
|
||||||
|
"""Parse the input file
|
||||||
|
|
||||||
|
Parse and validate the json file containing the benchmark outputs. Return
|
||||||
|
the resulting object.
|
||||||
|
Args:
|
||||||
|
filename: Name of the benchmark output file.
|
||||||
|
Return:
|
||||||
|
The bench dictionary.
|
||||||
|
"""
|
||||||
|
with open(schema_filename, 'r') as schemafile:
|
||||||
|
schema = json.load(schemafile)
|
||||||
|
with open(filename, 'r') as benchfile:
|
||||||
|
bench = json.load(benchfile)
|
||||||
|
validator.validate(bench, schema)
|
||||||
|
do_for_all_timings(bench, lambda b, f, v:
|
||||||
|
b['functions'][f][v]['timings'].sort())
|
||||||
|
return bench
|
@ -27,37 +27,26 @@ import sys
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import jsonschema
|
import import_bench as bench
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print('Could not find jsonschema module. Output not validated.')
|
print('Import Error: Output will not be validated.')
|
||||||
# Return success because we don't want the bench target to fail just
|
# Return success because we don't want the bench target to fail just
|
||||||
# because the jsonschema module was not found.
|
# because the jsonschema module was not found.
|
||||||
sys.exit(os.EX_OK)
|
sys.exit(os.EX_OK)
|
||||||
|
|
||||||
|
|
||||||
def validate_bench(benchfile, schemafile):
|
def print_and_exit(message, exitcode):
|
||||||
"""Validate benchmark file
|
"""Prints message to stderr and returns the exit code.
|
||||||
|
|
||||||
Validate a benchmark output file against a JSON schema.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
benchfile: The file name of the bench.out file.
|
message: The message to print
|
||||||
schemafile: The file name of the JSON schema file to validate
|
exitcode: The exit code to return
|
||||||
bench.out against.
|
|
||||||
|
|
||||||
Exceptions:
|
Returns:
|
||||||
jsonschema.ValidationError: When bench.out is not valid
|
The passed exit code
|
||||||
jsonschema.SchemaError: When the JSON schema is not valid
|
|
||||||
IOError: If any of the files are not found.
|
|
||||||
"""
|
"""
|
||||||
with open(benchfile, 'r') as bfile:
|
print(message, file=sys.stderr)
|
||||||
with open(schemafile, 'r') as sfile:
|
return exitcode
|
||||||
bench = json.load(bfile)
|
|
||||||
schema = json.load(sfile)
|
|
||||||
jsonschema.validate(bench, schema)
|
|
||||||
|
|
||||||
# If we reach here, we're all good.
|
|
||||||
print("Benchmark output in %s is valid." % benchfile)
|
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
@ -73,11 +62,23 @@ def main(args):
|
|||||||
Exceptions thrown by validate_bench
|
Exceptions thrown by validate_bench
|
||||||
"""
|
"""
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
print("Usage: %s <bench.out file> <bench.out schema>" % sys.argv[0],
|
return print_and_exit("Usage: %s <bench.out file> <bench.out schema>"
|
||||||
file=sys.stderr)
|
% sys.argv[0], os.EX_USAGE)
|
||||||
return os.EX_USAGE
|
|
||||||
|
|
||||||
validate_bench(args[0], args[1])
|
try:
|
||||||
|
bench.parse_bench(args[0], args[1])
|
||||||
|
except IOError as e:
|
||||||
|
return print_and_exit("IOError(%d): %s" % (e.errno, e.strerror),
|
||||||
|
os.EX_OSFILE)
|
||||||
|
|
||||||
|
except bench.validator.ValidationError as e:
|
||||||
|
return print_and_exit("Invalid benchmark output: %s" % e.message,
|
||||||
|
os.EX_DATAERR)
|
||||||
|
|
||||||
|
except bench.validator.SchemaError as e:
|
||||||
|
return print_and_exit("Invalid schema: %s" % e.message, os.EX_DATAERR)
|
||||||
|
|
||||||
|
print("Benchmark output in %s is valid." % args[0])
|
||||||
return os.EX_OK
|
return os.EX_OK
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user