Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental extension for metric tracer #291

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 71 additions & 37 deletions scripts/parse_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from templates.helper import param_traits, type_traits, value_traits

default_version = "1.0"
all_versions = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "2.0"]
all_versions = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "2.0"]

"""
preprocess object
Expand Down Expand Up @@ -99,15 +99,7 @@ def __validate_version(d, prefix="", base_version=default_version):
if not isinstance(d['version'], str):
raise Exception(prefix+"'version' must be a string: '%s'"%type(d['version']))

try:
version = str(float(d['version']))
except:
version = None

if version != d['version']:
raise Exception(prefix+"'version' invalid value: '%s'"%d['version'])

return float(d.get('version', base_version))
return d.get('version', base_version)

def __validate_tag(d, key, tags, case):
for x in tags:
Expand All @@ -121,14 +113,6 @@ def __validate_desc(desc):
if not isinstance(k, str):
raise Exception(prefix+"'version' must be a string: '%s'"%type(k))

try:
version = str(float(k))
except:
version = None

if version != k:
raise Exception(prefix+"'version' invalid value: '%s'"%k)

for x in ['[in]', '[out]', '[in,out]']:
if v.startswith(x):
return x
Expand Down Expand Up @@ -197,7 +181,7 @@ def __validate_etors(d, tags):

value = -1
d_ver = d.get('version', default_version)
max_ver = float(d_ver)
max_ver = d_ver
for i, item in enumerate(d['etors']):
prefix="'etors'[%s] "%i
if not isinstance(item, dict):
Expand All @@ -220,7 +204,7 @@ def __validate_etors(d, tags):
ver = __validate_version(item, prefix=prefix, base_version=d_ver)
if item.get('value'):
max_ver = ver
if ver < max_ver:
if _version_compare_less(ver, max_ver):
raise Exception(prefix+"'version' must be increasing: %s"%item['version'])
max_ver = ver

Expand Down Expand Up @@ -250,7 +234,7 @@ def __validate_members(d, tags):
raise Exception("'members' must be a sequence: '%s'"%type(d['members']))

d_ver = d.get('version', default_version)
max_ver = float(d_ver)
max_ver = d_ver
for i, item in enumerate(d['members']):
prefix="'members'[%s] "%i
if not isinstance(item, dict):
Expand All @@ -270,7 +254,7 @@ def __validate_members(d, tags):
raise Exception(prefix+"'type' must not be '*_flag_t': %s"%item['type'])

ver = __validate_version(item, prefix=prefix, base_version=d_ver)
if ver < max_ver:
if _version_compare_less(ver, max_ver):
raise Exception(prefix+"'version' must be increasing: %s"%item['version'])
max_ver = ver

Expand All @@ -282,7 +266,7 @@ def __validate_params(d, tags):
raise Exception("'params' must be a sequence: '%s'"%type(d['params']))

d_ver = d.get('version', default_version)
max_ver = float(d_ver)
max_ver = d_ver
min = {'[in]': None, '[out]': None, '[in,out]': None}
for i, item in enumerate(d['params']):
prefix="'params'[%s] "%i
Expand All @@ -309,7 +293,7 @@ def __validate_params(d, tags):
raise Exception(prefix+"'type' must not be '*_flag_t': %s"%item['type'])

ver = __validate_version(item, prefix=prefix, base_version=d_ver)
if ver < max_ver:
if _version_compare_greater(ver, max_ver):
raise Exception(prefix+"'version' must be increasing: %s"%item['version'])
max_ver = ver

Expand Down Expand Up @@ -414,15 +398,65 @@ def __validate_params(d, tags):
"""
filters object by version
"""
def _version_compare_greater(a, b):
a_major = int(a.split('.')[0])
a_minor = int(a.split('.')[1])

b_major = int(b.split('.')[0])
b_minor = int(b.split('.')[1])

return ((a_major > b_major) or (a_minor > b_minor))

def _version_compare_less(a, b):
a_major = int(a.split('.')[0])
a_minor = int(a.split('.')[1])

b_major = int(b.split('.')[0])
b_minor = int(b.split('.')[1])

if a_major > b_major:
return False

if a_major < b_major:
return True

# a_major == b_major
if a_minor < b_minor:
return True

return False

def _version_compare_lequal(a, b):
# print("lequal: %s, %s" % (a, b))

a_major = int(a.split('.')[0])
a_minor = int(a.split('.')[1])

b_major = int(b.split('.')[0])
b_minor = int(b.split('.')[1])

if a_major > b_major:
return False

if a_major < b_major:
return True

# a_major == b_major
if a_minor <= b_minor:
return True

return False

def _filter_version(d, max_ver):
ver = float(d.get('version', default_version))
if ver > max_ver:
ver = d.get('version', default_version)

if _version_compare_greater(ver, max_ver):
return None

def __filter_desc(d):
if 'desc' in d and isinstance(d['desc'], dict):
for k, v in d['desc'].items():
if float(k) <= max_ver:
if _version_compare_lequal(k, max_ver):
desc = v
d['desc'] = desc
return d
Expand All @@ -435,7 +469,7 @@ def __filter_detail(det):
version = float(k)
except:
return det
if version <= max_ver:
if _version_compare_lequal(k, max_ver):
detail = v
return detail
return det
Expand All @@ -452,8 +486,8 @@ def __filter_detail(det):
type = d['type']
if 'enum' == type:
for e in d['etors']:
ver = float(e.get('version', default_version))
if ver <= max_ver:
ver = e.get('version', default_version)
if _version_compare_lequal(ver, max_ver):
flt.append(__filter_desc(e))
if d['name'].endswith('version_t'):
flt.append({
Expand All @@ -465,15 +499,15 @@ def __filter_detail(det):

elif 'function' == type:
for p in d['params']:
ver = float(p.get('version', default_version))
if ver <= max_ver:
ver = p.get('version', default_version)
if _version_compare_lequal(ver, max_ver):
flt.append(__filter_desc(p))
d['params'] = flt

elif 'struct' == type or 'union' == type or 'class' == type:
for m in d.get('members',[]):
ver = float(m.get('version', default_version))
if ver <= max_ver:
ver = m.get('version', default_version)
if _version_compare_lequal(ver, max_ver):
flt.append(__filter_desc(m))
d['members'] = flt

Expand All @@ -487,10 +521,10 @@ def _make_versions(d, max_ver):
type = d['type']
if 'function' == type or 'struct' == type:
for ver in all_versions:
if float(ver) > max_ver:
if _version_compare_greater(ver, max_ver):
break

dv = _filter_version(copy.deepcopy(d), float(ver))
dv = _filter_version(copy.deepcopy(d), ver)
if not dv:
continue

Expand Down Expand Up @@ -794,7 +828,7 @@ def parse(section, version, tags, meta, ref):
if not _validate_doc(f, d, tags, line_nums[i]):
continue

d = _filter_version(d, float(version))
d = _filter_version(d, version)
if not d:
continue

Expand Down
7 changes: 6 additions & 1 deletion scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,15 @@ def main():
add_argument(parser, "html", "generation of HTML files.", True)
add_argument(parser, "pdf", "generation of PDF file.")
add_argument(parser, "rst", "generation of reStructuredText files.", True)
add_argument(parser, "ignore_git_revision", "use command-line verison (ver) as revision instead of git tag.", False)
parser.add_argument("--update_spec", type=str, help="root of integrated spec directory to update")
parser.add_argument("--ver", type=str, default="1.4", required=False, help="specification version to generate.")

args = vars(parser.parse_args())
args['rev'] = revision()
if (args['ignore_git_revision']):
args['rev'] = args['ver']
else:
args['rev'] = revision()

print("--------------------------------------------")
print("Building Level Zero Spec Version: %s" % args['rev'])
Expand Down
Loading