Ë
    r™ãjA'  ã                  ó˜  — U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ dd	l
mZ d
dlmZ d
dlmZ d
dlmZ d
dlmZ d
dlmZ d
dlmZ ddlmZ ddlmZ 	 ddlZdZded<   	 da ded<   	 dd„Z! G d„ d«      Z"	 d	 	 	 	 	 	 	 dd„Z#ejH                  dd d„«       Z%y# e$ r dZY ŒIw xY w)!z§Profiling support for unit and performance tests.

These are special purpose profiling methods which operate
in a more fine-grained way than nose's profiling plugin.

é    )ÚannotationsN)ÚAny)ÚCallable)ÚDefaultDict)Ú	Generator)ÚOptional)ÚTupleé   )Úconfig)Ú	provision)ÚPlatformKey)ÚProfilesFile)ÚTestKey)Ú
gc_collecté   )Úfreethreading)Úhas_compiled_extÚProfileStatsFileÚ_profile_statsr   Ú_current_testc                óR   — | a t        j                  rt        j                  «        y y ©N)r   r   Úforce_writeÚreset_count)Úid_s    úg/var/www/html/python-recuperauto-other/env/lib/python3.12/site-packages/sqlalchemy/testing/profiling.pyÚ_start_current_testr   C   s!   € à€Mä×!Ò!Ü×"Ñ"Õ$ð "ó    c                  óv   — e Zd ZdZ	 	 d	 	 	 	 	 	 	 dd„Zedd„«       Zdd„Zdd„Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zy)r   aû  Store per-platform/fn profiling results in a file.

    There was no json module available when this was written, but now
    the file format which is very deterministically line oriented is kind of
    handy in any case for diffs and merges.

    The parsing and rendering of the file itself, as well as of the platform
    keys used within it, is in :mod:`.testing.profiles_file`, which is shared
    with ``tools/profiles.py``.  This class adds the bookkeeping needed while
    the test suite runs.

    Nc                ó6  — t         j                  d uxr t         j                  j                  | _        | j                  xs. t         j                  d uxr t         j                  j                  | _        t        |«      | _        | j                  j                  | _	        t        j                  j                  | j                  «      d   | _        || _        || _        t        j                   t"        «      | _        | j
                  r| j'                  «        y y )Néÿÿÿÿ)r   ÚoptionsÚforce_write_profilesr   Úwrite_profilesÚwriter   ÚprofilesÚpathÚfnameÚosÚsplitÚshort_fnameÚdumpÚsortÚcollectionsÚdefaultdictÚintÚ_current_countsÚ_write)ÚselfÚfilenamer-   r,   s       r   Ú__init__zProfileStatsFile.__init__Y   sÕ   € ô �N‰N $Ð&ÒN¬6¯>©>×+NÑ+Nð 	Ôð ×%Ñ%ò 
Ü�N‰N $Ð&ÒH¬6¯>©>×+HÑ+Hð 	Œ
ô % XÓ.ˆŒØ—]‘]×'Ñ'ˆŒ
ÜŸ7™7Ÿ=™=¨¯©Ó4°RÑ8ˆÔØˆŒ	ØˆŒ	ô
 ×#Ñ#¤CÓ(ð 	Ôð �:Š:ð �K‰K�Mð r   c                óV   — t         j                  }|€J d«       ‚| j                  |«      S )Nzno database configured)r   ÚdbÚplatform_key_for)r3   r7   s     r   Úplatform_keyzProfileStatsFile.platform_keyv   s,   € ä�Y‰YˆØˆ~Ð7Ð7Ó7ˆ~Ø×$Ñ$ RÓ(Ð(r   c                ó4  — g }|j                   j                  r|j                  d«       |j                  t	        j
                  |«      «       t        j                  j                  › dt        j                  j                  › �}t        r|dz  }t        t        j                  «       t        j                  «       j                  «       t        j                   «       j                  «       ||j"                  |j$                  t'        |«      t)        «       ¬«      S )NÚasyncú.Út)ÚmachineÚsystemÚimplementationÚpythonÚdialectÚdriverÚdbapi_flagsÚcextensions)rB   Úis_asyncÚappendÚextendr   Úprofile_platform_tokensÚsysÚversion_infoÚmajorÚminorr   r   Úplatformr>   r?   ÚlowerÚpython_implementationÚnamerC   Útupler   )r3   r7   rD   Ú
py_versions       r   r8   z!ProfileStatsFile.platform_key_for|   sÖ   € ØˆØ�:‰:×ÒØ×Ñ˜wÔ'ð 	×Ñœ9×<Ñ<¸RÓ@ÔAô ×(Ñ(×.Ñ.Ð/¨q´×1AÑ1A×1GÑ1GÐ0HÐIˆ
ÝØ˜#ÑˆJäÜ×$Ñ$Ó&Ü—?‘?Ó$×*Ñ*Ó,Ü#×9Ñ9Ó;×AÑAÓCØØ—G‘GØ—9‘9Ü˜kÓ*Ü(Ó*ô	
ð 		
r   c                óœ   ‡ ‡— ‰ j                   ry‰ j                  |«      Št        ˆˆ fd„‰ j                  j	                  «       D «       «      S )aå  Return True if profiling tests should run against the given
        engine.

        This is the case when the profile file has counts for at least
        one test on the engine's platform, or when profiles are being
        written.  Used to keep profiling test classes from being generated
        at all for drivers / interpreters that would only have each
        test skip from within :func:`.count_functions`, after the class
        has already run its fixture setup.

        Tc              3  óX   •K  — | ]!  }‰‰j                   j                  |«      v –— Œ# y ­wr   )r&   Úplatforms_for)Ú.0Útest_keyr9   r3   s     €€r   ú	<genexpr>z0ProfileStatsFile.has_platform.<locals>.<genexpr>¥   s-   øè ø€ ò 
àð ˜DŸM™M×7Ñ7¸ÓAÔAñ
ùs   ƒ'*)r%   r8   Úanyr&   Ú	test_keys)r3   r7   r9   s   ` @r   Úhas_platformzProfileStatsFile.has_platform•   sF   ù€ ð �:Š:Øà×,Ñ,¨RÓ0ˆÜô 
à ŸM™M×3Ñ3Ó5ô
ó 
ð 	
r   c                óZ   — | j                   j                  t        | j                  «      d uS r   ©r&   Ú
counts_forr   r9   ©r3   s    r   Ú	has_statszProfileStatsFile.has_statsª   s)   € à�M‰M×$Ñ$¤]°D×4EÑ4EÓFØðð	
r   c                ój  — t         }| j                  }| j                  j                  ||«      }| j                  ||f   }t        |«      |k  r0|j                  |«       | j                  r| j                  «        d }n!| j                  j                  ||«      ||   f}|dz   | j                  ||f<   |S )Nr
   )
r   r9   r&   Úsetdefault_countsr1   ÚlenrG   r%   r2   Ú
lineno_for)r3   Ú	callcountrX   r9   ÚcountsÚcurrent_countÚresults          r   ri   zProfileStatsFile.result°   s³   € Ü ˆØ×(Ñ(ˆà—‘×0Ñ0°¸<ÓHˆØ×,Ñ,¨X°|Ð-CÑDˆô ˆv‹;˜-Ò'Ø�M‰M˜)Ô$Ø�zŠzØ—‘”Ø‰Fð —‘×(Ñ(¨°<Ó@Ø�}Ñ%ðˆFð 8EÀqÑ7Hˆ×Ñ˜X |Ð3Ñ4Øˆr   c                óh   — | j                   j                  t        | j                  «      }|�g |d d  y y r   r^   )r3   rg   s     r   r   zProfileStatsFile.reset_countÅ   s2   € Ø—‘×)Ñ)¬-¸×9JÑ9JÓKˆØÐØˆF‘1‰Ið r   c                ó  — t         }| j                  }| j                  j                  ||«      }|sJ d«       ‚| j                  ||f   }|t        |«      k  r	|||dz
  <   n||d<   | j                  r| j                  «        y y )Nz1replace() called before result() recorded a countr
   r!   )r   r9   r&   r_   r1   rd   r%   r2   )r3   rf   rX   r9   rg   rh   s         r   ÚreplacezProfileStatsFile.replaceÊ   s„   € Ü ˆØ×(Ñ(ˆà—‘×)Ñ)¨(°LÓAˆÙÐJÐJÓJˆvà×,Ñ,¨X°|Ð-CÑDˆØœ3˜v›;Ò&Ø(1ˆF�= 1Ñ$Ò%à"ˆF�2‰JØ�:Š:Ø�K‰K�Mð r   c                óh   — t        d| j                  z  «       | j                  j                  «        y )NzWriting profile file %s)Úprintr(   r&   r%   r`   s    r   r2   zProfileStatsFile._writeÙ   s$   € ÜÐ'¨$¯*©*Ñ4Ô5Ø�‰×ÑÕr   )Ú
cumulativeN)r4   Ústrr-   rp   r,   zOptional[str]ÚreturnÚNone)rq   r   )r7   r   rq   r   )r7   r   rq   Úbool)rq   rs   )rf   r0   rq   z#Optional[Tuple[Optional[int], int]])rq   rr   )rf   r0   rq   rr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   Úpropertyr9   r8   r\   ra   ri   r   rl   r2   © r   r   r   r   K   sq   „ ñð  !Ø"ð	àðð ðð ð	ð
 
óð: ò)ó ð)ó

ó2
ó*
óó*ó
ôr   c                ó2   ‡ ‡‡— ddl m} |dˆˆ ˆfd„«       }|S )a©  Assert a target for a test case's function call count.

    The main purpose of this assertion is to detect changes in
    callcounts for various functions - the actual number is not as important.
    Callcounts are stored in a file keyed to Python version and OS platform
    information.  This file is generated automatically for new tests,
    and versioned so that unexpected changes in callcounts will be detected.

    r   )Ú	decoratorc                ó°   •— t        ‰	«      D ]
  } | |i |¤Ž Œ t        ‰«      }t        ‰¬«      5  |D ]
  } | |i |¤Ž}Œ cd d d «       S # 1 sw Y   y xY w)N)Úvariance)ÚrangeÚcount_functions)
ÚfnÚargsÚkwÚwarmÚ	timerangeÚtimeÚrvÚtimesr}   Úwarmups
          €€€r   Úwrapz!function_call_count.<locals>.wrapí   sh   ø€ ä˜&“Mò 	ˆDÙ�ˆO˜‹Oð	ô ˜%“Lˆ	Ü hÔ/ñ 	Ø!ò %�Ù˜�_ ‘_‘ð%à÷	÷ 	ò 	ús   ±AÁA)r€   úCallable[..., Any]r�   r   r‚   r   rq   r   )Úsqlalchemy.utilr{   )r}   r‡   rˆ   r{   r‰   s   ```  r   Úfunction_call_countrŒ   Þ   s!   ú€ õ *àöó ðð €Kr   c              #  óÖ  K  — t         €t        j                  d«      ‚t        j	                  «       s6t        j
                  s&t        j                  dt        j                  z  «       t        «        t        j                  «       }|j                  «        d –— |j                  «        t        j                  |t        j                  ¬«      }|j                   }t        j#                  |«      }|€d }n|\  }}t%        d||fz  «        |j&                  t)        j*                  dt        j,                  «      Ž  |j/                  «        t        j0                  rtt2        j4                  j7                  t        j0                  «      \  }}t8        j+                  d«      d   }	|›d|	›|xs d	›�}
|j;                  |
«       t%        d
|
z  «       t        j<                  rt        j?                  |«       y |rqtA        || z  «      }tC        ||z
  «      |kD  }|rOt        j
                  rt        j?                  |«       y tE        d|›d| dz  ›d|›dt        jF                  ›d�	«      ‚y y ­w)NzcProfile is not installedzŒNo profiling stats available on this platform for this function.  Run tests with --write-profiles to add statistics to %s for this platform.)ÚstreamzPstats calls: %d Expected %sz[, ]r<   r!   Ú_z.profilezDumped stats to file %szAdjusted function call count z not within éd   z% of expected z, platform z;. Rerun with --write-profiles to regenerate this callcount.)$ÚcProfiler   Ú_skip_test_exceptionr   ra   r%   Ú	skip_testr+   r   ÚProfileÚenableÚdisableÚpstatsÚStatsrJ   ÚstdoutÚtotal_callsri   rn   Ú
sort_statsÚrer*   r-   Úprint_statsr,   r)   r'   Úsplitextr   Ú
dump_statsr   rl   r0   ÚabsÚAssertionErrorr9   )r}   ÚprÚstatsrf   ÚexpectedÚexpected_countÚline_noÚbaseÚextÚ	test_nameÚdumpfileÚdevianceÚfaileds                r   r   r   û   sþ  è ø€ äÐÜ×)Ñ)Ð*EÓFÐFä×#Ñ#Ô%¬n×.BÒ.BÜ×Ñðô  .×9Ñ9ñ:ô	
ô „Lä	×	Ñ	Ó	€BØ‡I�I„Kã	à‡J�J„Lô �L‰L˜¤C§J¡JÔ/€Eð ×!Ñ!€Iä×$Ñ$ YÓ/€HàÐØ‰à"*Ñˆ�ä	Ð
(¨I°~Ð+FÑ
FÔGØ€E×Ñ”b—h‘h˜w¬×(;Ñ(;Ó<Ñ=Ø	×ÑÔÜ×ÒÜ—G‘G×$Ñ$¤^×%8Ñ%8Ó9‰	ˆˆcÜ!×'Ñ'¨Ó,¨RÑ0ˆ	Ú $¡i°Ò1B¸
Ð1BÐCˆØ×Ñ˜Ô"ÜÐ'¨(Ñ2Ô3ä×!Ò!Ü×Ñ˜yÕ)Ù	Ü�y 8Ñ+Ó,ˆÜ�Y Ñ/Ó0°8Ñ;ˆáÜ×#Ò#Ü×&Ñ& yÕ1å$ò "Ø! C›Ú&Ü&×3Ó3ð	óð ð	 ð	 
ùs   ‚I'I))r   r   rq   rr   )çš™™™™™©?r
   r   )r}   Úfloatr‡   r0   rˆ   r0   rq   rŠ   )r­   )r}   r®   rq   zGenerator[None, None, None])&rw   Ú
__future__r   r.   Ú
contextlibr)   rN   r—   rœ   rJ   Útypingr   r   r   r   r   r	   Ú r   r   Úprofiles_filer   r   r   Úutilr   r   r   r‘   ÚImportErrorr   Ú__annotations__r   r   r   rŒ   Úcontextmanagerr   ry   r   r   ú<module>r¸      sè   ðòõ #ã Û Û 	Û Û Û 	Û 
Ý Ý Ý Ý Ý Ý å Ý Ý &Ý 'Ý "Ý Ý  Ý #ðÛð $(€Ð Ó 'ðð €ˆwÓ ðó%÷Pñ Pðh ;<ðØðØ#&ðØ47ðàóð: ×ÑóAó ñAøð[ ò Ø‚Hðús   Á;B? Â?C	ÃC	