| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -533,11 +533,10 @@ one write() call (or feeds through the compression stream). | |||
| 533 | 533 | ||
| 534 | 534 | ## Future Considerations | |
| 535 | 535 | ||
| 536 | - The format reserves space for future extensions. The 12 reserved bytes in | ||
| 537 | - the header could hold additional metadata. The 16-byte checksum field in | ||
| 538 | - the footer is currently unused. The version field allows incompatible | ||
| 539 | - changes with graceful rejection. New compression types could be added | ||
| 540 | - (compression_type > 1). | ||
| 536 | + The Python-version field retains one reserved byte. The 16-byte checksum | ||
| 537 | + field in the footer is currently unused. The version field allows | ||
| 538 | + incompatible changes with graceful rejection. New compression types could | ||
| 539 | + be added (compression_type > 1). | ||
| 541 | 540 | ||
| 542 | 541 | Any changes that alter the meaning of existing fields or the parsing logic | |
| 543 | 542 | should increment the version number to prevent older readers from | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,7 +120,7 @@ def convert_binary_to_format(input_file, output_file, output_format, | |||
| 120 | 120 | elif output_format == 'gecko': | |
| 121 | 121 | collector = GeckoCollector(interval) | |
| 122 | 122 | elif output_format == "jsonl": | |
| 123 | - collector = JsonlCollector(interval) | ||
| 123 | + collector = JsonlCollector(interval, mode=info.get("mode")) | ||
| 124 | 124 | else: | |
| 125 | 125 | raise ValueError(f"Unknown output format: {output_format}") | |
| 126 | 126 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -761,6 +761,7 @@ def _replay_with_reader(args, reader): | |||
| 761 | 761 | ||
| 762 | 762 | collector = _create_collector( | |
| 763 | 763 | args.format, interval, skip_idle=False, | |
| 764 | + mode=info.get("mode"), | ||
| 764 | 765 | diff_baseline=args.diff_baseline | |
| 765 | 766 | ) | |
| 766 | 767 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1598,8 +1598,10 @@ def test_timestamp_preservation_with_rle(self): | |||
| 1598 | 1598 | class TestBinaryReplayToJsonl(BinaryFormatTestBase): | |
| 1599 | 1599 | """Tests for binary -> JSONL replay via convert_binary_to_format.""" | |
| 1600 | 1600 | ||
| 1601 | - def _replay_to_jsonl(self, samples, interval=1000): | ||
| 1602 | - bin_path = self.create_binary_file(samples, interval=interval) | ||
| 1601 | + def _replay_to_jsonl(self, samples, interval=1000, mode=None): | ||
| 1602 | + bin_path = self.create_binary_file( | ||
| 1603 | + samples, interval=interval, mode=mode | ||
| 1604 | + ) | ||
| 1603 | 1605 | with tempfile.NamedTemporaryFile(suffix=".jsonl", delete=False) as f: | |
| 1604 | 1606 | jsonl_path = f.name | |
| 1605 | 1607 | self.temp_files.append(jsonl_path) | |
@@ -1629,6 +1631,16 @@ def test_binary_replay_to_jsonl_basic(self): | |||
| 1629 | 1631 | self.assertEqual(len(frame_defs), 1) | |
| 1630 | 1632 | self.assertEqual(frame_defs[0]["line"], 99) | |
| 1631 | 1633 | ||
| 1634 | + def test_binary_replay_to_jsonl_preserves_mode(self): | ||
| 1635 | + frame = make_frame("hot.py", 99, "hot_func") | ||
| 1636 | + records = self._replay_to_jsonl( | ||
| 1637 | + [[make_interpreter(0, [make_thread(1, [frame])])]], | ||
| 1638 | + mode=PROFILING_MODE_CPU, | ||
| 1639 | + ) | ||
| 1640 | + | ||
| 1641 | + meta = next(record for record in records if record["type"] == "meta") | ||
| 1642 | + self.assertEqual(meta["mode"], "cpu") | ||
| 1643 | + | ||
| 1632 | 1644 | def test_binary_replay_to_jsonl_rle_weight_propagation(self): | |
| 1633 | 1645 | """RLE-batched identical samples land as a single agg entry with the right total.""" | |
| 1634 | 1646 | frame = make_frame("rle.py", 42, "rle_func") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ | |||
| 29 | 29 | _create_collector, | |
| 30 | 30 | _generate_output_filename, | |
| 31 | 31 | _handle_output, | |
| 32 | + _replay_with_reader, | ||
| 32 | 33 | main, | |
| 33 | 34 | ) | |
| 34 | 35 | from profiling.sampling.constants import ( | |
@@ -964,6 +965,39 @@ def test_cli_replay_reader_errors_exit_cleanly(self): | |||
| 964 | 965 | "Error: Unsupported format version 2", | |
| 965 | 966 | ) | |
| 966 | 967 | ||
| 968 | + def test_cli_replay_propagates_recorded_mode(self): | ||
| 969 | + reader = mock.MagicMock() | ||
| 970 | + reader.get_info.return_value = { | ||
| 971 | + "sample_interval_us": 1000, | ||
| 972 | + "sample_count": 0, | ||
| 973 | + "compression_type": 0, | ||
| 974 | + "mode": PROFILING_MODE_CPU, | ||
| 975 | + } | ||
| 976 | + reader.replay_samples.return_value = 0 | ||
| 977 | + collector = mock.MagicMock() | ||
| 978 | + collector.export.return_value = True | ||
| 979 | + args = SimpleNamespace( | ||
| 980 | + format="diff_flamegraph", | ||
| 981 | + input_file="current.bin", | ||
| 982 | + diff_baseline="baseline.bin", | ||
| 983 | + outfile="diff.html", | ||
| 984 | + browser=False, | ||
| 985 | + ) | ||
| 986 | + | ||
| 987 | + with mock.patch( | ||
| 988 | + "profiling.sampling.cli._create_collector", | ||
| 989 | + return_value=collector, | ||
| 990 | + ) as create_collector: | ||
| 991 | + _replay_with_reader(args, reader) | ||
| 992 | + | ||
| 993 | + create_collector.assert_called_once_with( | ||
| 994 | + "diff_flamegraph", | ||
| 995 | + 1000, | ||
| 996 | + skip_idle=False, | ||
| 997 | + mode=PROFILING_MODE_CPU, | ||
| 998 | + diff_baseline="baseline.bin", | ||
| 999 | + ) | ||
| 1000 | + | ||
| 967 | 1001 | def test_cli_jsonl_format_mutually_exclusive_with_pstats(self): | |
| 968 | 1002 | """--jsonl and --pstats cannot be combined (mutually exclusive group).""" | |
| 969 | 1003 | with ( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments