a
    $ñ»j[8  ã                   @  sŽ  d dl mZ d dlZd dlmZ ddlmZmZ ddlm	Z	 ddlm
Z
 eG dd	„ d	ƒƒZeG d
d„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZddœdd„Zddœdd„Zddœdd„Zdddœdd „Zddœd!d"„Zd9d#d#d#d$d%œd&d'„Zd(dœd)d*„Zddœd+d,„Zd-dœd.d/„Zed0ƒeG d1d2„ d2ƒƒƒZed3ƒeG d4d5„ d5ƒƒƒZed6ƒeG d7d8„ d8ƒƒƒZdS ):é    )ÚannotationsN)Ú	dataclassé   )Úevent_classÚT_JSON_DICT)Údebugger)Úruntimec                   @  st   e Zd ZU dZded< ded< dZded< dZd	ed
< dZded< dZded< ddœdd„Z	e
dd dœdd„ƒZdS )ÚProfileNodez]
    Profile node. Holds callsite information,
    execution statistics and child nodes.
    ÚintÚid_zruntime.CallFrameÚ
call_frameNztyping.Optional[int]Ú	hit_countú!typing.Optional[typing.List[int]]Úchildrenútyping.Optional[str]Údeopt_reasonz.typing.Optional[typing.List[PositionTickInfo]]Úposition_ticksr   ©Úreturnc                 C  s†   t ƒ }| j|d< | j ¡ |d< | jd ur2| j|d< | jd urPdd„ | jD ƒ|d< | jd urd| j|d< | jd ur‚dd„ | jD ƒ|d	< |S )
NÚidÚ	callFrameÚhitCountc                 S  s   g | ]}|‘qS © r   ©Ú.0Úir   r   ú4E:\soccer\ml_env\Lib\site-packages\mycdp/profiler.pyÚ
<listcomp>+   ó    z'ProfileNode.to_json.<locals>.<listcomp>r   ÚdeoptReasonc                 S  s   g | ]}|  ¡ ‘qS r   ©Úto_jsonr   r   r   r   r   /   r   ÚpositionTicks)Údictr   r   r!   r   r   r   r   ©ÚselfÚjsonr   r   r   r!   $   s    






zProfileNode.to_json©r&   r   c              
   C  s¤   | t |d ƒtj |d ¡| dd ¡d ur6t |d ƒnd | dd ¡d urZdd„ |d D ƒnd | dd ¡d urxt|d ƒnd | dd ¡d urœd	d„ |d D ƒnd d
�S )Nr   r   r   r   c                 S  s   g | ]}t |ƒ‘qS r   ©r
   r   r   r   r   r   =   r   z)ProfileNode.from_json.<locals>.<listcomp>r   r"   c                 S  s   g | ]}t  |¡‘qS r   )ÚPositionTickInfoÚ	from_jsonr   r   r   r   r   G   r   )r   r   r   r   r   r   )r
   r   Z	CallFramer*   ÚgetÚstr©Úclsr&   r   r   r   r*   2   s     
ÿÿÿÿëzProfileNode.from_json)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r   r!   Úclassmethodr*   r   r   r   r   r	      s   
r	   c                   @  sd   e Zd ZU dZded< ded< ded< dZded	< dZded
< ddœdd„Zedd dœdd„ƒZ	dS )ÚProfilezProfile.ztyping.List[ProfileNode]ÚnodesÚfloatÚ
start_timeÚend_timeNr   ÚsamplesÚtime_deltasr   r   c                 C  sn   t ƒ }dd„ | jD ƒ|d< | j|d< | j|d< | jd urLdd„ | jD ƒ|d< | jd urjdd„ | jD ƒ|d	< |S )
Nc                 S  s   g | ]}|  ¡ ‘qS r   r    r   r   r   r   r   _   r   z#Profile.to_json.<locals>.<listcomp>r6   Ú	startTimeÚendTimec                 S  s   g | ]}|‘qS r   r   r   r   r   r   r   c   r   r:   c                 S  s   g | ]}|‘qS r   r   r   r   r   r   r   e   r   Ú
timeDeltas)r#   r6   r8   r9   r:   r;   r$   r   r   r   r!   ]   s    



zProfile.to_jsonr'   c              	   C  st   | dd„ |d D ƒt |d ƒt |d ƒ| dd ¡d urHdd„ |d D ƒnd | dd ¡d urld	d„ |d D ƒnd d
�S )Nc                 S  s   g | ]}t  |¡‘qS r   )r	   r*   r   r   r   r   r   k   r   z%Profile.from_json.<locals>.<listcomp>r6   r<   r=   r:   c                 S  s   g | ]}t |ƒ‘qS r   r(   r   r   r   r   r   o   r   r>   c                 S  s   g | ]}t |ƒ‘qS r   r(   r   r   r   r   r   t   r   )r6   r8   r9   r:   r;   )r7   r+   r-   r   r   r   r*   h   s    

ÿÿôzProfile.from_json)
r/   r0   r1   r2   r3   r:   r;   r!   r4   r*   r   r   r   r   r5   N   s   
r5   c                   @  sD   e Zd ZU dZded< ded< ddœdd„Zedd d	œd
d„ƒZdS )r)   zDSpecifies number of samples attributed to a certain source position.r
   ÚlineÚticksr   r   c                 C  s   t ƒ }| j|d< | j|d< |S )Nr?   r@   )r#   r?   r@   r$   r   r   r   r!   ƒ   s    

zPositionTickInfo.to_jsonr'   c                 C  s   | t |d ƒt |d ƒd�S )Nr?   r@   )r?   r@   r(   r-   r   r   r   r*   ‰   s    

þzPositionTickInfo.from_jsonN©r/   r0   r1   r2   r3   r!   r4   r*   r   r   r   r   r)   {   s   
r)   c                   @  sL   e Zd ZU dZded< ded< ded< ddœdd	„Zedd d
œdd„ƒZdS )ÚCoverageRangez!Coverage data for a source range.r
   Ústart_offsetÚ
end_offsetÚcountr   r   c                 C  s(   t ƒ }| j|d< | j|d< | j|d< |S )NÚstartOffsetÚ	endOffsetrE   )r#   rC   rD   rE   r$   r   r   r   r!   ›   s
    


zCoverageRange.to_jsonr'   c                 C  s&   | t |d ƒt |d ƒt |d ƒd�S )NrF   rG   rE   )rC   rD   rE   r(   r-   r   r   r   r*   ¢   s
    


ýzCoverageRange.from_jsonNrA   r   r   r   r   rB   ‘   s   
rB   c                   @  sL   e Zd ZU dZded< ded< ded< dd	œd
d„Zedd dœdd„ƒZdS )ÚFunctionCoveragez(Coverage data for a JavaScript function.r,   Úfunction_nameztyping.List[CoverageRange]ÚrangesÚboolÚis_block_coverager   r   c                 C  s2   t ƒ }| j|d< dd„ | jD ƒ|d< | j|d< |S )NÚfunctionNamec                 S  s   g | ]}|  ¡ ‘qS r   r    r   r   r   r   r   ¸   r   z,FunctionCoverage.to_json.<locals>.<listcomp>rJ   ÚisBlockCoverage)r#   rI   rJ   rL   r$   r   r   r   r!   µ   s
    

zFunctionCoverage.to_jsonr'   c                 C  s,   | t |d ƒdd„ |d D ƒt|d ƒd�S )NrM   c                 S  s   g | ]}t  |¡‘qS r   )rB   r*   r   r   r   r   r   À   r   z.FunctionCoverage.from_json.<locals>.<listcomp>rJ   rN   )rI   rJ   rL   )r,   rK   r-   r   r   r   r*   ¼   s
    

ýzFunctionCoverage.from_jsonNrA   r   r   r   r   rH   «   s   
rH   c                   @  sL   e Zd ZU dZded< ded< ded< dd	œd
d„Zedd dœdd„ƒZdS )ÚScriptCoveragez&Coverage data for a JavaScript script.zruntime.ScriptIdÚ	script_idr,   Úurlztyping.List[FunctionCoverage]Ú	functionsr   r   c                 C  s6   t ƒ }| j ¡ |d< | j|d< dd„ | jD ƒ|d< |S )NÚscriptIdrQ   c                 S  s   g | ]}|  ¡ ‘qS r   r    r   r   r   r   r   Ó   r   z*ScriptCoverage.to_json.<locals>.<listcomp>rR   )r#   rP   r!   rQ   rR   r$   r   r   r   r!   Ï   s
    
zScriptCoverage.to_jsonr'   c                 C  s0   | t j |d ¡t|d ƒdd„ |d D ƒd�S )NrS   rQ   c                 S  s   g | ]}t  |¡‘qS r   )rH   r*   r   r   r   r   r   Û   s   z,ScriptCoverage.from_json.<locals>.<listcomp>rR   )rP   rQ   rR   )r   ZScriptIdr*   r,   r-   r   r   r   r*   Ö   s    
ÿýzScriptCoverage.from_jsonNrA   r   r   r   r   rO   Å   s   
rO   z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None]r   c                  c  s   ddi} | V }d S )NÚmethodzProfiler.disabler   ©Úcmd_dictr&   r   r   r   Údisableá   s    ÿrW   c                  c  s   ddi} | V }d S )NrT   zProfiler.enabler   rU   r   r   r   Úenableè   s    ÿrX   zGtyping.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[ScriptCoverage]]c                  c  s    ddi} | V }dd„ |d D ƒS )z°
    Collect coverage data for the current isolate.
    The coverage data may be incomplete due to garbage collection.
    :returns: Coverage data for the current isolate.
    rT   zProfiler.getBestEffortCoveragec                 S  s   g | ]}t  |¡‘qS r   ©rO   r*   r   r   r   r   r   û   r   z,get_best_effort_coverage.<locals>.<listcomp>Úresultr   rU   r   r   r   Úget_best_effort_coverageï   s    	ÿr[   r
   )Úintervalr   c                 c  s"   t ƒ }| |d< d|dœ}|V }dS )z§
    Changes CPU profiler sampling interval.
    Must be called before CPU profiles recording started.
    :param interval: New sampling interval in microseconds.
    r\   zProfiler.setSamplingInterval©rT   ÚparamsN)r#   )r\   r^   rV   r&   r   r   r   Úset_sampling_intervalþ   s    þr_   c                  c  s   ddi} | V }d S )NrT   zProfiler.startr   rU   r   r   r   Ústart  s    ÿr`   ztyping.Optional[bool]z1typing.Generator[T_JSON_DICT, T_JSON_DICT, float])Ú
call_countÚdetailedÚallow_triggered_updatesr   c                 c  sR   t ƒ }| dur| |d< |dur&||d< |dur6||d< d|dœ}|V }t|d ƒS )ao  
    Enable precise code coverage.
    Coverage data for JavaScript executed before enabling precise code coverage
    may be incomplete.
    Enabling prevents running optimized code and resets execution counters.
    :param call_count: *(Optional)*
     Collect accurate call counts beyond simple 'covered' or 'not covered'.
    :param detailed: *(Optional)*
     Collect block-based coverage.
    :param allow_triggered_updates: *(Optional)*
     Allow the backend to send updates on its own initiative.
    :returns: Monotonically increasing time (in seconds)
     when the coverage update was taken in the backend.
    NZ	callCountrb   ZallowTriggeredUpdateszProfiler.startPreciseCoverager]   Ú	timestamp)r#   r7   )ra   rb   rc   r^   rV   r&   r   r   r   Ústart_precise_coverage  s    þre   z3typing.Generator[T_JSON_DICT, T_JSON_DICT, Profile]c                  c  s   ddi} | V }t  |d ¡S )z%
    :returns: Recorded profile.
    rT   zProfiler.stopÚprofile)r5   r*   rU   r   r   r   Ústop8  s    ÿrg   c                  c  s   ddi} | V }dS )zŒ
    Disable precise code coverage.
    Disabling releases unnecessary execution count records and allows
    executing optimized code.
    rT   zProfiler.stopPreciseCoverageNr   rU   r   r   r   Ústop_precise_coverageC  s    	ÿrh   z\typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.Tuple[typing.List[ScriptCoverage], float]]c                  c  s,   ddi} | V }dd„ |d D ƒt |d ƒfS )ay  
    Collect coverage data for the current isolate,
    and resets execution counters. Precise code coverage needs to have started.
    :returns: A tuple with the following items:
        0. **result** - Coverage data for the current isolate.
        1. **timestamp** - Monotonically increasing time (in seconds)
         when the coverage update was taken in the backend.
    rT   zProfiler.takePreciseCoveragec                 S  s   g | ]}t  |¡‘qS r   rY   r   r   r   r   r   c  r   z)take_precise_coverage.<locals>.<listcomp>rZ   rd   )r7   rU   r   r   r   Útake_precise_coverageQ  s    ÿ
þri   zProfiler.consoleProfileFinishedc                   @  sB   e Zd ZU ded< ded< ded< ded< ed	d d
œdd„ƒZdS )ÚConsoleProfileFinishedr,   r   údebugger.LocationÚlocationr5   rf   r   Útitler   r'   c                 C  sJ   | t |d ƒtj |d ¡t |d ¡| dd ¡d urBt |d ƒnd d�S )Nr   rl   rf   rm   )r   rl   rf   rm   )r,   r   ÚLocationr*   r5   r+   r-   r   r   r   r*   r  s    
ÿùz ConsoleProfileFinished.from_jsonN)r/   r0   r1   r3   r4   r*   r   r   r   r   rj   h  s   
rj   zProfiler.consoleProfileStartedc                   @  s>   e Zd ZU dZded< ded< ded< edd d	œd
d„ƒZdS )ÚConsoleProfileStartedzR
    Sent when new profile recording is started using console.profile() call.
    r,   r   rk   rl   r   rm   r   r'   c                 C  s>   | t |d ƒtj |d ¡| dd ¡d ur6t |d ƒnd d�S )Nr   rl   rm   )r   rl   rm   )r,   r   rn   r*   r+   r-   r   r   r   r*   Œ  s    
ÿúzConsoleProfileStarted.from_jsonN©r/   r0   r1   r2   r3   r4   r*   r   r   r   r   ro   €  s   
ro   z#Profiler.preciseCoverageDeltaUpdatec                   @  s>   e Zd ZU dZded< ded< ded< edd d	œd
d„ƒZdS )ÚPreciseCoverageDeltaUpdatea_  
    Reports coverage delta since the last poll (either from an event like this,
    or from `takePreciseCoverage` for the current isolate.
    May only be sent if precise code coverage has been started.
    This event can be trigged by the embedder to, for example,
    trigger collection of coverage data immediately at a certain point in time.
    r7   rd   r,   Úoccasionztyping.List[ScriptCoverage]rZ   r   r'   c                 C  s,   | t |d ƒt|d ƒdd„ |d D ƒd�S )Nrd   rr   c                 S  s   g | ]}t  |¡‘qS r   rY   r   r   r   r   r   °  r   z8PreciseCoverageDeltaUpdate.from_json.<locals>.<listcomp>rZ   )rd   rr   rZ   )r7   r,   r-   r   r   r   r*   «  s
    

ýz$PreciseCoverageDeltaUpdate.from_jsonNrp   r   r   r   r   rq   ™  s   
	rq   )NNN)Ú
__future__r   ÚtypingÚdataclassesr   Úutilr   r   Ú r   r   r	   r5   r)   rB   rH   rO   rW   rX   r[   r_   r`   re   rg   rh   ri   rj   ro   rq   r   r   r   r   Ú<module>   sL   =,   ý"