
    BTh.                         d dl m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  G d de      Z G d d      Zy)    )partialN   )
statistics)statistics_error)Logger)TableResults)NAME_FORMATTERS)SecondsDecimal)first_or_value)get_machine_id)load_storage)
load_timer)report_noprogress)report_progress)
safe_dumps)short_filenamec                       e Zd Zy)PerformanceRegressionN)__name__
__module____qualname__     j/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pytest_benchmark/session.pyr   r      s    r   r   c                   P    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zy)BenchmarkSessionNc                    |j                  d      | _        | j                  rdn|j                  d      | _        | j                  rt        j                  nt        j
                  }| j                  rt        j                  }t        ||      | _        || _        g | _	        g | _
        t               | _        t        |j                  d      | j                  | j                  |j                  d            | _        |j                  d      | _        |j                  d	      | _        |j                  d
      | _        t%        |j                  d      d      | _        t)        |j                  d            |j                  d      t)        |j                  d            t+        |j                  d            |j                  d      |j                  d      |j                  d      |j                  d      t-        | j                        | j                   | j&                  d| _        |j                  d      | _        |j                  d      xr |j                  d       | _        |j                  dd      dk7  r:| j0                  s.| j2                  s"| j                  j5                  d       d| _        t7        |d      rd| _        t8        s5| j2                  s)| j                  j5                  dt:                d| _        |j                  d      | _        |j                  d      | _        |j                  d       | _         | j0                  r| j<                  rd| _        | j2                  r!| j<                  rtC        jD                  d!      |j                  d"      | _#        |j                  d#      | _$        |j                  d$      | _%        |j                  d%      | _&        |j                  d&      | _'        |j                  d'      | _(        |j                  d(      | _)        tT        |j                  d)         | _+        t%        |j                  d*      d      | _,        y )+Nbenchmark_verboseFbenchmark_quietconfigbenchmark_storagebenchmark_netrc)loggerdefault_machine_idnetrcbenchmark_cprofilebenchmark_cprofile_loopsbenchmark_cprofile_topbenchmark_cprofile_dumpbenchmark_min_timebenchmark_min_roundsbenchmark_max_timebenchmark_timerbenchmark_calibration_precisionbenchmark_disable_gcbenchmark_warmupbenchmark_warmup_iterations)min_time
min_roundsmax_timetimercalibration_precision
disable_gcwarmupwarmup_iterationscprofilecprofile_loopscprofile_dumpbenchmark_skipbenchmark_disablebenchmark_enabledistnozBenchmarks are automatically disabled because xdist plugin is active.Benchmarks cannot be performed reliably in a parallelized environment.T
slaveinputzPBenchmarks are automatically disabled because we could not import `statistics`

benchmark_onlybenchmark_sortbenchmark_columnszCan't have both --benchmark-only and --benchmark-disable options. Note that --benchmark-disable is automatically activated if xdist is on or you're missing the statistics dependency.benchmark_group_bybenchmark_savebenchmark_autosavebenchmark_save_databenchmark_jsonbenchmark_comparebenchmark_compare_failbenchmark_namebenchmark_histogram)-	getoptionverbosequietr   QUIETNORMALVERBOSEr$   r!   performance_regressions
benchmarksr   
machine_idr   storagecprofile_sort_byr<   cprofile_topr   r=   r
   r   booloptionsskipdisabledwarninghasattrr   r   onlysortcolumnspytest
UsageErrorgroup_bysaveautosave	save_datajsoncomparecompare_failr	   name_format	histogram)selfr!   levels      r   __init__zBenchmarkSession.__init__   s   ''(;<"llU0@0@AR0S
 $

<<NNEU62')$(*#01;;#""#45	
 !' 0 01E F$../IJ",,-EF+F,<,<=V,WY^_&v'7'78L'MN **+AB&v'7'78L'MN 0 01B CD%+%5%56W%X **+AB&&'9:!'!1!12O!PT223"11!//
 $$%56	(()<=jfFVFVWiFjBjFD)T1$))DMMKKY !DM6<( DM$--KKdeudvw !DM$$%56	$$%56	''(;<99DI==TYY##f  (()=>$$%56	(()=>))*?@$$%56	''(;<",,-EF*6+;+;<L+MN'(8(89N(OQVWr   c                     | j                   j                  j                  | j                         }| j                   j                  j                  | j                   |       |S )Nr    )r!   machine_info)r!   hook&pytest_benchmark_generate_machine_info$pytest_benchmark_update_machine_info)rp   objs     r   get_machine_infoz!BenchmarkSession.get_machine_infod   sJ    kkEET[[EY==T[[_b=c
r   c              #     K   | j                   D ]M  }|sd}| j                  j                         D ]  \  }}|j                  |v s||j                     }t	        || j
                        }|j                  dd| j                  | j                  f      }|j                  |d          t        |      |d<   ||d<   | j                  rR| j                  D ]C  }|j                  ||      }|s| j                  j                  | j                  |      |f       E |  |j                  dd| j                  | j                  f      }d |d<   |xr d|d<   | P y w)	NF)include_datastatsr;   r|   pathsourceT)r{   flatr;   NOW)rW   compared_mappingitemsfullnamer   rX   as_dictrZ   r[   updatestrrm   failsrV   appendrn   )	rp   benchcomparedr}   r   r~   
flat_benchcheckfails	            r   prepare_benchmarksz#BenchmarkSession.prepare_benchmarksi   sz    __ 	!E .2.C.C.I.I.K )*D*~~)99#3ENN#C!/doo!F%*]]U^b^s^suy  vG  vG  ^H]  &I
"))(7*;<-0Y
6*/5
8,,,)-):): n',{{5*'E#'$($@$@$G$GIYIYZdIegkHl$mn )() #]]DTXTiTikok|k|S}]~
%)
6"'/'9E
8$  )	!s   E!0E!B%E!-A4E!c                     | j                   5 }|j                  t        |dd      j                                d d d        | j                  j                  d| j                    d       y # 1 sw Y   4xY w)NT   )ensure_asciiindentzWrote benchmark data in: )purple)rk   writer   encoder$   info)rp   output_jsonfhs      r   	save_jsonzBenchmarkSession.save_json   se    YY 	T"HHZ$qIPPRS	T4TYYK@N	T 	Ts   ,A,,A5c                    | j                   xs | j                  }|s| j                  r| j                  s(| j                  s| j
                  j                  d       y | j                         }| j                  j                  j                  | j                        }| j                  j                  j                  | j                  |       | j                  r| j                  j                  j                  | j                  | j                  d      }| j                  j                  j                  | j                  | j                  |       | j                  |       |r| j                  j                  j                  | j                  | j                  | j                        }| j                  j                  j                  | j                  | j                  |       | j                   j                  ||       y y )Nz1Not saving anything, no benchmarks have been run!r    )r!   commit_infoT)r!   rW   r{   rt   r   )r!   rW   r   )rh   ri   rk   rW   r_   r$   r`   ry   r!   ru   %pytest_benchmark_generate_commit_info#pytest_benchmark_update_commit_infopytest_benchmark_generate_jsonpytest_benchmark_update_jsonr   rj   rY   )rp   rh   rt   r   r   s        r   handle_savingzBenchmarkSession.handle_saving   s   yy)DMM499??}}KK''([\002L++**PPX\XcXcPdKKK@@al@m99++**II{{??!)' J K KK99{{??' : 
 NN;'++**II{{??!^^)' J K KK99{{??' : 
 LLk40 r   c                    i }| j                   rF| j                   du r't        | j                  j                               dd  }n.t        | j                  j                  | j                               }|sZdt	        | j                        }| j                   du r|dz  }n|d| j                   dz  }| j
                  j                  |       | j                         }|D ]r  \  }}| j                  j                  j                  | j                  | ||       |d   D ci c]  }|d	   |
 c}||<   | j
                  j                  d
| d       t || _        y c c}w )NTz%Can't compare. No benchmark files in z$. Can't load the previous benchmark.z match .)r!   benchmarksessionrt   compared_benchmarkrW   r   z#Comparing against benchmarks from: F)newline)rl   listrY   loadr   r$   r`   ry   r!   ru   %pytest_benchmark_compare_machine_infor   r   )rp   r   compared_benchmarksmsgrt   r}   r   r   s           r   handle_loadingzBenchmarkSession.handle_loading   s_   <<||t#&*4<<+<+<+>&?&D#&*4<<+<+<T\\+J&K#&=c$,,>O=RS<<4'AACWT\\$4A66C##C(002L,? ^((  FF;;%)!-'9	 G  QccoPp)qu%
*;U*B)q &  #Ftf!MW\ ]^ !1 *rs   !Ec                     | j                          t        | j                               }|rB| j                  j                  j                  | j                  || j                        | _        y y )N)r!   rW   rg   )r   r   r   r!   ru   pytest_benchmark_group_statsrg   groups)rp   prepared_benchmarkss     r   finishzBenchmarkSession.finish   s\    "4#:#:#<=++**GG{{/BT]] H DK r   c                 
   | j                   sy |j                          t        | j                  | j                  | j
                  | j                  | j                  t        | j                  j                  j                  | j                              }| j                  rt        nt        }| j                  s|j!                  || j                   |       | j#                          | j                  s| j%                  |       y y )Nr    )rd   rc   ro   rn   r$   
scale_unit)progress_reporter)r   ensure_newliner   rd   rc   ro   rn   r$   r   r!   ru   pytest_benchmark_scale_unitrQ   r   r   rR   displaycheck_regressionsdisplay_cprofile)rp   trresults_tabler   s       r   r   zBenchmarkSession.display   s    {{
$LLnn((;;t{{//KKTXT_T_`
 04||OARzz!!"dkkEV!W zz!!"% r   c                     | j                   r!| j                  st        j                  d      | j                  rU| j
                  j                  dj                  dj                  d | j                  D                           t        d      y )Nz<--benchmark-compare-fail requires valid --benchmark-compare.zPerformance has regressed:
{}
c              3   :   K   | ]  } d j                   |   yw)z	{} - {}N)format).0lines     r   	<genexpr>z5BenchmarkSession.check_regressions.<locals>.<genexpr>   s(       BF`dBT+BTBTVZB[  BFs   zPerformance has regressed.)
rm   r   re   rf   rV   r$   errorr   joinr   )rp   s    r   r   z"BenchmarkSession.check_regressions   s    T%:%:##$bcc''KK077		  BFhl  iE  iE  BF  9F  G ((DEE	 (r   c                    d}| j                   D ]  }|\  }}|D ]  }d|v s|s|j                  ddd       d}|j                  |d   d       |d	   r$|j                  d
j	                  |d	                n|j                  d       |j                  d       |d   D ]'  } dj                  dddi|}|j                  |       ) |j                  d         y )NFr;   zcProfile (time in s)-T)sepyellowr   )r   r~   z ({})r   z@ncalls	tottime	percall	cumtime	percall	filename:lineno(function)zv{ncalls_recursion}	{tottime:.{prec}f}	{tottime_per:.{prec}f}	{cumtime:.{prec}f}	{cumtime_per:.{prec}f}	{function_name}precr   r   )r   sectionr   
write_liner   )	rp   r   section_displayedgroup
group_namerW   	benchmarkfunction_infor   s	            r   r   z!BenchmarkSession.display_cprofile   s   ![[ 	#E%*"J
' #	*,

#9s4
P,0)HHYz24H@ *gnnYx5H&IJMM"ij)2:)> , !H & : '( : ,9 : d+, HHTN##	#r   )r   r   r   r   r   rr   ry   r   r   r   r   r   r   r   r   r   r   r   r   r      sE    FEXN
!.O
'1R18&(F#r   r   )	functoolsr   re   fixturer   r   r$   r   tabler   utilsr	   r
   r   r   r   r   r   r   r   r   	Exceptionr   r   r   r   r   <module>r      sM       %   " ! ! !   $ "  !	I 	l# l#r   