Skip to content

Commit fd1c7cf

Browse files
FindHaofacebook-github-bot
authored andcommitted
Add summary printing for parsed files (#20)
Summary: - Introduced a new function `print_parsed_files_summary` to display a formatted summary of all parsed files, including their paths and sizes. - Updated `oss_parse` to call this new function after parsing logs, enhancing user feedback on parsing results. Pull Request resolved: #20 Reviewed By: davidberard98 Differential Revision: D77236623 Pulled By: FindHao fbshipit-source-id: 2fbc6485040100855de8a8eac436fb254421287f
1 parent aa52b00 commit fd1c7cf

File tree

4 files changed

+92
-8
lines changed

4 files changed

+92
-8
lines changed

tests/test_add.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ def test_tensor_add():
7171
if __name__ == "__main__":
7272
test_tensor_add()
7373
# Use improved unified_parse with explicit output directory
74-
tritonparse.utils.unified_parse(source=log_path, out="./parsed_output")
74+
tritonparse.utils.unified_parse(
75+
source=log_path, out="./parsed_output", overwrite=True
76+
)

tritonparse/common.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,57 @@ def to_rank(self) -> Rank:
135135
return Rank()
136136

137137

138+
def print_parsed_files_summary(parsed_log_dir: str) -> None:
139+
"""
140+
Print a beautiful summary of all parsed files.
141+
142+
Args:
143+
parsed_log_dir: Directory containing parsed files
144+
"""
145+
# Collect all parsed files
146+
all_parsed_files = []
147+
for root, _, files in os.walk(parsed_log_dir):
148+
for file in files:
149+
file_path = os.path.join(root, file)
150+
all_parsed_files.append(file_path)
151+
152+
# Sort files for consistent output
153+
all_parsed_files.sort()
154+
155+
# Print beautiful summary
156+
print("\n" + "=" * 80)
157+
print("📁 TRITONPARSE PARSING RESULTS")
158+
print("=" * 80)
159+
160+
# Print log file list (required for integration)
161+
print(f"📂 Parsed files directory: {parsed_log_dir}")
162+
print(f"📊 Total files generated: {len(all_parsed_files)}")
163+
164+
if all_parsed_files:
165+
print("\n📄 Generated files:")
166+
print("-" * 50)
167+
for i, file_path in enumerate(all_parsed_files, 1):
168+
# Get relative path for cleaner display
169+
rel_path = os.path.relpath(file_path, parsed_log_dir)
170+
file_size = "N/A"
171+
try:
172+
size_bytes = os.path.getsize(file_path)
173+
if size_bytes < 1024:
174+
file_size = f"{size_bytes}B"
175+
elif size_bytes < 1024 * 1024:
176+
file_size = f"{size_bytes/1024:.1f}KB"
177+
else:
178+
file_size = f"{size_bytes/(1024*1024):.1f}MB"
179+
except OSError:
180+
pass
181+
182+
print(f" {i:2d}. 📝 {rel_path} ({file_size})")
183+
184+
print("=" * 80)
185+
print("✅ Parsing completed successfully!")
186+
print("=" * 80 + "\n")
187+
188+
138189
def gzip_single_file(file_path: str, verbose: bool = False) -> str:
139190
"""
140191
Gzip a single file and delete the original file.
@@ -318,7 +369,9 @@ def parse_logs(
318369
log_file_list_path = os.path.join(parsed_log_dir, "log_file_list.json")
319370
with open(log_file_list_path, "w") as f:
320371
json.dump(file_mapping, f, indent=2)
372+
321373
# NOTICE: this print is required for tlparser-tritonparse integration
374+
# DON'T REMOVE THIS PRINT
322375
print(f"tritonparse log file list: {log_file_list_path}")
323376
return parsed_log_dir, file_mapping
324377

tritonparse/structured_logging.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,18 @@ def __call__(
851851
Returns:
852852
True to continue with compilation, None/False to skip
853853
"""
854-
launch_metadata_fn = fn.jit_function.launch_metadata
855-
if launch_metadata_fn is not None:
854+
# Check kernel allowlist early to avoid unnecessary work
855+
if _KERNEL_ALLOWLIST_PATTERNS is not None:
856+
kernel_name = fn.name
857+
if not should_trace_kernel(kernel_name, _KERNEL_ALLOWLIST_PATTERNS):
858+
# Skip overriding launch_metadata if kernel is not in allowlist
859+
return True
860+
861+
# Get the current launch_metadata function if it exists
862+
current_launch_metadata = getattr(fn.jit_function, "launch_metadata", None)
863+
if current_launch_metadata is not None:
856864
log.warning(
857-
f"fn {fn} launch_metadata_fn is not None: {launch_metadata_fn}. It will be overridden by tritonparse."
865+
f"fn {fn} launch_metadata is not None: {current_launch_metadata}. It will be overridden by tritonparse."
858866
)
859867
fn.jit_function.launch_metadata = add_launch_metadata
860868
return True
@@ -898,8 +906,16 @@ def __call__(self, metadata):
898906
https://github.com/triton-lang/triton/blob/7ce287dc24b43476cdeb30529089ac361564505d/
899907
python/triton/compiler/compiler.py#L512.
900908
"""
901-
trace_data = defaultdict(dict)
902909
metadata_dict = metadata.get()
910+
# Check kernel allowlist early to avoid unnecessary work
911+
if _KERNEL_ALLOWLIST_PATTERNS is not None:
912+
kernel_name = metadata_dict.get("name")
913+
914+
if not should_trace_kernel(kernel_name, _KERNEL_ALLOWLIST_PATTERNS):
915+
# Skip tracing if kernel is not in allowlist
916+
return
917+
918+
trace_data = defaultdict(dict)
903919
trace_data["name"] = metadata_dict["name"]
904920
trace_data["function"] = metadata_dict["function"]
905921
trace_data["stream"] = metadata_dict["stream"]

tritonparse/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
# argument parser for OSS
1010
parser = None
1111

12-
from .common import copy_local_to_tmpdir, is_fbcode, parse_logs, RankConfig, save_logs
12+
from .common import (
13+
copy_local_to_tmpdir,
14+
is_fbcode,
15+
parse_logs,
16+
print_parsed_files_summary,
17+
RankConfig,
18+
save_logs,
19+
)
1320
from .source_type import Source, SourceType
1421

1522

@@ -53,7 +60,7 @@ def init_parser():
5360
def oss_run(
5461
source: str,
5562
out: Optional[str] = None,
56-
overwrite: bool = True,
63+
overwrite: Optional[bool] = False,
5764
rank: Optional[int] = None,
5865
all_ranks: bool = False,
5966
verbose: bool = False,
@@ -98,6 +105,12 @@ def oss_run(
98105
parsed_log_dir, _ = parse_logs(logs, rank_config, verbose)
99106
if out is not None:
100107
save_logs(Path(out), parsed_log_dir, overwrite, verbose)
108+
# Print beautiful summary of all parsed files
109+
if out is not None:
110+
out_dir = str(Path(out).absolute())
111+
else:
112+
out_dir = str(Path(parsed_log_dir).absolute())
113+
print_parsed_files_summary(out_dir)
101114

102115

103116
def unified_parse_from_cli():
@@ -109,7 +122,7 @@ def unified_parse_from_cli():
109122
def unified_parse(
110123
source: str,
111124
out: Optional[str] = None,
112-
overwrite: bool = True,
125+
overwrite: Optional[bool] = False,
113126
rank: Optional[int] = None,
114127
all_ranks: bool = False,
115128
verbose: bool = False,

0 commit comments

Comments
 (0)