1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!/usr/bin/env python3
# ===--- convertToJSON.py ------------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===---------------------------------------------------------------------===//
# This script converts results from pre-commit benchmark tests to JSON.
# Usage: PrecommitBench_O | convertToJSON.py
#
# Input example:
# #,TEST,SAMPLES,MIN(ms),MAX(ms),MEAN(ms),SD(ms),MEDIAN(ms)
# 1,2Sum,1,1318,1318,1318,0,1318
# 2,Ackermann,1,805,805,805,0,805
#
# Totals,2,2123,2123,2123,0,0
#
# Output for this input:
# {
# "Machine": {},
# "Run": {},
# "Tests": [
# {
# "Data": [
# 1318
# ],
# "Info": {},
# "Name": [
# "2Sum"
# ]
# },
# {
# "Data": [
# 805
# ],
# "Info": {},
# "Name": [
# "Ackermann"
# ]
# },
# {
# "Data": [
# 2123
# ],
# "Info": {},
# "Name": [
# "Totals"
# ]
# }
# ]
# }
import json
import re
import sys
# Parse lines like this
# #,TEST,SAMPLES,MIN(ms),MAX(ms),MEAN(ms),SD(ms),MEDIAN(ms)
SCORERE = re.compile(r"(\d+),[ \t]*(\w+),[ \t]*([\d.]+),[ \t]*([\d.]+)")
# The Totals line would be parsed like this.
TOTALRE = re.compile(r"()(Totals),[ \t]*([\d.]+),[ \t]*([\d.]+)")
KEYGROUP = 2
VALGROUP = 4
if __name__ == "__main__":
data = {}
data["Tests"] = []
data["Machine"] = {}
data["Run"] = {}
for line in sys.stdin:
m = SCORERE.match(line)
if not m:
m = TOTALRE.match(line)
if not m:
continue
test = {}
test["Data"] = [int(m.group(VALGROUP))]
test["Info"] = {}
test["Name"] = [m.group(KEYGROUP)]
data["Tests"].append(test)
print(json.dumps(data, sort_keys=True, indent=4))
|