K i ddlZddlZddlmZddlmZmZddlmZddl m Z ejZ eeefZGddZGd d eZdd d ed eeeefdeefdZddd d eed eeeefdeefdZy)Nwraps)OptionalUnion)get_profiling_on)protoncTeZdZdZd dedeeeefddfdZdZ dZ d Z d Z d Z y) scopea  A context manager and decorator for entering and exiting a scope. Usage: context manager: ```python with proton.scope("test0", {metric_name: metric_value}): foo[1,](x, y) ``` decorator: ```python @proton.scope("test0", {metric_name: metric_value}) def foo(x, y): ... ``` Args: name (str): The name of the scope. metrics (dict[str, float], optional): The metrics of the scope. Default is None. Nnamemetricsreturnc.||_||_d|_yNr r id)selfr r s [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/triton/profiler/scope.py__init__zscope.__init__%s  ctsytj|_tj|j|j |j r+tj|j|j yyr)r libproton record_scoper enter_scoper r add_metricsrs r _enter_scopezscope._enter_scope*sW! ((*dggtyy1 <<  ! !$''4<< 8 rctr |jytj|j|jyr)rrr exit_scoper rs r _exit_scopezscope._exit_scope2s+!TWW_ TWWdii0rc&|j|Sr)rrs r __enter__zscope.__enter__7s  rc$|jyr)r )rexc_type exc_value tracebacks r__exit__zscope.__exit__;s rc2tfd}|S)Ncj |i|jS#jwxYwr)rr )argskwargsfuncrs rwrapperzscope.__call__..wrapper@s:     #T,V,  "  "s+=r)rr,r-s`` r__call__zscope.__call__>s t #  #rr)__name__ __module__ __qualname____doc__strrdictMetricValueTyperrr r"r'r.rrr r sJ,S8Do9M4N+O[_ 91  rr cVeZdZdZd dedeeeefddffd ZfdZ fdZ xZ S) cpu_timed_scopez A scope that measures elapsed time (cpu_time). Args: name (str): The name of the scope. metrics (dict[str, float], optional): Additional metrics to add. Default is None. Nr r rcXt|||d|_|rd|vr tdyy)Ncpu_timez'The metric name 'cpu_time' is reserved.)superr start_time ValueError)rr r __class__s rrzcpu_timed_scope.__init__Ts6 w' zW,FG G-7rcjtsytj|_t|yr)rtimetime_nsr<r;r)rr>s rrzcpu_timed_scope._enter_scopeZs$! ,,. rctsyt| |jDt j |jz }t j|jd|iyy)Nzcpu_time (ns)(exc)) rr;r r<r@rArrr)rr:r>s rr zcpu_timed_scope._exit_scope`sT!   ?? &||~7H  ! !$'',@(+K L 'rr) r/r0r1r2r3rr4floatrrr __classcell__)r>s@rr8r8KsFHSH8De4D+EHQUH  MMrr8)r r r rctsytj}ttdgt_tj j ||ftj|||rtj|||S)Nscopes) rrrgetattrthread_local_scopesrFappendrrrs rrrisl      !B!()rTs "#3%ioo's #::zMeM<OS c xS/5I0J'K W_`cWd  ^b Xc] xS/EY@Z7[ gopsgt r