@@ -1665,7 +1665,7 @@ def test_diff_flamegraph_elided_stacks(self):
16651665
16661666 data = diff ._convert_to_flamegraph_format ()
16671667
1668- self .assertGreater (data ["stats" ]["elided_count" ], 0 )
1668+ self .assertEqual (data ["stats" ]["elided_count" ], 1 )
16691669 self .assertIn ("elided_flamegraph" , data ["stats" ])
16701670 elided = data ["stats" ]["elided_flamegraph" ]
16711671 self .assertTrue (elided ["stats" ]["is_differential" ])
@@ -1681,6 +1681,74 @@ def test_diff_flamegraph_elided_stacks(self):
16811681 self .assertGreater (child ["baseline" ], 0 )
16821682 self .assertAlmostEqual (child ["diff" ], - child ["baseline" ])
16831683
1684+ def test_diff_flamegraph_counts_elided_stacks_not_paths (self ):
1685+ """Internal and leaf stack endings are counted separately."""
1686+ internal_stack = [
1687+ MockInterpreterInfo (0 , [
1688+ MockThreadInfo (1 , [
1689+ MockFrameInfo ("file.py" , 20 , "old_mid" ),
1690+ MockFrameInfo ("file.py" , 10 , "root" ),
1691+ ])
1692+ ])
1693+ ]
1694+ leaf_stack = [
1695+ MockInterpreterInfo (0 , [
1696+ MockThreadInfo (1 , [
1697+ MockFrameInfo ("file.py" , 30 , "old_leaf" ),
1698+ MockFrameInfo ("file.py" , 20 , "old_mid" ),
1699+ MockFrameInfo ("file.py" , 10 , "root" ),
1700+ ])
1701+ ])
1702+ ]
1703+ current_frames = [
1704+ MockInterpreterInfo (0 , [
1705+ MockThreadInfo (1 , [MockFrameInfo ("file.py" , 10 , "root" )])
1706+ ])
1707+ ]
1708+
1709+ diff = make_diff_collector_with_mock_baseline (
1710+ [internal_stack , leaf_stack ]
1711+ )
1712+ diff .collect (current_frames )
1713+
1714+ data = diff ._convert_to_flamegraph_format ()
1715+ self .assertEqual (data ["stats" ]["elided_count" ], 2 )
1716+
1717+ def test_diff_flamegraph_renders_small_elided_stack (self ):
1718+ """Elided stacks are not removed by the significance filter."""
1719+ common_frames = [
1720+ MockInterpreterInfo (0 , [
1721+ MockThreadInfo (1 , [
1722+ MockFrameInfo ("file.py" , 20 , "common" ),
1723+ MockFrameInfo ("file.py" , 10 , "root" ),
1724+ ])
1725+ ])
1726+ ]
1727+ old_frames = [
1728+ MockInterpreterInfo (0 , [
1729+ MockThreadInfo (1 , [
1730+ MockFrameInfo ("file.py" , 30 , "old_tiny" ),
1731+ MockFrameInfo ("file.py" , 10 , "root" ),
1732+ ])
1733+ ])
1734+ ]
1735+
1736+ diff = make_diff_collector_with_mock_baseline (
1737+ [common_frames ] * 1999 + [old_frames ]
1738+ )
1739+ for _ in range (1999 ):
1740+ diff .collect (common_frames )
1741+
1742+ data = diff ._convert_to_flamegraph_format ()
1743+ self .assertEqual (data ["stats" ]["elided_count" ], 1 )
1744+ self .assertIn ("elided_flamegraph" , data ["stats" ])
1745+
1746+ elided = data ["stats" ]["elided_flamegraph" ]
1747+ strings = elided ["strings" ]
1748+ self .assertIsNotNone (
1749+ find_child_by_name (elided .get ("children" , []), strings , "old_tiny" )
1750+ )
1751+
16841752 def test_diff_flamegraph_elided_top_level_root (self ):
16851753 """Elided top-level roots do not crash metadata generation."""
16861754 baseline_frames_1 = [
0 commit comments