$Qe4z`PdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z  ddl Z n #e $rdZ YnwxYwdZdZGdd eZd d Zejdd ZdS)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. N)config) gc_collectupdate_wrappercReZdZdZdZedZdZdZdZ dZ dZ d Z d S) ProfileStatsFilezStore per-platform/fn profiling results in a file. We're still targeting Py2.5, 2.4 on 0.7 with no dependencies, so no json lib :( need to roll something silly ctjduotjj|_|jptjduotjj|_t j||_ t j |j d|_ tj d|_||jr|dSdS)Nc4tjtSN) collections defaultdictdict/srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/testing/profiling.pyz+ProfileStatsFile.__init__..8sK+D11r)roptionsforce_write_profiles force_writewrite_profileswriteospathabspathfnamesplit short_fnamerrdata_read_write)selffilenames r__init__zProfileStatsFile.__init__.s N$ & N6>+N % N$ & H6>+H W__X.. 7==44R8+ 1 1    :  KKMMMMM  rctjjdztjjz}tjjdkr8tjjtjjr|dz }ddtj ddD}tj tj tj ||g}|tjjjrdnd tj}||rd pd d|S) N_sqlite_file.c,g|]}t|Srstr).0vs r z1ProfileStatsFile.platform_key..KsEEE!s1vvEEErrr nativeunicode dbapiunicode cextensions nocextensions)rdbnamedriverdialect_is_url_file_dburljoinsys version_infoplatformmachinesystemlowerpython_implementationappendconvert_unicode requirements_has_cextensions)r$ dbapi_key py_versionplatform_tokens _has_cexts r platform_keyzProfileStatsFile.platform_key@sGINS(69+;; 9>X % %&)*;*K*K IM+ + %  IXXEEs/?!/DEEEFF      O   # # % %  * , , 2 2 4 4     y 0 OO   '88:: y:]MoNNNxx(((rcJt}||jvo|j|j|vSr) _current_testr!rL)r$test_keys r has_statszProfileStatsFile.has_stats^s*   ! Nd&749X;N&N rcht}|j|}||j}d|vrgx|d<}n|d}d|vrdx|d<}n|d}t||k}|s3|||jr|d}n|d||f}|dxxdz cc<|S)Ncounts current_countrlinenor)rNr!rLlenrDrr#) r$ callcountrOper_fn per_platformrRrS has_countresults rrZzProfileStatsFile.resultds 8$d/0 < ' '.0 0L "VV!(+F , . .<= =L )MM(9MKK-/  C MM) $ $ $z  FF!(+VM-BBF_%%%*%%% rct}|j|}||j}|d}|d}|t|kr |||dz <n||d<|jr|dSdS)NrRrSrr )rNr!rLrUrr#)r$rVrOrWrXrRrSs rreplacezProfileStatsFile.replaces 8$d/0 h'$_5 3v;; & &(1F=1$ % %"F2J :  KKMMMMM  rcd|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 Z! rc t|j}n#t$rYdSwxYwt|D]\}}|}|r|dr1|\}}}|j|}||}d|dD} | |d<|dz|d<d|d<|dS) N#c,g|]}t|Sr)intr/counts rr1z*ProfileStatsFile._read..s;;;U;;;r,rRrrTrrS) openrIOError enumeratestrip startswithrr!close) r$ profile_frTlinerOrLrRrWrXcs rr"zProfileStatsFile._reads TZ((II    FF %i00 . .LFD::<z*ProfileStatsFile._write..s(LLESZZLLLLLLrrR  ) printrrfrr^sortedr!r<rk)r$rlrOrWrLrXrns rr#zProfileStatsFile._writes (4:5777S))  '''ty)) L LHYx(F OO.9 : : : &v L L %l3 HHLL\(5KLLLLL,,, JKKKK L rN) __name__ __module__ __qualname____doc__r&propertyrLrPrZr\r^r"r#rrrr r &s$))X):   6   &&     rr 皙?cfd}|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. c6fd}t|S)Nct D] }|i| t}t5|D] }|i|} |cdddS#1swxYwYdS)N)variance)rangecount_functions) argskwwarm timerangetimervfntimesrwarmups rwrapz3function_call_count..decorate..wrapsf   DBe I (333  %))DTRBB                  sAAAr)rrrrrs` rdecoratez%function_call_count..decorates>        dB'''rr)rrrrs``` rfunction_call_countrs/ ( ( ( ( ( ( ( Orc #Kttjdts-tjs!tjdtjzttj }| dV| tj |tj}|j}t|}|d}n|\}}t%d||fz|d||rt+||z}t-||z |k}|s tjrStjrt|dSt3d|d|dzd |d tjd dSdS) 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 %s cumulativezAdjusted function call count z not within dz% of expected z , platform z;. Rerun with --write-profiles to regenerate this callcount.)cProfiler_skip_test_exception_profile_statsrPr skip_testr rProfileenabledisablepstatsStatsr=stdout total_callsrZru sort_stats print_statsrbabsrr\AssertionErrorrL) rprstatsrVexpectedexpected_countline_nodeviancefaileds rrrs)*EFFF  # # % % n.B   .9 :   LLL    BIIKKK EEEJJLLL LCJ / / /E!I$$Y//H"* )Y,G GIII \""" y8+,,Y/008;  ^/ # &&y11111$n " !C&&333      r)r|rr)r|)rzr contextlibrr?rr=rutilrrr ImportErrorrNrobjectr rcontextmanagerrrrrrs:  !!!!!!OOOOHHH XXXXXvXXXv4 999999s 3==