|
7 | 7 | import struct |
8 | 8 | import tempfile |
9 | 9 | import unittest |
| 10 | +from types import SimpleNamespace |
10 | 11 | from unittest import mock |
11 | 12 | from collections import defaultdict |
12 | 13 |
|
13 | | -from test.support import captured_stderr |
| 14 | +from test.support import captured_stderr, captured_stdout, run_with_locale |
14 | 15 |
|
15 | 16 | try: |
16 | 17 | import _remote_debugging |
|
28 | 29 | ) |
29 | 30 | from profiling.sampling.binary_collector import BinaryCollector |
30 | 31 | from profiling.sampling.binary_reader import BinaryReader, convert_binary_to_format |
| 32 | + from profiling.sampling.cli import _replay_with_reader |
31 | 33 | from profiling.sampling.constants import PROFILING_MODE_CPU |
32 | 34 | from profiling.sampling.gecko_collector import GeckoCollector |
33 | 35 |
|
@@ -1937,6 +1939,41 @@ def test_original_stats_extension_remains_readable(self): |
1937 | 1939 | self.assertIsNone(info["missed_samples"]) |
1938 | 1940 |
|
1939 | 1941 |
|
| 1942 | +class TestBinaryReplayToHeatmap(unittest.TestCase): |
| 1943 | + @run_with_locale("LC_NUMERIC", "C") |
| 1944 | + def test_replay_with_and_without_persisted_stats(self): |
| 1945 | + frame = make_frame(__file__, 1, "hot_func") |
| 1946 | + for with_stats in (True, False): |
| 1947 | + with ( |
| 1948 | + self.subTest(with_stats=with_stats), |
| 1949 | + tempfile.TemporaryDirectory() as tmp, |
| 1950 | + captured_stdout(), |
| 1951 | + ): |
| 1952 | + bin_path = os.path.join(tmp, "profile.bin") |
| 1953 | + with BinaryCollector(bin_path, 2000, compression="none") as collector: |
| 1954 | + collector.collect([ |
| 1955 | + make_interpreter(0, [make_thread(1, [frame])]) |
| 1956 | + ]) |
| 1957 | + if with_stats: |
| 1958 | + collector.set_stats( |
| 1959 | + 2000, 2.5, 0.4, error_rate=2.0, missed_samples=1.5 |
| 1960 | + ) |
| 1961 | + args = SimpleNamespace( |
| 1962 | + format="heatmap", input_file=bin_path, |
| 1963 | + outfile=tmp, diff_baseline=None, |
| 1964 | + ) |
| 1965 | + with BinaryReader(bin_path) as reader: |
| 1966 | + _replay_with_reader(args, reader) |
| 1967 | + content = pathlib.Path(tmp, "index.html").read_text( |
| 1968 | + encoding="utf-8" |
| 1969 | + ) |
| 1970 | + if with_stats: |
| 1971 | + self.assertIn('<span class="stat-value">2.5 sec</span>', content) |
| 1972 | + self.assertIn('<span class="stat-value">0.4</span>', content) |
| 1973 | + self.assertIn('<span class="rate-value">2.0%</span>', content) |
| 1974 | + self.assertIn('<span class="rate-value">1.5%</span>', content) |
| 1975 | + |
| 1976 | + |
1940 | 1977 | class TestBinaryReplayToJsonl(BinaryFormatTestBase): |
1941 | 1978 | """Tests for binary -> JSONL replay via convert_binary_to_format.""" |
1942 | 1979 |
|
|
0 commit comments