Skip to content
Snippets Groups Projects
Commit 2f164170 authored by Rafal Bielski's avatar Rafal Bielski :wave:
Browse files

Print messages if MessageCount step fails and is required

parent 78c63564
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,9 @@ def get_parser(): ...@@ -49,6 +49,9 @@ def get_parser():
parser.add_argument('-p', '--printMessages', parser.add_argument('-p', '--printMessages',
action='store_true', action='store_true',
help='Print the messages found in analysed files') help='Print the messages found in analysed files')
parser.add_argument('--saveAll',
action='store_true',
help='Store all the messages into the output JSON file')
parser.add_argument('-v', '--verbose', parser.add_argument('-v', '--verbose',
action='store_true', action='store_true',
help='Increase output verbosity') help='Increase output verbosity')
...@@ -113,12 +116,18 @@ def print_result(summary, full_result, print_messages=False): ...@@ -113,12 +116,18 @@ def print_result(summary, full_result, print_messages=False):
print(line, end='') # noqa: ATL901 print(line, end='') # noqa: ATL901
def save_to_json(result, filename): def save_summary_to_json(result, filename):
logging.info('Saving results to %s', filename) logging.info('Saving results to %s', filename)
with open(filename, 'w') as f: with open(filename, 'w') as f:
json.dump(result, f, indent=4) json.dump(result, f, indent=4)
def save_all_to_json(full_result, filename):
logging.info('Saving results to %s', filename)
with open(filename, 'w') as f:
json.dump(full_result, f, indent=4)
def main(): def main():
args = get_parser().parse_args() args = get_parser().parse_args()
logging.basicConfig(stream=sys.stdout, logging.basicConfig(stream=sys.stdout,
...@@ -141,7 +150,10 @@ def main(): ...@@ -141,7 +150,10 @@ def main():
summary = make_summary(messages) summary = make_summary(messages)
print_result(summary, messages, args.printMessages) print_result(summary, messages, args.printMessages)
out_file_name = 'MessageCount.{:s}.json'.format(fname) out_file_name = 'MessageCount.{:s}.json'.format(fname)
save_to_json(summary, out_file_name) save_summary_to_json(summary, out_file_name)
if args.saveAll:
all_out_file_name = 'Messages.{:s}.json'.format(fname)
save_all_to_json(messages, all_out_file_name)
if '__main__' in __name__: if '__main__' in __name__:
......
...@@ -566,26 +566,27 @@ class MessageCountStep(Step): ...@@ -566,26 +566,27 @@ class MessageCountStep(Step):
self.log_regex = r'(athena\..*log$|athenaHLT:.*\.out$|^log\..*to.*)' self.log_regex = r'(athena\..*log$|athenaHLT:.*\.out$|^log\..*to.*)'
self.start_pattern = r'(HltEventLoopMgr|AthenaHiveEventLoopMgr).*INFO Starting loop on events' self.start_pattern = r'(HltEventLoopMgr|AthenaHiveEventLoopMgr).*INFO Starting loop on events'
self.end_pattern = r'(HltEventLoopMgr.*INFO All events processed|AthenaHiveEventLoopMgr.*INFO.*Loop Finished)' self.end_pattern = r'(HltEventLoopMgr.*INFO All events processed|AthenaHiveEventLoopMgr.*INFO.*Loop Finished)'
self.warning_threshold = None self.print_on_fail = None
self.info_threshold = None self.thresholds = {}
self.debug_threshold = None
self.verbose_threshold = None
self.other_threshold = None
self.auto_report_result = True self.auto_report_result = True
def configure(self, test): def configure(self, test):
self.args += ' -s "{:s}"'.format(self.start_pattern) self.args += ' -s "{:s}"'.format(self.start_pattern)
self.args += ' -e "{:s}"'.format(self.end_pattern) self.args += ' -e "{:s}"'.format(self.end_pattern)
if self.warning_threshold is None: if self.print_on_fail is None:
self.warning_threshold = 0 self.print_on_fail = self.required
if self.info_threshold is None: if self.print_on_fail:
self.info_threshold = test.exec_steps[0].max_events self.args += ' --saveAll'
if self.debug_threshold is None: if 'WARNING' not in self.thresholds:
self.debug_threshold = 0 self.thresholds['WARNING'] = 0
if self.verbose_threshold is None: if 'INFO' not in self.thresholds:
self.verbose_threshold = 0 self.thresholds['INFO'] = test.exec_steps[0].max_events
if self.other_threshold is None: if 'DEBUG' not in self.thresholds:
self.other_threshold = test.exec_steps[0].max_events self.thresholds['DEBUG'] = 0
if 'VERBOSE' not in self.thresholds:
self.thresholds['VERBOSE'] = 0
if 'other' not in self.thresholds:
self.thresholds['other'] = test.exec_steps[0].max_events
super(MessageCountStep, self).configure(test) super(MessageCountStep, self).configure(test)
def run(self, dry_run=False): def run(self, dry_run=False):
...@@ -603,43 +604,28 @@ class MessageCountStep(Step): ...@@ -603,43 +604,28 @@ class MessageCountStep(Step):
if self.auto_report_result: if self.auto_report_result:
self.report_result() self.report_result()
return self.result, cmd return self.result, cmd
(num_warning, num_info, num_debug, num_verbose, num_other) = (0, 0, 0, 0, 0)
for log_file in log_files: for log_file in log_files:
json_file = 'MessageCount.{:s}.json'.format(log_file) json_file = 'MessageCount.{:s}.json'.format(log_file)
if self.print_on_fail:
all_json_file = 'Messages.{:s}.json'.format(log_file)
if not os.path.isfile(json_file): if not os.path.isfile(json_file):
self.log.warning('%s cannot open file %s', self.name, json_file) self.log.warning('%s cannot open file %s', self.name, json_file)
with open(json_file) as f: with open(json_file) as f:
summary = json.load(f) summary = json.load(f)
num_warning += summary['WARNING'] for level, threshold in six.iteritems(self.thresholds):
num_info += summary['INFO'] if summary[level] > threshold:
num_debug += summary['DEBUG'] self.result += 1
num_verbose += summary['VERBOSE'] self.log.info(
num_other += summary['other'] '%s Number of %s messages %s is higher than threshold %s',
if num_warning > self.warning_threshold: self.name, level, summary[level], threshold)
self.log.info( if self.print_on_fail:
'%s Number of WARNING messages %s is higher than threshold %s', self.log.info('%s Printing all %s messages', self.name, level)
self.name, num_warning, self.warning_threshold) with open(all_json_file) as af:
self.result += 1 all_msg = json.load(af)
if num_info > self.info_threshold: for msg in all_msg[level]:
self.log.info( print(msg.strip()) # noqa: ATL901
'%s Number of INFO messages %s is higher than threshold %s',
self.name, num_info, self.info_threshold)
self.result += 1
if num_debug > self.debug_threshold:
self.log.info(
'%s Number of DEBUG messages %s is higher than threshold %s',
self.name, num_debug, self.debug_threshold)
self.result += 1
if num_verbose > self.verbose_threshold:
self.log.info(
'%s Number of VERBOSE messages %s is higher than threshold %s',
self.name, num_verbose, self.verbose_threshold)
self.result += 1
if num_other > self.other_threshold:
self.log.info(
'%s Number of "other" messages %s is higher than threshold %s',
self.name, num_other, self.other_threshold)
self.result += 1
if self.auto_report_result: if self.auto_report_result:
self.report_result() self.report_result()
return self.result, cmd return self.result, cmd
......
...@@ -31,9 +31,11 @@ test.check_steps = CheckSteps.default_check_steps(test) ...@@ -31,9 +31,11 @@ test.check_steps = CheckSteps.default_check_steps(test)
# We are trying to lower the limits step by step # We are trying to lower the limits step by step
# Ultimately there should be no per-event messages # Ultimately there should be no per-event messages
msgcount = test.get_step("MessageCount") msgcount = test.get_step("MessageCount")
msgcount.warning_threshold = 500 msgcount.thresholds = {
msgcount.info_threshold = 1200 'WARNING': 500,
msgcount.other_threshold = 80 'INFO': 1200,
'other': 80
}
msgcount.required = True # make the test exit code depend on this step msgcount.required = True # make the test exit code depend on this step
# Add a step comparing counts in the log against reference # Add a step comparing counts in the log against reference
......
...@@ -36,9 +36,11 @@ test.check_steps.remove(test.get_step("ZeroCounts")) ...@@ -36,9 +36,11 @@ test.check_steps.remove(test.get_step("ZeroCounts"))
# Overwrite default MessageCount settings # Overwrite default MessageCount settings
msgcount = test.get_step("MessageCount") msgcount = test.get_step("MessageCount")
msgcount.warning_threshold = 40 msgcount.thresholds = {
msgcount.info_threshold = 600 'WARNING': 40,
msgcount.other_threshold = 40 'INFO': 600,
'other': 40
}
msgcount.required = True # make the test exit code depend on this step msgcount.required = True # make the test exit code depend on this step
import sys import sys
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment