§
    ÕóÉ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n# e$ r dZY nw xY wdZded<   	 da ded<   	 d'd„Z! G d„ d¦  «        Z"	 d(d)d$„Z#ej$        d*d+d&„¦   «         Z%dS ),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_testÚid_ÚreturnÚNonec                óX   — | a t          j        rt                               ¦   «          d S d S ©N)r   r   Úforce_writeÚreset_count)r   s    ú�/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib64/python3.11/site-packages/sqlalchemy/testing/profiling.pyÚ_start_current_testr   C   s4   € à€MåÔ!ð %Ý×"Ò"Ñ$Ô$Ð$Ð$Ð$ð%ð %ó    c                  óp   — 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dS )$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.

    Ú
cumulativeNÚfilenameÚstrÚsortÚdumpúOptional[str]r   r   c                óÞ  — t           j        d uot           j        j        | _        | j        pt           j        d uot           j        j        | _        t          |¦  «        | _        | j        j        | _	        t          j                             | j	        ¦  «        d         | _        || _        || _        t          j        t"          ¦  «        | _        | j        r|                      ¦   «          d S d S )Néÿÿÿÿ)r   ÚoptionsÚforce_write_profilesr   Úwrite_profilesÚwriter   ÚprofilesÚpathÚfnameÚosÚsplitÚshort_fnamer&   r%   ÚcollectionsÚdefaultdictÚintÚ_current_countsÚ_write)Úselfr#   r%   r&   s       r   Ú__init__zProfileStatsFile.__init__Y   sÑ   € õ ŒN $Ð&ÐN­6¬>Ô+Nð 	Ôð Ô%ð 
ÝŒN $Ð&ÐH­6¬>Ô+Hð 	Œ
õ % XÑ.Ô.ˆŒØ”]Ô'ˆŒ
Ýœ7Ÿ=š=¨¬Ñ4Ô4°RÔ8ˆÔØˆŒ	ØˆŒ	õ
 Ô#¥CÑ(Ô(ð 	Ôð Œ:ð 	ð �KŠK‰MŒMˆMˆMˆMð	ð 	r    r   c                ó\   — t           j        }|€
J d¦   «         ‚|                      |¦  «        S )Nzno database configured)r   ÚdbÚplatform_key_for)r9   r<   s     r   Úplatform_keyzProfileStatsFile.platform_keyv   s-   € åŒYˆØˆ~ˆ~Ð7‰~Œ~ˆ~Ø×$Ò$ RÑ(Ô(Ð(r    r<   r   c                ó  — g }|j         j        r|                     d¦  «         |                     t	          j        |¦  «        ¦  «         t          j        j        › dt          j        j	        › �}t          r|dz  }t          t          j        ¦   «         t          j        ¦   «                              ¦   «         t          j        ¦   «                              ¦   «         ||j        |j        t'          |¦  «        t)          ¦   «         ¬¦  «        S )NÚasyncú.Út)ÚmachineÚsystemÚimplementationÚpythonÚdialectÚdriverÚdbapi_flagsÚcextensions)rG   Úis_asyncÚappendÚextendr   Úprofile_platform_tokensÚsysÚversion_infoÚmajorÚminorr   r   ÚplatformrC   rD   ÚlowerÚpython_implementationÚnamerH   Útupler   )r9   r<   rI   Ú
py_versions       r   r=   z!ProfileStatsFile.platform_key_for|   sï   € ØˆØŒ:Ôð 	(Ø×Ò˜wÑ'Ô'Ð'ð 	×Ò�9Ô<¸RÑ@Ô@ÑAÔAÐAõ Ô(Ô.ÐIÐIµÔ1AÔ1GÐIÐIˆ
Ýð 	Ø˜#ÑˆJåÝÔ$Ñ&Ô&Ý”?Ñ$Ô$×*Ò*Ñ,Ô,Ý#Ô9Ñ;Ô;×AÒAÑCÔCØØ”GØ”9Ý˜kÑ*Ô*Ý(Ñ*Ô*ð	
ñ 	
ô 	
ð 		
r    Úboolc                ó¨   ‡ ‡— ‰ j         rdS ‰                      |¦  «        Št          ˆˆ fd„‰ 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  óP   •K  — | ] }‰‰j                              |¦  «        v V — Œ!d S r   )r.   Úplatforms_for)Ú.0Útest_keyr>   r9   s     €€r   ú	<genexpr>z0ProfileStatsFile.has_platform.<locals>.<genexpr>¥   sL   øè è € ð 
ð 
àð ˜DœM×7Ò7¸ÑAÔAÐAð
ð 
ð 
ð 
ð 
ð 
r    )r-   r=   Úanyr.   Ú	test_keys)r9   r<   r>   s   ` @r   Úhas_platformzProfileStatsFile.has_platform•   ss   øø€ ð Œ:ð 	Ø�4à×,Ò,¨RÑ0Ô0ˆÝð 
ð 
ð 
ð 
ð 
à œM×3Ò3Ñ5Ô5ð
ñ 
ô 
ñ 
ô 
ð 	
r    c                óP   — | j                              t          | j        ¦  «        d uS r   ©r.   Ú
counts_forr   r>   ©r9   s    r   Ú	has_statszProfileStatsFile.has_statsª   s'   € àŒM×$Ò$¥]°DÔ4EÑFÔFØðð	
r    Ú	callcountr6   ú#Optional[Tuple[Optional[int], int]]c                óf  — t           }| j        }| j                             ||¦  «        }| j        ||f         }t          |¦  «        |k    r3|                     |¦  «         | j        r|                      ¦   «          d }n#| j         	                    ||¦  «        ||         f}|dz   | j        ||f<   |S )Nr
   )
r   r>   r.   Úsetdefault_countsr7   ÚlenrL   r-   r8   Ú
lineno_for)r9   rh   r^   r>   ÚcountsÚcurrent_countÚresults          r   rp   zProfileStatsFile.result°   sÀ   € Ý ˆØÔ(ˆà”×0Ò0°¸<ÑHÔHˆØÔ,¨X°|Ð-CÔDˆõ ˆv‰;Œ;˜-Ò'Ð'Ø�MŠM˜)Ñ$Ô$Ð$ØŒzð Ø—’‘”�ØˆFˆFð ”×(Ò(¨°<Ñ@Ô@Ø�}Ô%ðˆFð 8EÀqÑ7HˆÔ˜X |Ð3Ñ4Øˆr    c                óf   — | j                              t          | j        ¦  «        }|�	g |d d …<   d S d S r   rd   )r9   rn   s     r   r   zProfileStatsFile.reset_countÅ   s;   € Ø”×)Ò)­-¸Ô9JÑKÔKˆØÐØˆF�1�1�1‰IˆIˆIð Ðr    c                ó
  — t           }| j        }| j                             ||¦  «        }|s
J d¦   «         ‚| j        ||f         }|t          |¦  «        k     r	|||dz
  <   n||d<   | j        r|                      ¦   «          d S d S )Nz1replace() called before result() recorded a countr
   r)   )r   r>   r.   re   r7   rl   r-   r8   )r9   rh   r^   r>   rn   ro   s         r   ÚreplacezProfileStatsFile.replaceÊ   sž   € Ý ˆØÔ(ˆà”×)Ò)¨(°LÑAÔAˆØÐJÐJÐJÑJÔJÐJàÔ,¨X°|Ð-CÔDˆØ�3˜v™;œ;Ò&Ð&Ø(1ˆF�= 1Ñ$Ñ%Ð%à"ˆF�2‰JØŒ:ð 	Ø�KŠK‰MŒMˆMˆMˆMð	ð 	r    c                óf   — t          d| j        z  ¦  «         | j                             ¦   «          d S )NzWriting profile file %s)Úprintr0   r.   r-   rf   s    r   r8   zProfileStatsFile._writeÙ   s2   € ÝÐ'¨$¬*Ñ4Ñ5Ô5Ð5ØŒ×ÒÑÔÐÐÐr    )r"   N)r#   r$   r%   r$   r&   r'   r   r   )r   r   )r<   r   r   r   )r<   r   r   rY   )r   rY   )rh   r6   r   ri   )r   r   )rh   r6   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   Úpropertyr>   r=   rb   rg   rp   r   rs   r8   © r    r   r   r   K   së   € € € € € ðð ð  !Ø"ð	ð ð ð ð ð: ð)ð )ð )ñ „Xð)ð

ð 
ð 
ð 
ð2
ð 
ð 
ð 
ð*
ð 
ð 
ð 
ðð ð ð ð*ð ð ð ð
ð ð ð ðð ð ð ð ð r    çš™™™™™©?ÚvarianceÚfloatÚtimesr6   ÚwarmupúCallable[..., Any]c                ó8   ‡ ‡‡— 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   )Ú	decoratorÚfnr�   Úargsr   Úkwr   c                óÈ   •— t          ‰	¦  «        D ]
} | |i |¤Ž Œt          ‰¦  «        }t          ‰¬¦  «        5  |D ]
} | |i |¤Ž}Œ|cd d d ¦  «         S # 1 swxY w Y   d S )N)r}   )ÚrangeÚcount_functions)
r„   r…   r†   ÚwarmÚ	timerangeÚtimeÚrvr   r}   r€   s
          €€€r   Úwrapz!function_call_count.<locals>.wrapí   sÐ   ø€ å˜&‘M”Mð 	ð 	ˆDØˆB�ˆO˜ˆOˆOˆOˆOå˜%‘L”Lˆ	Ý hÐ/Ñ/Ô/ð 	ð 	Ø!ð %ð %�Ø�R˜�_ �_�_��Øð	ð 	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   »AÁAÁA)r„   r�   r…   r   r†   r   r   r   )Úsqlalchemy.utilrƒ   )r}   r   r€   rƒ   rŽ   s   ```  r   Úfunction_call_countr�   Þ   sR   øøø€ ð *Ð)Ð)Ð)Ð)Ð)àðð ð ð ð ð ð ñ „Yðð €Kr    úGenerator[None, None, None]c              #  óü  K  — t           €t          j        d¦  «        ‚t                               ¦   «         s-t          j        s!t          j        dt          j        z  ¦  «         t          ¦   «          t          j	        ¦   «         }| 
                    ¦   «          d V — |                     ¦   «          t          j        |t          j        ¬¦  «        }|j        }t                               |¦  «        }|€d }n|\  }}t%          d||fz  ¦  «          |j        t)          j        dt          j        ¦  «        Ž  |                     ¦   «          t          j        r~t2          j                             t          j        ¦  «        \  }}t8                               d¦  «        d         }	|›d|	›|pd	›�}
|                     |
¦  «         t%          d
|
z  ¦  «         t          j        rt                               |¦  «         d S |r{tA          || z  ¦  «        }tC          ||z
  ¦  «        |k    }|rSt          j        rt                               |¦  «         d S tE          d|›d| dz  ›d|›dt          j#        ›d�	¦  «        ‚d S d S )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[, ]rA   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   rg   r-   Ú	skip_testr3   r   ÚProfileÚenableÚdisableÚpstatsÚStatsrO   ÚstdoutÚtotal_callsrp   ru   Ú
sort_statsÚrer2   r%   Úprint_statsr&   r1   r/   Úsplitextr   Ú
dump_statsr   rs   r6   ÚabsÚAssertionErrorr>   )r}   ÚprÚstatsrh   ÚexpectedÚexpected_countÚline_noÚbaseÚextÚ	test_nameÚdumpfileÚdevianceÚfaileds                r   r‰   r‰   û   s�  è è € åÐÝÔ)Ð*EÑFÔFÐFå×#Ò#Ñ%Ô%ð 
­nÔ.Bð 
ÝÔðõ  .Ô9ñ:ñ	
ô 	
ð 	
õ �L„L€Lå	Ô	Ñ	Ô	€BØ‡I‚I�K„K€Kà	€E€E€Eà‡J‚J�L„L€Lõ ŒL˜¥C¤JÐ/Ñ/Ô/€Eð Ô!€Iå×$Ò$ YÑ/Ô/€HàÐØˆˆà"*Ñˆ�å	Ð
(¨I°~Ð+FÑ
FÑGÔGÐGØ€EÔ•b”h˜w­Ô(;Ñ<Ô<Ð=Ð=Ø	×ÒÑÔÐÝÔð 4Ý”G×$Ò$¥^Ô%8Ñ9Ô9‰	ˆˆcÝ!×'Ò'¨Ñ,Ô,¨RÔ0ˆ	Ø $   i i°Ð1B¸
Ð1BÐCˆØ×Ò˜Ñ"Ô"Ð"ÝÐ'¨(Ñ2Ñ3Ô3Ð3åÔ!ð Ý×Ò˜yÑ)Ô)Ð)Ð)Ð)Ø	ð Ý�y 8Ñ+Ñ,Ô,ˆÝ�Y Ñ/Ñ0Ô0°8Ò;ˆàð 	ÝÔ#ð Ý×&Ò& yÑ1Ô1Ð1Ð1Ð1å$�nð "˜	˜	Ø! C™˜˜Ø&˜˜Ý&Ô3Ð3Ð3ð	ñô ð ðð ð	ð 	r    )r   r   r   r   )r|   r
   r   )r}   r~   r   r6   r€   r6   r   r�   )r|   )r}   r~   r   r‘   )&ry   Ú
__future__r   r4   Ú
contextlibr1   rS   rœ   r¡   rO   Útypingr   r   r   r   r   r	   Ú r   r   Úprofiles_filer   r   r   Úutilr   r   r   r–   ÚImportErrorr   Ú__annotations__r   r   r   r�   Úcontextmanagerr‰   r{   r    r   ú<module>r»      sj  ððð ð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ø 	€	€	€	Ø €€€Ø €€€Ø 	€	€	€	Ø 
€
€
€
Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø #Ð #Ð #Ð #Ð #Ð #ðØ€O€O€O€OøØð ð ð Ø€H€H€Hðøøøð $(€Ð 'Ð 'Ð 'Ñ 'ðð €Ð Ð Ð Ñ ðð%ð %ð %ð %ðPð Pð Pð Pð Pñ Pô Pð Pðh ;<ðð ð ð ð ð: ÔðAð Að Að Añ ÔðAð Að As   Á;B  Â B
Â	B
