1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
10 from crunchstat_summary import logger, summarizer
13 class ArgumentParser(argparse.ArgumentParser):
15 super(ArgumentParser, self).__init__(
16 description='Summarize resource usage of an Arvados Crunch job')
17 src = self.add_mutually_exclusive_group()
19 '--job', '--container', '--container-request',
20 type=str, metavar='UUID',
21 help='Look up the specified job, container, or container request '
22 'and read its log data from Keep (or from the Arvados event log, '
23 'if the job is still running)')
25 '--pipeline-instance', type=str, metavar='UUID',
26 help='Summarize each component of the given pipeline instance')
28 '--log-file', type=str,
29 help='Read log data from a regular file')
31 '--skip-child-jobs', action='store_true',
32 help='Do not include stats from child jobs')
34 '--format', type=str, choices=('html', 'text'), default='text',
37 '--threads', type=int, default=8,
38 help='Maximum worker threads to run')
40 '--verbose', '-v', action='count', default=0,
41 help='Log more information (once for progress, twice for debug)')
44 class Command(object):
45 def __init__(self, args):
47 logger.setLevel(logging.WARNING - 10 * args.verbose)
51 'skip_child_jobs': self.args.skip_child_jobs,
52 'threads': self.args.threads,
54 if self.args.pipeline_instance:
55 self.summer = summarizer.NewSummarizer(self.args.pipeline_instance, **kwargs)
57 self.summer = summarizer.NewSummarizer(self.args.job, **kwargs)
58 elif self.args.log_file:
59 if self.args.log_file.endswith('.gz'):
60 fh = gzip.open(self.args.log_file)
62 fh = open(self.args.log_file)
63 self.summer = summarizer.Summarizer(fh, **kwargs)
65 self.summer = summarizer.Summarizer(sys.stdin, **kwargs)
66 return self.summer.run()
69 if self.args.format == 'html':
70 return self.summer.html_report()
71 elif self.args.format == 'text':
72 return self.summer.text_report()