Skip to content

Commit

Permalink
introduce JsonSingleFileRule
Browse files Browse the repository at this point in the history
  • Loading branch information
d-kozak committed Jan 20, 2022
1 parent 7a440c2 commit ce44747
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17878,7 +17878,7 @@ def alarm_handler(signum, frame):


# The version must be updated for every PR (checked in CI)
version = VersionSpec("5.317.8") # GR-33851
version = VersionSpec("5.317.9") # GR-35755

currentUmask = None
_mx_start_datetime = datetime.utcnow()
Expand Down
46 changes: 38 additions & 8 deletions mx_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,25 +853,55 @@ def __init__(self, pattern, match_name, *args, **kwargs):
def getCSVFiles(self, text):
return (m.groupdict()[self.match_name] for m in re.finditer(self.pattern, text, re.MULTILINE))

class JsonStdOutFileRule(BaseRule):

def __init__(self, pattern, match_name, replacement, keys):
super(JsonStdOutFileRule, self).__init__(replacement)
self.pattern = pattern
self.match_name = match_name
class JsonBaseRule(BaseRule):
"""Parses JSON files and creates a measurement result using the replacement."""

def __init__(self, replacement, keys):
super(JsonBaseRule, self).__init__(replacement)
self.keys = keys

def parseResults(self, text):
l = []
for f in self.getFiles(text):
for f in self.getJsonFiles(text):
with open(f) as fp:
l = l + [{k:str(v)} for k, v in json.load(fp).items() if k in self.keys]
l = l + [{k: str(v)} for k, v in json.load(fp).items() if k in self.keys]
return l

def getFiles(self, text):
def getJsonFiles(self, text):
"""Get the JSON files which should be parsed.
:param text: The standard output of the benchmark.
:type text: str
:return: List of file names
:rtype: list
"""
raise NotImplementedError()


class JsonStdOutFileRule(JsonBaseRule):
"""Rule that looks for JSON file names in the output of the benchmark."""

def __init__(self, pattern, match_name, replacement, keys):
super(JsonStdOutFileRule, self).__init__(replacement, keys)
self.pattern = pattern
self.match_name = match_name

def getJsonFiles(self, text):
return (m.groupdict()[self.match_name] for m in re.finditer(self.pattern, text, re.MULTILINE))


class JsonFixedFileRule(JsonBaseRule):
"""Rule that parses a JSON file with a predefined name."""

def __init__(self, filename, replacement, keys):
super(JsonFixedFileRule, self).__init__(replacement, keys)
self.filename = filename

def getJsonFiles(self, text):
return [self.filename]


class JMHJsonRule(Rule):
"""Parses a JSON file produced by JMH and creates a measurement result."""

Expand Down

0 comments on commit ce44747

Please sign in to comment.