|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import time |
| 4 | + |
| 5 | +if sys.version_info >= (3, 7): |
| 6 | + import importlib.resources as importlib_resources |
| 7 | +else: |
| 8 | + import importlib_resources |
| 9 | + |
| 10 | +import darshan |
| 11 | +from darshan.cli.summary import ReportData |
| 12 | + |
| 13 | +import rich_click as click |
| 14 | +from mako.template import Template |
| 15 | + |
| 16 | +click.rich_click.OPTION_GROUPS = { |
| 17 | + "darshan_summary": [ |
| 18 | + { |
| 19 | + "name": "Basic usage", |
| 20 | + "options": ["--log_path", "--output", "--help"], |
| 21 | + }, |
| 22 | + { |
| 23 | + "name": "Heatmap Options", |
| 24 | + "options": ["--split-heatmaps", "--force-dxt"], |
| 25 | + }, |
| 26 | + ], |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +@click.command() |
| 31 | +@click.option('--log_path', help='Path to darshan log file.', required=True) |
| 32 | +@click.option('--output', help='Specify output filename.') |
| 33 | +# TODO: actually implement heatmap options in summary report |
| 34 | +@click.option('--split-heatmaps', |
| 35 | + is_flag=True, |
| 36 | + show_default=True, |
| 37 | + default=False, |
| 38 | + help='Separate heatmaps for read and write IO activity.') |
| 39 | +@click.option('--force-dxt', |
| 40 | + is_flag=True, |
| 41 | + show_default=True, |
| 42 | + default=False, |
| 43 | + help='Force plotting of DXT heatmaps even when large.') |
| 44 | +def summary_report(log_path, |
| 45 | + output, |
| 46 | + split_heatmaps, |
| 47 | + force_dxt): |
| 48 | + start = time.perf_counter() |
| 49 | + if output is None: |
| 50 | + # if no output is provided, use the log file |
| 51 | + # name to create the output filename |
| 52 | + log_filename = os.path.splitext(os.path.basename(log_path))[0] |
| 53 | + report_filename = f"{log_filename}_report.html" |
| 54 | + else: |
| 55 | + report_filename = output |
| 56 | + |
| 57 | + # collect the report data to feed into the template |
| 58 | + report_data = ReportData(log_path=log_path) |
| 59 | + |
| 60 | + with importlib_resources.path(darshan.cli, "base.html") as base_path: |
| 61 | + # load a template object using the base template |
| 62 | + template = Template(filename=str(base_path)) |
| 63 | + # render the base template |
| 64 | + stream = template.render(report_data=report_data) |
| 65 | + with open(report_filename, "w") as f: |
| 66 | + # print a message so users know where to look for their report |
| 67 | + save_path = os.path.join(os.getcwd(), report_filename) |
| 68 | + click.echo( |
| 69 | + f"Report generated successfully. \n" |
| 70 | + f"Saving report at location: {save_path}" |
| 71 | + ) |
| 72 | + # save the rendered html |
| 73 | + f.write(stream) |
| 74 | + end = time.perf_counter() |
| 75 | + total_time_sec = end - start |
| 76 | + click.echo(f"Report generation time (s): {total_time_sec:.2f}") |
0 commit comments