
    Yf;                     :   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mZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ dej&                  j)                  ej&                  j+                  e      dd	       Z G d
 de j0                        Z G d de      Z G d d      Zy)    N)dedent)AnyListNoReturnOptionalTuple)find_browser)ScaleneArguments)scalene_versionscalene_datezfile:zscalene-guiz
index.htmlc                   D     e Zd Zdedef fdZd	dee   deddfdZ xZS )
RichArgParserargskwargsc                 H    ddl m}  |       | _        t        |   |i | y )Nr   )Console)rich.consoler   consolesuper__init__)selfr   r   r   	__class__s       Y/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/scalene/scalene_parseargs.pyr   zRichArgParser.__init__   s!    (y$)&)    Nmessagefilereturnc                 @    |r| j                   j                  |       y y N)r   print)r   r   r   s      r   _print_messagezRichArgParser._print_message   s    LLw' r   r   )	__name__
__module____qualname__r   r   r   strr!   __classcell__)r   s   @r   r   r      s4    *c *S *(hsm (3 ($ (r   r   c                       e Zd ZdZddZy)StopJupyterExecutionzBNOP exception to enable clean exits from within Jupyter notebooks.Nc                      y r    )r   s    r   _render_traceback_z'StopJupyterExecution._render_traceback_   s    r   )r   N)r"   r#   r$   __doc__r+   r*   r   r   r(   r(      s
    Lr   r(   c                   b    e Zd Zeddedefd       Zedeej                  e
e   f   fd       Zy)ScaleneParseArgscoder   c                     t         )zJReplacement for sys.exit that exits cleanly from within Jupyter notebooks.)r(   )r/   s    r   
clean_exitzScaleneParseArgs.clean_exit#   s
     #"r   c                     t        j                  t              5  ddlm}   |        r2t
        j                  t        _        t
        j                  t        _	        d d d        t               }t        dt         dt         d      }t        d      }t        d|t        j                  dk7  r|nd	t         j"                  d
      }|j%                  ddddd       |j%                  ddt&        |j(                  d|j(                   d       |j%                  dt*        |j,                  d|j,                  sdn|j,                  z   dz          |j%                  dddd|j.                  dt+        |j.                  rdnd      z   dz          |j%                  d d!dd|j0                  d"t+        |j0                  rd!nd      z   dz          |j%                  d#d$dd|j2                  d%       |j%                  d&d'dd|j4                  d(       |j%                  d)ddd|j6                  d*       |j%                  d+d,dd|j8                  d-       |j%                  d.d/ddd
d0       |j%                  d1d2dd|j:                  d3|j:                   d       |j%                  d4t<        |j>                  d5|j>                   d       |j%                  d6d7ddd d8       |j%                  d9d7ddd d:       |j%                  d;d<ddd d=t+        |j@                        z   d>z          t        j                  dk(  rd?}nd@t+        |jB                        z   d>z   }|j%                  dAdBddd |       |j%                  dCdDdd|jD                  dE|jD                  rdFndGz   dz          |j%                  dHdIt*        |jF                  dJ|jF                  sdKn|jF                  z   dz          |j%                  dLdMt*        |jH                  dN|jH                  sdKn|jH                  z   dz          |j%                  dOdPdd|jJ                  dQ|jJ                   d       |j%                  dRdSt<        |jL                  dT|jL                   dU       |j%                  dVdWt<        |jN                  dX|jN                   dY       |j%                  dZd[t&        |jP                  d\|jP                   d]       |j%                  d^d_t&        |jR                  d`|jR                   d       |j%                  dadbt*        d	dc       |j%                  dddedf|jT                  dgt+        |jT                        z   dz   h       |j%                  didjddd
t         jV                         t        j                  dk7  r:|jY                  d
k      }|j%                  dldfdmn       |j%                  dodfdpn       |j%                  dqt&        dt         jV                         |j%                  drdsg t         jV                  t         jZ                  t       |j]                         \  }}|j,                  rHt^        j`                  jc                  |j,                        r|je                  du|j,                   dv       t        j                  dk(  rd|_3        d|_4        ||jj                  z  }dd l6}	|jn                  rtq               x}
r|j8                  rJ t^        j`                  js                  tt              }dd l;}dd l<}|j{                  t        j|                  | t^        j~                   dwdxt+        |j                  j                        g|j                  |j                  y       t        j                  d       n t        dz       t        j                  d       |j                  s|j@                  s|jB                  r'|jB                  sd
|_!        |j@                  s;d
|_         n3|j                  |_D        |j@                  |_         |jB                  |_!        d|_D        t        t        j                        d{k\  xr# |	j                  d|t        j                  d         }|s\t        t        j                        t        |      z   d{k(  r4|j                  t        j                         t        j                  d}       |j                  rat        d~t         dt         d       |j                  st        j                  d}       t        |j                        D ]  }t        ||        ||fS # 1 sw Y   	xY w)Nr   )get_ipythonzB[b]Scalene[/b]: a high-precision CPU and memory profiler, version z (a  )
[link=https://github.com/plasma-umass/scalene]https://github.com/plasma-umass/scalene[/link]


command-line:
  % [b]scalene \[options] your_program.py \[--- --your_program_args] [/b]
or
  % [b]python3 -m scalene \[options] your_program.py \[--- --your_program_args] [/b]

in Jupyter, line mode:
[b]  %scrun \[options] statement[/b]

in Jupyter, cell mode:
[b]  %%scalene \[options]
   your code here
[/b]
ad  When running Scalene in the background, you can suspend/resume profiling
for the process ID that Scalene reports. For example:

   % python3 -m scalene [options] yourprogram.py &
 Scalene now profiling process 12345
   to suspend profiling: python3 -m scalene.profile --off --pid 12345
   to resume profiling:  python3 -m scalene.profile --on  --pid 12345
scalenewin32 F)progdescriptionepilogformatter_classallow_abbrevz	--versionversionstore_constTz?prints the version number for this release of Scalene and exits)destactionconsthelpz--column-widthcolumn_widthz0Column width for profile output (default: [blue]z[/blue]))r>   typedefaultrA   z	--outfilez-file to hold profiler output (default: [blue]stdout)rC   rD   rA   z--htmlhtmlzoutput as HTML (default: [blue]web)r>   r?   r@   rD   rA   z--jsonjsonzoutput as JSON (default: [blue]z--cliclizforces use of the command-linez--stacksstackszcollect stack tracesz--webz=opens a web tab to view the profile (saved as 'profile.html')z--no-browser
no_browserz?doesn't open a web tab; just saves the profile ('profile.html')z--viewerviewerzopens the Scalene web UI.z--reduced-profilereduced_profilezEgenerate a reduced profile, with non-zero lines only (default: [blue]z--profile-intervalz6output profiles every so many seconds (default: [blue]z--cpucpuz/profile CPU time (default: [blue] True [/blue])z
--cpu-onlyz4profile CPU time ([red]deprecated: use --cpu [/red])z--gpugpuz,profile GPU time and memory (default: [blue]z	 [/blue])z/profile memory (not supported on this platform)zprofile memory (default: [blue]z--memorymemoryz--profile-allprofile_allzGprofile all executed code, not just the target program (default: [blue]zall codezonly the target programz--profile-onlyprofile_onlyzcprofile only code in filenames that contain the given strings, separated by commas (default: [blue]zno restrictionsz--profile-excludeprofile_excludezedo not profile code in filenames that contain the given strings, separated by commas (default: [blue]z--use-virtual-timeuse_virtual_timezImeasure only CPU time, not time spent in I/O or blocking (default: [blue]z--cpu-percent-thresholdcpu_percent_thresholdzLonly report profiles with at least this percent of CPU time (default: [blue]z
%%[/blue])z--cpu-sampling-ratecpu_sampling_ratez(CPU sampling rate (default: every [blue]z	s[/blue])z--allocation-sampling-windowallocation_sampling_windowz:Allocation sampling window size, in bytes (default: [blue]z bytes[/blue])z--malloc-thresholdmalloc_thresholdzIonly report profiles with at least this many allocations (default: [blue]z--program-pathprogram_pathzeThe directory containing the code to profile (default: [blue]the path to the profiled program[/blue])z--memory-leak-detectormemory_leak_detector
store_truez9EXPERIMENTAL: report likely memory leaks (default: [blue])r>   r?   rD   rA   z	--ipythonipython)requiredz--onz!start with profiling on (default))r?   rA   z--offzstart with profiling offz--pidz---unused_args)r>   rD   rA   nargszoutfile z is a directoryzlaunchbrowser.pydemo)rE   stderrz"Scalene: could not open a browser.   z_ipython-input-([0-9]+)-.*zScalene version ))O
contextlibsuppressBaseExceptionIPythonr3   r.   r1   sysexit_exitr
   r   r   r   r   platformargparseRawTextHelpFormatteradd_argumentintrB   r%   outfilerF   rH   rI   rJ   rG   rK   rM   floatprofile_intervalrO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rZ   SUPPRESSadd_mutually_exclusive_group	REMAINDERparse_known_argsospathisdirerroronpidr^   rerL   r	   dirname__file__scalene.scalene_config
subprocessPopen
executablesepscalene_configSCALENE_PORTDEVNULLr    rN   lenargvmatch
print_helpra   r<   r\   list__dict__delattr)r3   defaultsusager9   parsermemory_profile_messagegroupr   leftr~   browserdirr4   r   in_jupyter_notebookargs                   r   
parse_argszScaleneParseArgs.parse_args*   s	      / 	8+}+66,77		8 $%STcSddfgsft u 
( 	
  \\W46"$99
 	 R 	 	
 	))CHDYDYCZZbc 	 	
 	$$@'//xX5E5EG	 	 	
 	 MM2HMM&u56 	 		
 	 MM2HMM&u56 	 		
 	 LL1 	 	
 	 OO' 	 	
 	 LLP 	 	
 	 ''R 	 	
 	 , 	 	
 	" ,,XYaYqYqXrrz{ 	 	
 	 --I(JcJcIddlm	 	 	
 	 B 	 	
 	 G 	 	
 	 ?8<< " 	 		
 <<7"A #
 2x') #
 	 ' 	 	
 	 ((Z '' .	  	 	
 	))v  ,, "**	  	 	
 	",,x  // "--	  	 	
 	 # --\]e]v]v\ww  A 	 	
 	%(22_`h`~`~_  @J  K 	 	
 	!$..;H<V<V;WW`a 	 	
 	*-77MhNqNqMr  sA  B 	 	
 	 #--\]e]v]v\ww  A 	 	
 	x 	 	
 	$'11L80013 	 	
 	 "" 	 	
 <<7"777GE#8  
 3M   	#qx/@/@ 	 	
 	""$$ 	 	
 ,,.
d <<BGGMM$,,7LL8DLL>AB <<7"DGDH    ;;&.(w(??**ggooh/-!  #..%(E"&&1A"B"("%g&<&<&I&I"J"L )3(:(:(2(:(: ! < :< 88txx4;;;;#88   ||DH||DH"//DK!#((mq0 
RXX)388A;6

 #CHHD	(AQ(Fcjj)HHRL<<$_$5R~QGH<<DMM* #c"# Tzs	8 	8s   A ee#N)r   )r"   r#   r$   staticmethodobjectr   r1   r   rm   	Namespacer   r%   r   r*   r   r   r.   r.   "   sT    # # # # {h00$s);< { {r   r.   )rm   re   rx   ri   textwrapr   typingr   r   r   r   r   scalene.find_browserr	   scalene.scalene_argumentsr
   r   r   r   ry   joinr   r   scalene_gui_urlArgumentParserr   	Exceptionr(   r.   r*   r   r   <module>r      sy      	 
  7 7 - 6 @"'',,rwwx'@-Q]^_`	(H++ 	(9 D Dr   