g'dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl mZ ddlZdZ da d ZGd d Zdd Zej,dd Zy#e$rdZY4wxYw)zProfiling 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)config) gc_collect)has_compiled_extcR|atjrtjyyN) _current_test_profile_stats force_write reset_count)id_s M/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/testing/profiling.py_start_current_testr6s!M!!""$"cReZdZdZd dZedZdZdZdZ dZ d Z d Z d Z y) ProfileStatsFilezStore 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. NcBtjduxrtjj|_|jxs.tjduxrtjj|_t jj||_ t jj|jd|_ tjd|_||_||_|j#|j r|j%yy)Nc4tjtSr ) collections defaultdictdictrrz+ProfileStatsFile.__init__..QsK++D1r)roptionsforce_write_profilesr write_profileswriteospathabspathfnamesplit short_fnamerrdatadumpsort_read_write)selffilenamer)r(s r__init__zProfileStatsFile.__init__Gs NN$ & N6>>+N+N %% NN$ & H6>>+H+H WW__X. 77==4R8++ 1     :: KKM rctjjdztjjz}tjjdk(rFtjjj tjj r|dz }djtjddDcgc] }t|c}}tjtjjtjj||g}|j!dt#}|j!|xrdxsd dj|Scc}w) N_sqlite_file.rr dbapiunicode cextensions nocextensions)rdbnamedriverdialect_is_url_file_dburljoinsys version_infostrplatformmachinesystemlowerpython_implementationappendr)r, dbapi_keyv py_versionplatform_tokens _has_cexts r platform_keyzProfileStatsFile.platform_key[sIINNS(699+;+;; 99>>X %&))*;*;*K*K IIMM+   IXXs/?/?!/DE/D!s1v/DEF      OO  # # %  * * , 2 2 4     ~.$& y:]MoNxx((Fs<E3cdt}||jvxr|j|j|vSr r r'rL)r,test_keys r has_statszProfileStatsFile.has_statsts1   ! Nd&7&7499X;N&N rc@t}|j|}||j}d|vrgx|d<}n|d}d|vrdx|d<}n|d}t||kD}|s0|j ||j r|j d}n |d||f}|dxxdz cc<|S)Ncounts current_countrlinenor)r r'rLlenrFr r+) r, callcountrOper_fn per_platformrRrS has_countresults rrZzProfileStatsFile.resultzs 8$d//0 < '.0 0L "V!(+F , .<= =L )M(9MK-/  MM) $zz F!(+VM-BBF_%*% rct}||jvry|j|}|j|vry||j}d|vr g|dddyy)NrRrN)r,rOrWrXs rrzProfileStatsFile.reset_countsc  499 $ 8$   F * d//0 | #(*L "1 % $rct}|j|}||j}|d}|d}|t|kr |||dz <n||d<|jr|j yy)NrRrSrr)r r'rLrUr r+)r,rVrOrWrXrRrSs rreplacezProfileStatsFile.replacesr 8$d//0 h'$_5 3v; &(1F=1$ %"F2J :: KKM rc d|jzS)Na # %s # This file is written out on a per-environment basis. # For each test in aaa_profiling, the corresponding function and # environment is located within this file. If it doesn't exist, # the test is skipped. # If a callcount does exist, it is compared to what we received. # assertions are raised if the counts do not match. # # To add a new callcount test, apply the function_call_count # decorator and re-run the tests using the --write-profiles # option - this file will be rewritten including the new count. # )r$)r,s r_headerzProfileStatsFile._headers ZZ! rc t|j}t|D]\}}|j }|r|j dr*|j \}}}|j|}||}|j dD cgc] } t| } } | |d<|dz|d<d|d<|jy#t$rYywxYwcc} w)N#,rRrrTrrS) openr$OSError enumeratestrip startswithr%r'intclose) r, profile_frTlinerOrLrRrWrXcountcs rr*zProfileStatsFile._reads TZZ(I&i0LFD::q|jy) NzWriting profile file %swz # TEST: %s rbc32K|]}t|ywr )r@).0rls r z*ProfileStatsFile._write..sL5KESZ5KsrR  ) printr$rcr r_sortedr'r=ri)r,rjrOrWrLrXrms rr+zProfileStatsFile._writes '$**45S)  'tyy)HYYx(F OO.9 : &v %l3 HHL\(5KLL, JK!/* r) cumulativeN)__name__ __module__ __qualname____doc__r.propertyrLrPrZrr]r_r*r+rrrrr>sC())0 6 + && rrc0ddlm}|fd}|S)aAssert 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) decoratorct D] }||i| t}t5|D] }||i|} cdddS#1swYyxYw)N)variance)rangecount_functions) fnargskwwarm timerangetimervtimesrwarmups rwrapz!function_call_count..wrapsU&MD OO"%L h /!__"0 / /s A  A)sqlalchemy.utilr~)rrrr~rs``` rfunction_call_countrs!* Krc #Kttjdtj s6tj s&tj dtjzttj}|jd|jtj|tj}|j }tj#|}|d}n|\}}t%d||fz|j&t)j*dtj,|j/tj0rtt2j4j7tj0\}}t8j+dd} |d| |xsd } |j;| t%d | ztj<rtj?|y|rqtA||z} tC||z | kD} | rOtj rtj?|ytEd |d |d zd|dtjFd yyw)NzcProfile is not installedzNo profiling stats available on this platform for this function. Run tests with --write-profiles to add statistics to %s for this platform.)streamzPstats calls: %d Expected %sz[, ]r3rr0z.profilezDumped stats to file %szAdjusted function call count z not within dz% of expected z , platform z;. Rerun with --write-profiles to regenerate this callcount.)$cProfiler_skip_test_exceptionr rPr skip_testr&rProfileenabledisablepstatsStatsr>stdout total_callsrZru sort_statsrer%r) print_statsr(r!r"splitextr dump_statsr r]rhabsAssertionErrorrL) rprstatsrVexpectedexpected_countline_nobaseext test_namedumpfiledeviancefaileds rrrs))*EFF  # # %n.B.B  .99 : L    BIIK JJL LLCJJ /E!!I$$Y/H"* (I~+F FGEbhhw(;(;<= GG$$^%8%89 c!'',R0 $i1B 1BC " '(23!!y) y8+,Y/08; ##&&y1$ "!C&&33     sI'I))皙?rr)r)r{ __future__rr contextlibr!rArrr>rutilrrr ImportErrorr r rrrcontextmanagerrrrrrs#  # %bbJ> AACHsA''A10A1