diff --git a/darshan-util/pydarshan/darshan/cli/darshan_summary.py b/darshan-util/pydarshan/darshan/cli/darshan_summary.py new file mode 100644 index 000000000..3e7e1b8fc --- /dev/null +++ b/darshan-util/pydarshan/darshan/cli/darshan_summary.py @@ -0,0 +1,76 @@ +import os +import sys +import time + +if sys.version_info >= (3, 7): + import importlib.resources as importlib_resources +else: + import importlib_resources + +import darshan +from darshan.cli.summary import ReportData + +import rich_click as click +from mako.template import Template + +click.rich_click.OPTION_GROUPS = { + "darshan_summary": [ + { + "name": "Basic usage", + "options": ["--log_path", "--output", "--help"], + }, + { + "name": "Heatmap Options", + "options": ["--split-heatmaps", "--force-dxt"], + }, + ], +} + + +@click.command() +@click.option('--log_path', help='Path to darshan log file.', required=True) +@click.option('--output', help='Specify output filename.') +# TODO: actually implement heatmap options in summary report +@click.option('--split-heatmaps', + is_flag=True, + show_default=True, + default=False, + help='Separate heatmaps for read and write IO activity.') +@click.option('--force-dxt', + is_flag=True, + show_default=True, + default=False, + help='Force plotting of DXT heatmaps even when large.') +def summary_report(log_path, + output, + split_heatmaps, + force_dxt): + start = time.perf_counter() + if output is None: + # if no output is provided, use the log file + # name to create the output filename + log_filename = os.path.splitext(os.path.basename(log_path))[0] + report_filename = f"{log_filename}_report.html" + else: + report_filename = output + + # collect the report data to feed into the template + report_data = ReportData(log_path=log_path) + + with importlib_resources.path(darshan.cli, "base.html") as base_path: + # load a template object using the base template + template = Template(filename=str(base_path)) + # render the base template + stream = template.render(report_data=report_data) + with open(report_filename, "w") as f: + # print a message so users know where to look for their report + save_path = os.path.join(os.getcwd(), report_filename) + click.echo( + f"Report generated successfully. \n" + f"Saving report at location: {save_path}" + ) + # save the rendered html + f.write(stream) + end = time.perf_counter() + total_time_sec = end - start + click.echo(f"Report generation time (s): {total_time_sec:.2f}") diff --git a/darshan-util/pydarshan/mypy.ini b/darshan-util/pydarshan/mypy.ini index a228c052a..c2b390e95 100644 --- a/darshan-util/pydarshan/mypy.ini +++ b/darshan-util/pydarshan/mypy.ini @@ -37,6 +37,9 @@ ignore_missing_imports = True [mypy-mako.*] ignore_missing_imports = True +[mypy-rich_click] +ignore_missing_imports = True + # pydarshan modules that lack types # or currently have errors diff --git a/darshan-util/pydarshan/setup.py b/darshan-util/pydarshan/setup.py index 07d2d1c50..f293ec1e0 100644 --- a/darshan-util/pydarshan/setup.py +++ b/darshan-util/pydarshan/setup.py @@ -86,4 +86,8 @@ "examples/example_logs/*", "examples/darshan-graph/*", "tests/input/*"]}, + entry_points={"console_scripts": [ + "darshan_summary = darshan.cli.darshan_summary:summary_report", + ], + }, )