Skip to content

Commit 89913ff

Browse files
FindHaometa-codesync[bot]
authored andcommitted
feat: extend usage_report_logger to track all subcommands and API calls
Summary: This change extends the usage logging functionality to track all tritonparse usage, including: 1. **CLI layer logging**: Added unified usage_report_logger() call in cli.py main() function to record all subcommand invocations (parse, reproduce, info) 2. **API layer logging**: Added usage_report_logger() calls to reproduce() and info_command() functions to capture direct API usage (non-CLI calls) 3. **Entry function detection**: Modified usage_report_logger() to use sys._getframe() to traverse the call stack and identify the outermost entry function (unified_parse, reproduce, info_command, fb_run, or main), storing it in extra_data["entry_function"] 4. **skip_logger parameter**: Added skip_logger parameter to unified_parse(), reproduce(), info_command(), and oss_run() functions to prevent duplicate logging when called from CLI (which already logs at the top level) This enables better tracking of how tritonparse is being used - both through CLI commands and through direct Python API calls. Reviewed By: wychi Differential Revision: D88983900 fbshipit-source-id: fd193a0ff64ba01ce425899220a22deb710ebdaf
1 parent 5159847 commit 89913ff

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

tritonparse/cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ def main():
7373

7474
args = parser.parse_args()
7575

76+
# Log usage for CLI invocations
77+
if is_fbcode():
78+
from tritonparse.fb.utils import usage_report_logger
79+
80+
usage_report_logger()
81+
7682
if args.func == "parse":
7783
parse_args = {
7884
k: v for k, v in vars(args).items() if k not in ["command", "func"]
7985
}
80-
unified_parse(**parse_args)
86+
# skip_logger=True because we already logged above
87+
unified_parse(**parse_args, skip_logger=True)
8188
elif args.func == "reproduce":
8289
# Check mutual exclusivity between --line and --kernel/--launch-id
8390
if args.kernel and args.line != 0:
@@ -99,9 +106,12 @@ def main():
99106
launch_id=args.launch_id if args.kernel else 0,
100107
kernel_import=args.kernel_import,
101108
replacer=replacer,
109+
skip_logger=True, # Already logged above
102110
)
103111
elif args.func == "info":
104-
info_command(input_path=args.input, kernel_name=args.kernel)
112+
info_command(
113+
input_path=args.input, kernel_name=args.kernel, skip_logger=True
114+
) # Already logged above
105115
else:
106116
raise RuntimeError(f"Unknown command: {args.func}")
107117

tritonparse/info/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import tempfile
1212
from typing import Optional
1313

14+
from tritonparse.common import is_fbcode
1415
from tritonparse.info.kernel_query import (
1516
find_similar_kernels,
1617
list_kernels_fast,
@@ -34,14 +35,22 @@ def _add_info_args(parser: argparse.ArgumentParser) -> None:
3435
)
3536

3637

37-
def info_command(input_path: str, kernel_name: Optional[str] = None) -> None:
38+
def info_command(
39+
input_path: str, kernel_name: Optional[str] = None, skip_logger: bool = False
40+
) -> None:
3841
"""
3942
Main function for the info command.
4043
4144
Args:
4245
input_path: Path to ndjson file
4346
kernel_name: Optional kernel name to list launches for
47+
skip_logger: Whether to skip usage logging (default: False).
4448
"""
49+
if not skip_logger and is_fbcode():
50+
from tritonparse.fb.utils import usage_report_logger
51+
52+
usage_report_logger()
53+
4554
# 1. Load and detect type
4655
events = load_ndjson(input_path)
4756
has_launch_diff = any(e.get("event_type") == "launch_diff" for e in events)

tritonparse/reproducer/orchestrator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from typing import Optional
55

6+
from tritonparse.common import is_fbcode
67
from tritonparse.info.kernel_query import find_launch_index_by_kernel
78
from tritonparse.reproducer.ingestion.ndjson import build_context_bundle
89
from tritonparse.reproducer.placeholder_replacer import (
@@ -25,6 +26,7 @@ def reproduce(
2526
launch_id: int = 0,
2627
replacer: Optional[PlaceholderReplacer] = None,
2728
kernel_import: KernelImportMode = KernelImportMode.DEFAULT,
29+
skip_logger: bool = False,
2830
) -> dict[str, str]:
2931
"""
3032
Generate a reproducer script from NDJSON trace file.
@@ -43,7 +45,13 @@ def reproduce(
4345
launch_id: 0-based launch index for the kernel (default: 0, first launch).
4446
replacer: Optional custom PlaceholderReplacer instance. If None, uses DefaultPlaceholderReplacer.
4547
kernel_import: Kernel import mode (DEFAULT or COPY).
48+
skip_logger: Whether to skip usage logging (default: False).
4649
"""
50+
if not skip_logger and is_fbcode():
51+
from tritonparse.fb.utils import usage_report_logger
52+
53+
usage_report_logger()
54+
4755
events = load_ndjson(Path(input_path))
4856
logger.debug(f"Loaded {len(events)} events")
4957

tritonparse/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def oss_run(
6060
all_ranks: bool = False,
6161
verbose: bool = False,
6262
split_inductor_compilations: bool = True,
63+
skip_logger: bool = True,
6364
):
6465
"""
6566
Main function for tritonparse. It is for OSS only.
@@ -71,6 +72,7 @@ def oss_run(
7172
rank: Rank of logs to be analyzed
7273
all_ranks: Analyze all ranks
7374
verbose: Verbose logging
75+
skip_logger: Unused in OSS, kept for API compatibility.
7476
"""
7577
source = Source(source, verbose)
7678
rank_config = RankConfig.from_cli_args(rank, all_ranks, source.type)
@@ -123,6 +125,7 @@ def unified_parse(
123125
all_ranks: bool = False,
124126
verbose: bool = False,
125127
split_inductor_compilations: bool = True,
128+
skip_logger: bool = False,
126129
**kwargs,
127130
):
128131
"""
@@ -135,7 +138,14 @@ def unified_parse(
135138
rank: Specific rank to analyze
136139
all_ranks: Whether to analyze all ranks
137140
verbose: Whether to enable verbose logging
141+
skip_logger: Whether to skip usage logging (default: False).
138142
"""
143+
# Log usage for API invocations
144+
if not skip_logger and is_fbcode():
145+
from tritonparse.fb.utils import usage_report_logger
146+
147+
usage_report_logger()
148+
139149
# Choose the appropriate parse function
140150
if is_fbcode():
141151
from tritonparse.fb.utils import fb_run as parse
@@ -150,6 +160,7 @@ def unified_parse(
150160
all_ranks=all_ranks,
151161
verbose=verbose,
152162
split_inductor_compilations=split_inductor_compilations,
163+
skip_logger=skip_logger,
153164
**kwargs,
154165
)
155166
return output

0 commit comments

Comments
 (0)