Skip to content

Add summary printing for parsed files #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions tritonparse/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,60 @@ def to_rank(self) -> Rank:
return Rank()


def print_parsed_files_summary(parsed_log_dir: str, out_dir: str = None) -> None:
"""
Print a beautiful summary of all parsed files.

Args:
parsed_log_dir: Directory containing parsed files
"""
# Collect all parsed files
all_parsed_files = []
for root, _, files in os.walk(parsed_log_dir):
for file in files:
file_path = os.path.join(root, file)
all_parsed_files.append(file_path)

# Sort files for consistent output
all_parsed_files.sort()

# Print beautiful summary
print("\n" + "=" * 80)
print("πŸ“ TRITONPARSE PARSING RESULTS")
print("=" * 80)

# Print log file list (required for integration)
if out_dir:
print(f"πŸ“‚ Parsed files directory: {out_dir}")
else:
print(f"πŸ“‚ Parsed files directory: {parsed_log_dir}")
print(f"πŸ“Š Total files generated: {len(all_parsed_files)}")

if all_parsed_files:
print("\nπŸ“„ Generated files:")
print("-" * 50)
for i, file_path in enumerate(all_parsed_files, 1):
# Get relative path for cleaner display
rel_path = os.path.relpath(file_path, parsed_log_dir)
file_size = "N/A"
try:
size_bytes = os.path.getsize(file_path)
if size_bytes < 1024:
file_size = f"{size_bytes}B"
elif size_bytes < 1024 * 1024:
file_size = f"{size_bytes/1024:.1f}KB"
else:
file_size = f"{size_bytes/(1024*1024):.1f}MB"
except OSError:
pass

print(f" {i:2d}. πŸ“ {rel_path} ({file_size})")

print("=" * 80)
print("βœ… Parsing completed successfully!")
print("=" * 80 + "\n")


def gzip_single_file(file_path: str, verbose: bool = False) -> str:
"""
Gzip a single file and delete the original file.
Expand Down Expand Up @@ -318,7 +372,9 @@ def parse_logs(
log_file_list_path = os.path.join(parsed_log_dir, "log_file_list.json")
with open(log_file_list_path, "w") as f:
json.dump(file_mapping, f, indent=2)

# NOTICE: this print is required for tlparser-tritonparse integration
# DON'T REMOVE THIS PRINT
print(f"tritonparse log file list: {log_file_list_path}")
return parsed_log_dir, file_mapping

Expand Down
5 changes: 3 additions & 2 deletions tritonparse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# argument parser for OSS
parser = None

from .common import copy_local_to_tmpdir, is_fbcode, parse_logs, RankConfig, save_logs
from .common import copy_local_to_tmpdir, is_fbcode, parse_logs, RankConfig, save_logs, print_parsed_files_summary
from .source_type import Source, SourceType


Expand Down Expand Up @@ -92,7 +92,8 @@ def oss_parse(args):
parsed_log_dir, _ = parse_logs(logs, rank_config, verbose)
if args.out is not None:
save_logs(Path(args.out), parsed_log_dir, args.overwrite, verbose)

# Print beautiful summary of all parsed files
print_parsed_files_summary(parsed_log_dir, args.out)

def unified_parse(args=None):
"""
Expand Down