mBB SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ r SSK J r J r J r SSKJr \ R (d\R""S5e\ R$"SSSS9(a\R""S5eS r\"5(d\R""S 5e"S S \R(5rS rSrSS.Sjr"SS5r\R4"\"5S5\R4"\"5S5"SS\R(\555rSr\R4"\"5S5\R4"\"SS5S5"SS\R(\555r\S:Xa\R>"5 gg)N)support) make_scriptassert_python_failureassert_python_ok)temp_dirztest module requires subprocessT)addressmemoryubz,test crash randomly on ASAN/MSAN/UBSAN buildcZ[R"S5nU(dg[U5S:H$)NPY_HAVE_PERF_TRAMPOLINEF) sysconfigget_config_varint)perf_trampolines >/opt/alt/python313/lib64/python3.13/test/test_perf_profiler.pysupports_trampoline_profilingrs)../HIO   1 $$z'perf trampoline profiling not supportedc\^\rSrSrU4SjrS U4SjjrSrSrSrSr Sr S r S r U=r $) TestPerfTrampoline&c>[TU]5 [[R"S5R S55UlgN/tmp/z perf-*.mapsupersetUpsetpathlibPathglob perf_filesself __class__s rrTestPerfTrampoline.setUp',  gll7388FGrc>[TU]5 [[R"S5R S55UR - nUHnUR5 M grrtearDownrrr r!r"unlinkr$files_to_deletefiler%s rr*TestPerfTrampoline.tearDown+M   W%**<8 9DOO K $D KKM$rc^ Sn[5n[USU5n[R"[R SU/S[R [R S9nUR5upVSSS5 SSS5 URWS5 URWS5 [R"SWRS35nURUR55 UR5nUR5n S W3S U3S U3/n U Hm [!U 4S jU 5S5n UR#U S T S35 U R%S5Sn UR'U R)S5S5 UR[+U 5R-[.R05S5 M g!,(df  GNO=f!,(df  GNY=f)Nzif 1: def foo(): pass def bar(): foo() def baz(): bar() baz() perftest-XperfTtextstderrstdout /tmp/perf-.mappy::foo:py::bar:py::baz:c38># UHnTU;dM Uv M g7fN).0lineexpected_symbols r ;TestPerfTrampoline.test_trampoline_works..XsH*$40G*s  zCould not find z in perf file r0xz&Address should not be prefixed with 0xz*Address should contain only hex characters)rr subprocessPopensys executablePIPE communicate assertEqualrr pid assertTrueexists read_text splitlinesnextassertIsNotNonesplit assertFalse startswithrissubsetstring hexdigits)r$code script_dirscriptprocessr7r6 perf_fileperf_file_contents perf_linesexpected_symbols perf_line perf_addrrCs @rtest_trampoline_works(TestPerfTrampoline.test_trampoline_works3s Z: Z>F!!62!!  !(!4!4!6  $ $LL:gkk]$!?@   ((*+&002'224 vh vh vh   0OH*H$I  __,=]K ",Q/I   $$T*,T  OOI''(8(89<  0)Zs$AG  F;3G ; G G  GcSn[5n[USU5n[R"[R SU/S[R [R S9nUR5upVSSS5 SSS5 URWRS5 URWS5 [WR55n[R"SURS 35n[R"SUS 35n URUR!55 URU R!55 UR#5n UR%S W3U 5 UR%S U3U 5 UR%S U3U 5 U R#5n UR%S U3U 5 UR%SU3U 5 UR%SU3U 5 g!,(df  GNy=f!,(df  GN=f)Naif 1: import os, sys def foo_fork(): pass def bar_fork(): foo_fork() def baz_fork(): bar_fork() def foo(): pid = os.fork() if pid == 0: print(os.getpid()) baz_fork() else: _, status = os.waitpid(-1, 0) sys.exit(status) def bar(): foo() def baz(): bar() baz() r2r3Tr4rr8r9r:r;r<r= py::foo_fork: py::bar_fork:z py::baz_fork:)rrrHrIrJrKrLrMrN returncoderstriprr rOrPrQrRassertIn) r$r\r]r^r_r7r6 child_pidr`perf_child_filerachild_perf_file_contentss r test_trampoline_works_with_forks3TestPerfTrampoline.test_trampoline_works_with_forksfs:Z: Z>F!!62!!  !(!4!4!6  ++Q/ $ ' LL:gkk]$!?@ !,,I;d'CD  ((*+ ..01&002 )+=> )+=> )+=>#2#<#<#>  fX.0HI fX.0HI fX.0HI1Zs$AG6G$2G6$ G3 .G66 HcSn[5n[USU5n[R"[R U/S[R [R S9nUR5upVSSS5 SSS5 URWS5 URWS5 [R"SWRS35nURUR55 UR5nURSW3U5 UR!S U3U5 UR!S U3U5 UR!S U3U5 g!,(df  N=f!,(df  N=f) Naif 1: import sys def foo(): pass def spam(): pass def bar(): sys.deactivate_stack_trampoline() foo() sys.activate_stack_trampoline("perf") spam() def baz(): bar() sys.activate_stack_trampoline("perf") baz() r2Tr4r8r9r:r;z py::spam:r<r=)rrrHrIrJrKrLrMrNrr rOrPrQrR assertNotInrm) r$r\r]r^r_r7r6r`ras r test_sys_apiTestPerfTrampoline.test_sys_apis8(Z: Z>F!!(!!  !(!4!4!6  $ $LL:gkk]$!?@   ((*+&002 8F8,.@A &*,>? )+=> )+=>#Zs$AEE 1E E E E,c Sn[SU5 g)Nzif 1: import sys sys.activate_stack_trampoline("perf") sys.activate_stack_trampoline("perf") -crr$r\s r%test_sys_api_with_existing_trampoline8TestPerfTrampoline.test_sys_api_with_existing_trampolines t$rcfSn[SU5up#nURSUR55 g)Nzjif 1: import sys sys.activate_stack_trampoline("invalid") rxzinvalid backend: invalid)rrmdecode)r$r\rcouterrs r$test_sys_api_with_invalid_trampoline7TestPerfTrampoline.test_sys_api_with_invalid_trampolines0-T48  0#**,?rc Sn[SU5 g)Naif 1: import sys sys.activate_stack_trampoline("perf") assert sys.is_stack_trampoline_active() is True sys.deactivate_stack_trampoline() assert sys.is_stack_trampoline_active() is False rxryrzs rtest_sys_api_get_status*TestPerfTrampoline.test_sys_api_get_statuss t$rr"returnN)__name__ __module__ __qualname____firstlineno__rr*rfrqrur{rr__static_attributes__ __classcell__r%s@rrr&s6H1f8Jt(?T%@%%rrc`[R"S5nU(dgSU;=(a SU;$)NPY_CORE_CFLAGSFzno-omit-frame-pointer_Py_JIT)rr)cflagss r)is_unwinding_reliable_with_frame_pointersrs.  % %&6 7F  "f , H&1HHrc SS/n[R"USS9nSU;ag[ 5nUS-nSSS S S S S US[ R SS4 n[R"XS[RS9nSU;a SSS5 gSSS5 g![R[4a gf=f![R[4a SSS5 gf=f!,(df  g=f)Nperfz--helpTr5Fz perf.data/perf_output.perfrecord --no-buildid--no-buildid-cache-g--call-graph=fp-o--rxzprint("hello"))cwdr5r6hello)rH check_outputSubprocessErrorOSErrorrrJrKSTDOUT)cmdr7r] output_files rperf_command_worksrs x ((48 &  z $'::K$!  C ,,$z7H7HF & 1 . !/ 4 G  & & 0:**G4 + ( ) 4 s@B CAB-3C B*)B*-CCCC C#Fuse_jitc U(a0[RR5nURU5 OSnUS-nU(d SSSSSSSUS 4 nO SSSSSS S S SUS 4 n[R "Xb-[R [R US 9nUR(a:[UR[RS9 [SUR35eU(aUS-nSSSSUSU4n [R "U [R [R US9nUR(a-[UR5 [SUR35e[R"X5 Sn[R "SSSU4[R [R USS9nURRSS5URRSS54$)Nrrrrrrrrrz--call-graph=dwarf,65528z-F99z-k1)r7r6env)r.zPerf failed with return code z/jit_output.dumpinjectz-jz-i)r6r7r)rr^r^T)r7r6rcheckzutf-8replace)osenvironcopyupdaterHrunrLrkprintr6rJ ValueErrorrenamer7r~) rrargsenv_varsrrbase_cmdprocjit_output_filecommands rrun_perfrsjjoo 8++K       +        &        >>   D   dkk +88IJKK 228T4dOT~~ JOOJOO  ?? $++ > 4-   D ;;  gy 14;;3E3E4 rc&\rSrSrSrSrSrSrg)TestPerfProfilerMixiniYc[5er?)NotImplementedError)r$r] perf_moder^s rrTestPerfProfilerMixin.run_perfZs !##rc2[5nSn[USU5nURX5upEURUS5 UR SU3U5 UR SU3U5 UR SU3U5 SSS5 g!,(df  g=f)N!if 1: def foo(n): x = 0 for i in range(n): x += i def bar(n): foo(n) def baz(n): bar(n) baz(10000000) r2r8r;r<r=)rrrrNrmr$r]r\r^r7r6s r7test_python_calls_appear_in_the_stack_if_perf_activatedMTestPerfProfilerMixin.test_python_calls_appear_in_the_stack_if_perf_activated]s Z: D!Z>F!]]:>NF   VR ( MMHVH-v 6 MMHVH-v 6 MMHVH-v 6+ZZs A4B Bc0[5nSn[USU5nURXSS9upEURUS5 UR SU3U5 UR SU3U5 UR SU3U5 SSS5 g!,(df  g=f) Nrr2F)activate_trampoliner8r;r<r=)rrrrNrtrs r@test_python_calls_do_not_appear_in_the_stack_if_perf_deactivatedVTestPerfProfilerMixin.test_python_calls_do_not_appear_in_the_stack_if_perf_deactivatedus Z: D!Z>F!]]+NF   VR (   xx0& 9   xx0& 9   xx0& 9/ZZs A3B Br@N)rrrrrrrrr@rrrrYs$70:rrzperf command doesn't workz+Unwinding is unreliable with frame pointerscH^\rSrSrSSjrU4SjrSU4SjjrSrSrU=r $) TestPerfProfileric~U(a[U[RSU5$[U[RU5$)Nr3rrJrKr$r]r^rs rrTestPerfProfiler.run_perfs- J&I I CNNF;;rc>[TU]5 [[R"S5R S55Ulgrrr#s rrTestPerfProfiler.setUpr'rc>[TU]5 [[R"S5R S55UR - nUHnUR5 M grr)r,s rr*TestPerfProfiler.tearDownr0rcSn[5n[USU5n[R"[R SU/S[R [R S9nUR5upVSSS5 SSS5 URWRS5 URSW5 [WR55n[R"SURS 35n[R"SUS 35n UR!UR#55 UR!U R#55 UR%5n UR'S W3U 5 UR'S U3U 5 UR'S U3U 5 UR'S U3U 5 U R%5n UR'S U3U 5 UR'S U3U 5 U R)S5n U H(n S U3U ;d S U3U ;dMUR'X5 M* g!,(df  GN=f!,(df  GN=f)Naif 1: import sys import os import sysconfig from _testinternalcapi import ( compile_perf_trampoline_entry, perf_trampoline_set_persist_after_fork, ) def foo_fork(): pass def bar_fork(): foo_fork() def foo(): import time; time.sleep(1) def bar(): foo() def compile_trampolines_for_all_functions(): perf_trampoline_set_persist_after_fork(1) for _, obj in globals().items(): if callable(obj) and hasattr(obj, '__code__'): compile_perf_trampoline_entry(obj.__code__) if __name__ == "__main__": compile_trampolines_for_all_functions() pid = os.fork() if pid == 0: print(os.getpid()) bar_fork() else: bar() r2r3T)universal_newlinesr6r7rzError:r9r:r;r<rirj )rrrHrIrJrKrLrMrNrkrtrrlrr rOrPrQrRrmrV)r$r\r]r^r_r7r6rnr`rorarpperf_file_linesrBs rtest_pre_fork_compile&TestPerfProfiler.test_pre_fork_compiles#JZ: Z>F!!62#'!!  !(!4!4!6  ++Q/ 6* ' LL:gkk]$!?@ !,,I;d'CD  ((*+ ..01&002 )+=> )+=> fX.0BC fX.0BC#2#<#<#>  fX.0HI fX.0HI-2248#Dvh'4/]6(3Kt3S d=$;Zs$AH5H#2H5# H2 -H55 IrTr) rrrrrrr*rrrrs@rrrs < HG>G>rrc&[R"SS/SS9nUR 5SnUR S5SnUR S 5n[ [ [USS55nX0U4:$![R[4a gf=f) Nrz --versionTrF-r.)rHrCalledProcessErrorFileNotFoundErrorrVtuplemapr)majorminoroutputversions r_is_perf_vesion_at_leastrs((&+)>TJllnQGmmC #GmmC GCWRa[)*G en $$  ) )+< =sA33BBz+perf command may not work due to a perf bugcB^\rSrSrSSjrU4SjrSU4SjjrSrU=r$)TestPerfProfilerWithDwarficzU(a[U[RSUSS9$[U[RUSS9$)Nz -Xperf_jitTrrrs rr"TestPerfProfilerWithDwarf.run_perfs8 CNNL&$  CNNFDIIrc >[TU]5 [[R"S5R S55UlU=R [[R"S5R S55-slgNrz jit*.dumpz jitted-*.sorr#s rrTestPerfProfilerWithDwarf.setUp sS  gll7388EF 3w||G499-HIIrc.>[TU]5 [[R"S5R S55nU[[R"S5R S55-nXR - nUHnUR5 M grr)r,s rr*"TestPerfProfilerWithDwarf.tearDownsn gll7388EF3w||G499-HII)OO;#D KKM$rrrr) rrrrrrr*rrrs@rrrsJJ rr__main__) unittestrZrHrJrrrshutiltestrtest.support.script_helperrrrtest.support.os_helperrhas_subprocess_supportSkipTestcheck_sanitizerrTestCaserrrrr skipUnlessrrrrmainr@rrrs     ,%%   = >> 4>   J KK%%&&   E FF|%**|%~I'T"'@F4:4:l ')+FG -/1Y>x((*?Y> H Y>x % ')+FG -a35bc 1 13HdH, z MMOr