L i ddlZddlZgdZd dededdfdZdZejd dedefdZdefd Z defd Z ejd efd Z y)N)startstopprofile metal_captureis_metal_capture_enabledis_capturing_metalmodewait_until_completedreturnc|jjdd}tjj ||y)aStart OS Signpost tracing from MPS backend. The generated OS Signposts could be recorded and viewed in XCode Instruments Logging tool. Args: mode(str): OS Signpost tracing mode could be "interval", "event", or both "interval,event". The interval mode traces the duration of execution of the operations, whereas event mode marks the completion of executions. See document `Recording Performance Data`_ for more info. wait_until_completed(bool): Waits until the MPS Stream complete executing each encoded GPU operation. This helps generating single dispatches on the trace's timeline. Note that enabling this option would affect the performance negatively. .. _Recording Performance Data: https://developer.apple.com/documentation/os/logging/recording_performance_data  N)lowerreplacetorch_C_mps_profilerStartTrace)r r mode_normalizeds X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/mps/profiler.pyrrs1(jjl**33O HH$$_6JKc@tjjy)z6Stops generating OS Signpost tracing from MPS backend.N)rr_mps_profilerStopTracerrrr)s HH##%rc#`K t||dty#twxYww)a>Context Manager to enabling generating OS Signpost tracing from MPS backend. Args: mode(str): OS Signpost tracing mode could be "interval", "event", or both "interval,event". The interval mode traces the duration of execution of the operations, whereas event mode marks the completion of executions. See document `Recording Performance Data`_ for more info. wait_until_completed(bool): Waits until the MPS Stream complete executing each encoded GPU operation. This helps generating single dispatches on the trace's timeline. Note that enabling this option would affect the performance negatively. .. _Recording Performance Data: https://developer.apple.com/documentation/os/logging/recording_performance_data N)rr)r r s rrr.s#$ d()  s. . +.c>tjjS)ztChecks if `metal_capture` context manager is usable To enable metal capture, set MTL_CAPTURE_ENABLED envvar )rr_mps_isCaptureEnabledrrrrrGs 88 ) ) ++rc>tjjS)z&Checks if metal capture is in progress)rr_mps_isCapturingrrrrrNs 88 $ $ &&rfnamec#K tjj|dtjj tjj y#tjj wxYww)zCContext manager that enables capturing of Metal calls into gputraceN)rr_mps_startCapturemps synchronize_mps_stopCapture)rs rrrSsP$ ""5)   !!#!!#sBAA$B$ BB)intervalF) contextlibr__all__strboolrrcontextmanagerrrrrrrrr+s  LLLL0&  #$0,$,'D'  $$$r