Commit 09f28959 authored by Igor Merkulow's avatar Igor Merkulow
Browse files

modified metrics spec to simplify parsing, improved specparser

parent 5e1fe275
This diff is collapsed.
#! /usr/bin/env python3
from pprint import pprint as pp
# Data Validation
STR_MIN = 3
STR_MAX = 45
# only lower-case and numbers, no whitespace
LOW_NO_WS = r'[a-z0-9_]+'
UPLO_NO_WS = r'[a-zA-Z0-9_]+' # both cases, numbers, no whitespace
# both cases, numbers, space allowed
UPLO_WITH_WS = r'[a-zA-Z0-9_ \(\)@\.,\-]+'
STR_DEFAULT = {'type': 'string', 'regex': UPLO_NO_WS,
'minlength': STR_MIN, 'maxlength': STR_MAX, 'required': True}
MIO = 1000 * 1000 # one million
INT_TS = 1000 * MIO # was on 9 Sep 2001, so we should get larger values
DUR_MAX = 31556952 # exactly one year, maybe use 365 * 24 * 60 * 60
CU_MAX = 100 * MIO # 100 Mio should be future-proof
NODE_MAX = 10 * MIO # 10 Mio nodes - again, future-proof
MB = 1024 * 1024 # 1 megabyte
MEM_MIN_TOTAL = 100 * MB # less than 100MB is not plausible
# 100TB on a single node should be safe for now
MEM_MAX_TOTAL = MEM_MIN_TOTAL * 1024
MEM_MIN_PROC = 10 * MB
MEM_MAX_PROC = MEM_MIN_PROC * 1024
SAMPL = r"[0-9]+ [h\|m\|s]"
def _convert(name, datatype, unit):
if not name.startswith('`pfit'):
return None
def _convert(name, datatype, constraint, unit, required, label):
res = {}
res['name'] = name[1:-1]
res['name'] = name
res['label'] = label
res['type'] = datatype
# if 'INT-POS0' in unit:
# res['min'] = 0
# elif 'INT-POS' in unit:
# res['min'] = 1
# elif 'FLOAT-POS0' in unit:
# res['min'] = 0
# elif 'STR-EXT' in unit:
# res['minlength'] = 3
# res['maxlength'] = 45
if required in 'yYtT':
res['required'] = True
elif required in 'nNfF':
res['required'] = False
else:
res['required'] = None
if 'INT-POS0' in constraint:
res['min'] = 0
elif 'INT-POS' in constraint:
res['min'] = 1
elif 'INT-TS' in constraint:
res['min'] = INT_TS
elif 'INT-01' in constraint:
res['min'] = 0
res['max'] = 1
elif 'FLOAT-POS0' in constraint:
res['min'] = 0
elif 'FLOAT-PERCENT' in constraint:
res['min'] = 0.0
res['max'] = 1.0
elif 'STR-EXT' in constraint:
res['minlength'] = STR_MIN
res['maxlength'] = STR_MAX
res['regex'] = UPLO_NO_WS
elif 'STR' in constraint:
res['minlength'] = STR_MIN
res['maxlength'] = STR_MAX
res['regex'] = LOW_NO_WS
elif 'MEM-PR' in constraint:
res['min'] = MEM_MIN_PROC
res['max'] = MEM_MAX_PROC
elif 'SAMPL' in constraint:
res['regex'] = SAMPL
elif 'Range' in constraint:
tmp = constraint.split('[')[1].split(']')[0].split(',')
res['min'] = tmp[0]
res['max'] = tmp[1]
else:
print('WARNING: unknown constraint {}...'.format(unit))
if 'BYTE' in unit:
res['unit'] = 'byte(s)'
......@@ -26,8 +80,11 @@ def _convert(name, datatype, unit):
res['unit'] = 'Hz'
elif 'Nanoseconds' in unit:
res['unit'] = 'ns'
elif 'MB per second' in unit:
res['unit'] = 'MB/s'
else:
res['unit'] = None
return res
......@@ -43,7 +100,10 @@ def parse(fname):
if not block:
block = True
ll = l.split('|')
tmp = _convert(ll[1], ll[2], ll[3])
name = ll[1][1:-1]
if not name.startswith('pfit'):
continue
tmp = _convert(name, ll[2], ll[3], ll[4], ll[5], ll[6])
if tmp is not None:
table.append(tmp)
else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment