mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Add JSON file version checks to python scripts.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
@@ -10,6 +9,7 @@ from colorama import Fore
|
||||
|
||||
import tabulate
|
||||
|
||||
from nvbench_json import reader
|
||||
|
||||
# Parse version string into tuple, "x.y.z" -> (x, y, z)
|
||||
def version_tuple(v):
|
||||
@@ -282,9 +282,9 @@ def main():
|
||||
for ref, comp in to_compare:
|
||||
|
||||
with open(ref, "r") as ref_file:
|
||||
ref_root = json.load(ref_file)
|
||||
ref_root = reader.read_file(ref_file)
|
||||
with open(comp, "r") as cmp_file:
|
||||
cmp_root = json.load(cmp_file)
|
||||
cmp_root = reader.read_file(cmp_file)
|
||||
|
||||
global all_devices
|
||||
all_devices = cmp_root["devices"]
|
||||
|
||||
@@ -6,10 +6,10 @@ import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from nvbench_json import reader
|
||||
|
||||
def parse_files():
|
||||
help_text = "%(prog)s [nvbench.out.json | dir/] ..."
|
||||
@@ -76,8 +76,7 @@ def to_df(data):
|
||||
|
||||
|
||||
def parse_json(filename):
|
||||
with open(filename, "r") as f:
|
||||
json_root = json.load(f)
|
||||
json_root = reader.read_file(filename)
|
||||
|
||||
samples_data = {}
|
||||
|
||||
|
||||
1
scripts/nvbench_json/.gitignore
vendored
Normal file
1
scripts/nvbench_json/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__/*
|
||||
2
scripts/nvbench_json/__init__.py
Normal file
2
scripts/nvbench_json/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import reader
|
||||
from . import version
|
||||
10
scripts/nvbench_json/reader.py
Normal file
10
scripts/nvbench_json/reader.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import json
|
||||
|
||||
from . import version
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
with open(filename, "r") as f:
|
||||
file_root = json.load(f)
|
||||
version.check_file_version(filename, file_root)
|
||||
return file_root
|
||||
26
scripts/nvbench_json/version.py
Normal file
26
scripts/nvbench_json/version.py
Normal file
@@ -0,0 +1,26 @@
|
||||
file_version = (1, 0, 0)
|
||||
|
||||
file_version_string = "{}.{}.{}".format(file_version[0],
|
||||
file_version[1],
|
||||
file_version[2])
|
||||
|
||||
|
||||
def check_file_version(filename, root_node):
|
||||
try:
|
||||
version_node = root_node["meta"]["version"]["json"]
|
||||
except KeyError:
|
||||
print("WARNING:")
|
||||
print(" {} is written in an older, unversioned format. ".format(filename))
|
||||
print(" It may not read correctly.")
|
||||
print(" Reader expects JSON file version {}.".format(file_version_string))
|
||||
return
|
||||
|
||||
# TODO We could do something fancy here using semantic versioning, but
|
||||
# for now just warn on mismatch.
|
||||
if version_node["string"] != file_version_string:
|
||||
print("WARNING:")
|
||||
print(" {} was written using a different NVBench JSON file version."
|
||||
.format(filename))
|
||||
print(" It may not read correctly.")
|
||||
print(" (file version: {} reader version: {})"
|
||||
.format(version_node["string"], file_version_string))
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
import argparse
|
||||
import math
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from nvbench_json import reader
|
||||
|
||||
import tabulate
|
||||
|
||||
|
||||
@@ -111,8 +112,7 @@ def append_measure_values(row, measures, active=measure_names):
|
||||
|
||||
|
||||
def consume_file(filename):
|
||||
with open(filename, "r") as f:
|
||||
file_root = json.load(f)
|
||||
file_root = reader.read_file(filename)
|
||||
|
||||
file_out = {}
|
||||
file_measures = init_measures()
|
||||
@@ -349,9 +349,6 @@ def main():
|
||||
data["files"] = files_out
|
||||
data["measures"] = measures
|
||||
|
||||
# Debug data structure:
|
||||
# print(json.dumps(data, indent=2))
|
||||
|
||||
print_overview_section(data)
|
||||
print_files_section(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user