
    &`iR"                     b   d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlZ G d d          Zdej        v Z e            Z ed d	d
ddddddddddd          Z ed           G d d                      Z ed           G d d                      ZddZde	e         defdZdS )    N)defaultdict)asdict	dataclass)DictListUnionc                       e Zd ZdZd Zd ZdS )_NullLogSpanz,A log span context manager that does nothingc                     d S N )selfs    j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/profiling.py	__enter__z_NullLogSpan.__enter__           c                     d S r   r   )r   typevaluetbs       r   __exit__z_NullLogSpan.__exit__   r   r   N)__name__
__module____qualname____doc__r   r   r   r   r   r
   r
   
   s8        66      r   r
   RAY_PROFILINGc                      dS )Ngeneric_workr   r   r   r   <lambda>r      s    N r   cq_build_abandonedrail_response	rail_loadrail_animation	rail_idledetailed_memory_dumpgoodterriblevsync_highlight_colorbackground_memory_dump)worker_idletaskztask:deserialize_argumentsztask:executeztask:store_outputswait_for_functionzray.getzray.putzray.waitsubmit_taskfetch_and_run_functionregister_remote_functionT)initc                       e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   eed<   eeeeef         f         ed<   d	Zeed
<   dS )ChromeTracingCompleteEventcatnamepidtidtsdurcnameargsXphN)	r   r   r   str__annotations__intr   r   r<   r   r   r   r2   r2   ,   s~          
HHH
III 
HHH	HHHGGG	HHHJJJ
sE#s(O#
$$$$BMMMMMr   r2   c                   Z    e Zd ZU eed<   eeef         ed<   eed<   dZeed<   dZeed<   dS )ChromeTracingMetadataEventr4   r:   r5   Nr6   Mr<   )	r   r   r   r=   r>   r   r?   r6   r<   r   r   r   rA   rA   F   sR          III
sCx.	HHHCOOOBMMMMMr   rA   c                     t           st          S t          j        j        j        }|j        t          j        j        j        k    rt          S |j        	                    | 
                    d          |          S )aF  Profile a span of time so that it appears in the timeline visualization.

    Note that this only works in the raylet code path.

    This function can be used as follows (both on the driver or within a task).

    .. testcode::
        import ray._private.profiling as profiling

        with profiling.profile("custom event", extra_data={'key': 'val'}):
            # Do some computation here.
            x = 1 * 2

    Optionally, a dictionary can be passed as the "extra_data" argument, and
    it can have keys "name" and "cname" if you want to override the default
    timeline display text and box color. Other values will appear at the bottom
    of the chrome tracing GUI when you click on the box corresponding to this
    profile span.

    Args:
        event_type: A string describing the type of the event.
        extra_data: This must be a dictionary mapping strings to strings. This
            data will be added to the json objects that are used to populate
            the timeline, so if you want to set a particular color, you can
            simply set the "cname" attribute to an appropriate color.
            Similarly, if you set the "name" attribute, then that will set the
            text displayed on the box in the timeline.

    Returns:
        An object that can profile a span of time via a "with" statement.
    ascii)PROFILING_ENABLEDNULL_LOG_SPANray_privateworkerglobal_workermode
LOCAL_MODEcore_workerprofile_eventencode)
event_type
extra_datarI   s      r   profilerR   T   sb    @  \ .F{cl)444++J,=,=g,F,F
SSSr   tasksreturnc                 t   g }i }d}i }d}| D ]j}|                     dg           }|rN|d         }|d         }	|d         }
|
dz   |d         z   }|
dvrG|	D ]}|d	         }|d
         |d
<   |d         |d<   |d         |d<   |d         |d<   |d         |d<   |d         }||vr
|||<   |dz  }||         |f|vr||||         |f<   |dz  }t          |d                  }|}d|v rt          |d	         d                  }d|v r|d         }t          ||||         |||         |f         |d         dz  |d         dz  |d         dz  z
  ||          }|                    t	          |                     !l|                                D ]<\  }}|                    t	          t          d|dd| i                               =|                                D ]G\  }}|                    t	          t          dd||d         d|d         i                               Ht          j        |          S )zGenerate a chrome/perfetto tracing dump using task events.

    Args:
        tasks: List of tasks generated by a state API list_tasks(detail=True).

    Returns:
        Json serialized dump to create a chrome/perfetto tracing.
    r   profiling_datanode_ip_addresseventscomponent_type:component_id)rI   driverrQ   task_idjob_idattempt_numberfunc_or_class_nameactor_id
event_name   r9   r4   
start_timeg     @@end_time)r3   r4   r5   r6   r7   r8   r9   r:   process_namezNode )r4   r5   r:   thread_namerB   )r4   r<   r6   r5   r:   )	get_default_color_mappingr2   appendr   itemsrA   jsondumps)rS   
all_eventsnode_to_indexnode_idxworker_to_index
worker_idxr+   rV   rW   component_eventsrY   r[   eventrQ   rb   r9   r4   	new_eventnodeirI   s                        r   chrome_tracing_dumprx   |   s/    J MHOJ 75 75"2B77 5	5,->?O-h7+,<=N)C/.2PPL%999) ,5 ,5"<0
(,Y
9%'+H~
8$/34D/E
+,378L3M
/0)-j)9
:&"<0
 #-775=M/2MH "/2  )) ) # $&7F !OJ /u\/BC!j((253Fw3OPEZ''%f-D6"%o6')G(VW\*S0z*S0U<5H35NO#	 	 		 !!&"3"34444 &&(( 	
 	
a*' .$..1   	
 	
 	
 	
 %**,, 
 
	*&q	 &),   
	
 
	
 
	
 
	
 :j!!!r   r   )rl   oscollectionsr   dataclassesr   r   typingr   r   r   rG   r
   environrE   rF   ri   r2   rA   rR   dictr=   rx   r   r   r   <module>r      s    				 # # # # # # ) ) ) ) ) ) ) ) $ $ $ $ $ $ $ $ $ $ 



        $rz1  %+&1()3+/"8$:   &        2 
 
 
 
 
 
 
 
%T %T %T %TPt":t"t" t" t" t" t" t"r   