Commit ab34d43
Add
Summary:
This PR adds the `info` subcommand to query kernel information from NDJSON trace files. It automatically detects raw logs and parses them, enabling users to list kernels and their launches without manual parsing.
## Changes
- **`info/cli.py`** (NEW):
- `_add_info_args()`: Add CLI arguments for info subcommand
- `info_command()`: Main command implementation
- Auto-detects raw logs (no launch_diff events) and parses them automatically
- Supports listing all kernels or launches for a specific kernel
- Provides fuzzy matching suggestions when kernel not found
- **`info/parse_helper.py`** (NEW):
- `parse_and_compress_raw_log()`: Parse and compress raw log files
- Reuses `parse_single_file()` and `gzip_single_file()` from parse module
- Handles file naming for various input formats (.ndjson, .ndjson.gz, .bin.ndjson)
- **`info/kernel_query.py`**:
- `list_launches_for_kernel()`: List all launches for a specific kernel with grid info
- `find_similar_kernels()`: Fuzzy matching using `difflib.get_close_matches()`
- `list_kernels_fast()`: Optimized listing using `launch_diff` events when available
- Merges kernels with same name (sums up launches)
- Falls back to `list_kernels()` for raw logs
- **`info/__init__.py`**:
- Export new functions: `list_launches_for_kernel`, `find_similar_kernels`, `list_kernels_fast`
- **`cli.py`**:
- Add `info` subcommand integration
- Import `_add_info_args` and `info_command` from `info.cli`
- Update help examples
- **`tests/test_tritonparse.py`**:
- `test_info_kernel_query_functions()`: Combined unit test for 3 query functions
- `test_info_list_kernels()`: Integration test for listing all kernels
- `test_info_kernel_launches()`: Integration test for listing kernel launches
- `test_info_kernel_not_found()`: Integration test for error handling with suggestions
## Usage
```bash
# List all kernels with launch counts
tritonparseoss info trace.ndjson
# Output example:
# Kernels in trace.ndjson:
# fused_op_kernel 4 launches (id: 0-3)
# matmul_kernel 1553 launches (id: 0-1552)
# List launches for a specific kernel
tritonparseoss info trace.ndjson --kernel matmul_kernel
# Output example:
# Launches for 'matmul_kernel':
# id= 0 line 123 grid=[128, 1, 1]
# id= 1 line 456 grid=[256, 1, 1]
# ...
# Works with raw logs (auto-parses)
tritonparseoss info raw_trace.ndjson
# Automatically parses and compresses, then queries
```
## Features
- **Auto-parsing**: Automatically detects and parses raw logs (no launch_diff events)
- **Compression**: Parsed files are automatically compressed using parse module's gzip functionality
- **Performance**: Uses `launch_diff` events for fast kernel listing when available
- **Error handling**: Suggests similar kernel names when kernel not found
- **Temporary files**: Parsed files saved to temp directory (not cleaned up, user can reuse)
## Testing
- 1 combined unit test covering 3 query functions
- 3 integration tests covering CLI functionality
- All tests use real data from test fixtures
- Tests verify both fast path (launch_diff) and slow path (full traversal)
## Notes
- Temporary directories are not cleaned up (as per design requirement)
- Parsed files are compressed (.ndjson.gz) for consistency with parse module
- Kernel name matching is case-sensitive (exact match only)
- Fuzzy matching uses 0.6 cutoff threshold for similarity
Pull Request resolved: #210
Test Plan:
```bash
% python -m unittest tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_query_functions tests.test_tritonparse.TestTritonparseCPU.test_info_list_kernels tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_launches tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_not_found -v
test_info_kernel_query_functions (tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_query_functions)
Test info module kernel query functions. ... ok
test_info_list_kernels (tests.test_tritonparse.TestTritonparseCPU.test_info_list_kernels)
Integration test: info command lists all kernels. ... ok
test_info_kernel_launches (tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_launches)
Integration test: info command lists launches for specific kernel. ... ok
test_info_kernel_not_found (tests.test_tritonparse.TestTritonparseCPU.test_info_kernel_not_found)
Integration test: info command handles kernel not found. ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.708s
OK
```
Reviewed By: wychi
Differential Revision: D88171129
Pulled By: FindHao
fbshipit-source-id: ff464052f8d80819912b65551a6d87ba8a184fa2info CLI Subcommand (#210)1 parent 3b40ee8 commit ab34d43
File tree
6 files changed
+420
-0
lines changed- tests
- tritonparse
- info
6 files changed
+420
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
617 | 725 | | |
618 | 726 | | |
619 | 727 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
| |||
89 | 100 | | |
90 | 101 | | |
91 | 102 | | |
| 103 | + | |
| 104 | + | |
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
| 29 | + | |
24 | 30 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
0 commit comments