Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions scripts/tracelens_single_config/create_final_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from pathlib import Path
import base64
import argparse

from html_report_config import (
HTML_HEADER,
HTML_FOOTER,
OVERALL_GPU_CHARTS,
CROSS_RANK_CHARTS,
NCCL_CHARTS,
)


def get_image_base64(image_path):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already exists here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation should replace the refered code .. This is the base html creator, we will use this framework to genertae GEMM html report.

"""Read an image file and return its base64-encoded string."""
try:
with open(image_path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")
except Exception as e:
print(f"Error getting image data from {image_path}: {e}")
return None


def create_chart_html(plot_dir, chart_config):
"""Generate HTML for a single chart with title, image, and description."""
image_data = get_image_base64(plot_dir / chart_config["file"])
if image_data is None:
return ""
return f"""
<h4> {chart_config['name']} </h4>
<img src="data:image/png;base64,{image_data}" alt="{chart_config['alt']}" class="chart-image">
{chart_config['description']}
"""


def create_section_html(title, plot_dir, charts):
"""Generate HTML for a complete section with multiple charts."""
section_html = f"""
<h3> {title} </h3>
"""
for chart in charts:
section_html += create_chart_html(plot_dir, chart)
return section_html


def create_final_html(plot_file_path, output_path):
html_body = """
<body>

<h1> Performance Analysis Report </h1>

<hr>

<h2> Executive Summary </h2>

Comparison of GPU performance metrics between baseline and Test
implementations across 8 ranks.
"""

# Build all sections
sections = [
create_section_html(
"1. Overall GPU Metrics Comparison", plot_file_path, OVERALL_GPU_CHARTS
),
create_section_html(
"2. Cross-Rank Performance Comparison", plot_file_path, CROSS_RANK_CHARTS
),
create_section_html(
"3. NCCL Collective Operations Analysis", plot_file_path, NCCL_CHARTS
),
]

final_html = HTML_HEADER + html_body + "".join(sections) + HTML_FOOTER
with open(output_path, "w") as f:
f.write(final_html)
print(f"Final HTML file created at: {output_path}")


def main():
parser = argparse.ArgumentParser(
description="Create a final HTML file for the analysis report."
)
parser.add_argument(
"-p",
"--plot-files-directory",
type=Path,
required=True,
help="Path to the plot files direcotry.",
)
parser.add_argument(
"-o", "--output-html", type=None, default=None, help="Path to the output file."
)
args = parser.parse_args()
output_path = (
args.output_html
if args.output_html
else args.plot_files_directory.parent / "final_analysis_report.html"
)
create_final_html(args.plot_files_directory, output_path)


if __name__ == "__main__":
main()
Loading