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'
17 ' (or from the Arvados event log, if the job is still running)')
19 '--pipeline-instance', type=str, metavar='UUID',
20 help='Summarize each component of the given pipeline instance')
22 '--log-file', type=str,
23 help='Read log data from a regular file')
25 '--skip-child-jobs', action='store_true',
26 help='Do not include stats from child jobs')
28 '--format', type=str, choices=('html', 'text'), default='text',
31 '--verbose', '-v', action='count', default=0,
32 help='Log more information (once for progress, twice for debug)')
35 class Command(object):
36 def __init__(self, args):
38 logger.setLevel(logging.WARNING - 10 * args.verbose)
42 'skip_child_jobs': self.args.skip_child_jobs,
44 if self.args.pipeline_instance:
45 self.summer = summarizer.PipelineSummarizer(self.args.pipeline_instance, **kwargs)
47 self.summer = summarizer.JobSummarizer(self.args.job, **kwargs)
48 elif self.args.log_file:
49 if self.args.log_file.endswith('.gz'):
50 fh = gzip.open(self.args.log_file)
52 fh = open(self.args.log_file)
53 self.summer = summarizer.Summarizer(fh, **kwargs)
55 self.summer = summarizer.Summarizer(sys.stdin, **kwargs)
56 return self.summer.run()
59 if self.args.format == 'html':
60 return self.summer.html_report()
61 elif self.args.format == 'text':
62 return self.summer.text_report()