6 from crunchstat_summary import logger, summarizer
9 class ArgumentParser(argparse.ArgumentParser):
11 super(ArgumentParser, self).__init__(
12 description='Summarize resource usage of an Arvados Crunch job')
13 src = self.add_mutually_exclusive_group()
15 '--job', type=str, metavar='UUID',
16 help='Look up the specified job and read its log data from Keep')
18 '--pipeline-instance', type=str, metavar='UUID',
19 help='Summarize each component of the given pipeline instance')
21 '--log-file', type=str,
22 help='Read log data from a regular file')
24 '--skip-child-jobs', action='store_true',
25 help='Do not include stats from child jobs')
27 '--format', type=str, choices=('html', 'text'), default='text',
30 '--verbose', '-v', action='count', default=0,
31 help='Log more information (once for progress, twice for debug)')
34 class Command(object):
35 def __init__(self, args):
37 logger.setLevel(logging.WARNING - 10 * args.verbose)
41 'skip_child_jobs': self.args.skip_child_jobs,
43 if self.args.pipeline_instance:
44 self.summer = summarizer.PipelineSummarizer(self.args.pipeline_instance, **kwargs)
46 self.summer = summarizer.JobSummarizer(self.args.job, **kwargs)
47 elif self.args.log_file:
48 if self.args.log_file.endswith('.gz'):
49 fh = gzip.open(self.args.log_file)
51 fh = open(self.args.log_file)
52 self.summer = summarizer.Summarizer(fh, **kwargs)
54 self.summer = summarizer.Summarizer(sys.stdin, **kwargs)
55 return self.summer.run()
58 if self.args.format == 'html':
59 return self.summer.html_report()
60 elif self.args.format == 'text':
61 return self.summer.text_report()