def test_frame_stats_add_disjoint(): ref_frame_stats = FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 20), height=0, children={ Frame("foobar", "foo_module.py", 5): FrameStats( label=Frame("foobar", "foo_module.py", 5), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 10), height=1, ) }, ) frame_stats = deepcopy(ref_frame_stats) << FrameStats( label=Frame("bar", "bar_module.py", 10), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 20), height=0, children={ Frame("foobar", "bar_module.py", 5): FrameStats( label=Frame("foobar", "bar_module.py", 5), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 10), height=1, ) }, ) assert frame_stats == ref_frame_stats
def test_capital_ell(): assert Sample.parse( "P1;T0x7f546684;foo_module.py:foo:10;loo_module.py:Loo:20 10", MetricType.TIME, )[0] == Sample( 1, "0x7f546684", Metric(MetricType.TIME, 10), [Frame("foo", "foo_module.py", 10), Frame("Loo", "loo_module.py", 20)], )
def test_load(): buffer = io.StringIO(DUMP_LOAD_SAMPLES.format("")) stats = AustinStats.load(buffer) assert stats[AustinStatsType.WALL] == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645646": ThreadStats( label="0x7f45645646", own=Metric(MetricType.TIME, 0), total=Metric(MetricType.TIME, 1300), children={ Frame(function="foo", filename="foo_module.py", line=10): FrameStats( label=Frame(function="foo", filename="foo_module.py", line=10), own=Metric(MetricType.TIME, 300), total=Metric(MetricType.TIME, 1300), children={ Frame( function="bar", filename="bar_sample.py", line=20, ): FrameStats( label=Frame( function="bar", filename="bar_sample.py", line=20, ), own=Metric(MetricType.TIME, 1000), total=Metric(MetricType.TIME, 1000), children={}, height=1, ) }, height=0, ) }, ) }, ) }, )
def test_sample_alt_format(): assert Sample.parse( "P1;T7fdf1b437700;/usr/lib/python3.6/threading.py:_bootstrap;L884;" "/usr/lib/python3.6/threading.py:_bootstrap_inner;L916;" "/usr/lib/python3.6/threading.py:run;L864;" "test/target34.py:keep_cpu_busy;L31 " "10085", MetricType.TIME, )[0] == Sample( 1, "7fdf1b437700", Metric(MetricType.TIME, 10085), [ Frame.parse("/usr/lib/python3.6/threading.py:_bootstrap:884"), Frame.parse( "/usr/lib/python3.6/threading.py:_bootstrap_inner:916"), Frame.parse("/usr/lib/python3.6/threading.py:run:864"), Frame.parse("test/target34.py:keep_cpu_busy:31"), ], )
def test_frame_stats_add_matching(): frame_stats = FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 20), height=0, children={ Frame("foobar", "foo_module.py", 5): FrameStats( label=Frame("foobar", "foo_module.py", 5), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 10), height=1, ) }, ) << FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 0), total=Metric(MetricType.TIME, 15), height=0, children={ Frame("foobar", "foo_module.py", 5): FrameStats( label=Frame("foobar", "foo_module.py", 5), own=Metric(MetricType.TIME, 15), total=Metric(MetricType.TIME, 15), height=1, ) }, ) assert frame_stats == FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 10), total=Metric(MetricType.TIME, 35), height=0, children={ Frame("foobar", "foo_module.py", 5): FrameStats( label=Frame("foobar", "foo_module.py", 5), own=Metric(MetricType.TIME, 25), total=Metric(MetricType.TIME, 25), height=1, ) }, )
def test_austin_stats_single_process(): stats = AustinStats(stats_type=AustinStatsType.WALL) stats.update( Sample.parse("P42;T0x7f45645646;foo_module.py:foo:10 152", MetricType.TIME)[0]) assert stats == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645646": ThreadStats( label="0x7f45645646", own=Metric(MetricType.TIME, 0), total=Metric(MetricType.TIME, 152), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 152), total=Metric(MetricType.TIME, 152), ) }, ) }, ) }, ) stats.update(Sample.parse("P42;T0x7f45645646 148", MetricType.TIME)[0]) assert stats == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645646": ThreadStats( label="0x7f45645646", total=Metric(MetricType.TIME, 300), own=Metric(MetricType.TIME, 148), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 152), total=Metric(MetricType.TIME, 152), ) }, ) }, ) }, ) stats.update( Sample.parse("P42;T0x7f45645646;foo_module.py:foo:10 100", MetricType.TIME)[0]) assert stats == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645646": ThreadStats( label="0x7f45645646", total=Metric(MetricType.TIME, 400), own=Metric(MetricType.TIME, 148), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 252), total=Metric(MetricType.TIME, 252), ) }, ) }, ) }, ) stats.update( Sample.parse("P42;T0x7f45645646;foo_module.py:bar:35 400", MetricType.TIME)[0]) assert stats == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645646": ThreadStats( label="0x7f45645646", total=Metric(MetricType.TIME, 800), own=Metric(MetricType.TIME, 148), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 252), total=Metric(MetricType.TIME, 252), ), Frame("bar", "foo_module.py", 35): FrameStats( label=Frame("bar", "foo_module.py", 35), own=Metric(MetricType.TIME, 400), total=Metric(MetricType.TIME, 400), ), }, ) }, ) }, ) stats.update( Sample.parse("P42;T0x7f45645664;foo_module.py:foo:10 152", MetricType.TIME)[0]) assert stats == AustinStats( stats_type=AustinStatsType.WALL, processes={ 42: ProcessStats( pid=42, threads={ "0x7f45645664": ThreadStats( label="0x7f45645664", own=Metric(MetricType.TIME, 0), total=Metric(MetricType.TIME, 152), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 152), total=Metric(MetricType.TIME, 152), ) }, ), "0x7f45645646": ThreadStats( label="0x7f45645646", total=Metric(MetricType.TIME, 800), own=Metric(MetricType.TIME, 148), children={ Frame("foo", "foo_module.py", 10): FrameStats( label=Frame("foo", "foo_module.py", 10), own=Metric(MetricType.TIME, 252), total=Metric(MetricType.TIME, 252), ), Frame("bar", "foo_module.py", 35): FrameStats( label=Frame("bar", "foo_module.py", 35), own=Metric(MetricType.TIME, 400), total=Metric(MetricType.TIME, 400), ), }, ), }, ) }, )
def test_sample_parser_valid(): assert Sample.parse( "P123;T0x7f546684;foo_module.py:foo:10;bar_module.py:bar:20 42", MetricType.TIME)[0] == Sample( 123, "0x7f546684", Metric(MetricType.TIME, 42), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ) assert Sample.parse( "P1;T0x7f546684;foo_module.py:foo:10;bar_module.py:bar:20 42", MetricType.TIME)[0] == Sample( 1, "0x7f546684", Metric(MetricType.TIME, 42), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ) assert Sample.parse( "P123;T0x7f546684;foo_module.py:foo:10;bar_module.py:bar:20 42,1,-44", ) == [ Sample( 123, "0x7f546684", Metric(MetricType.TIME, 0), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ), Sample( 123, "0x7f546684", Metric(MetricType.TIME, 42), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ), Sample( 123, "0x7f546684", Metric(MetricType.MEMORY, 0), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ), Sample( 123, "0x7f546684", Metric(MetricType.MEMORY, 44), [ Frame("foo", "foo_module.py", 10), Frame("bar", "bar_module.py", 20) ], ), ] assert Sample.parse("P1;T0x7f546684 42,0,44") == [ Sample( 1, "0x7f546684", Metric(MetricType.TIME, 42), [], ), Sample( 1, "0x7f546684", Metric(MetricType.TIME, 42), [], ), Sample( 1, "0x7f546684", Metric(MetricType.MEMORY, 44), [], ), Sample( 1, "0x7f546684", Metric(MetricType.MEMORY, 0), [], ), ]