
    Yf                      l    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Zd dlm	Z	 d dl
Z
 G d d      Zy)    N)Dictc                   r    e Zd Zedej
                  deeef   fd       Zedej
                  de	fd       Z
y)ScalenePreloadargsreturnc                 0   dt        | j                        i}t        j                  dk(  rN| j                  r;t
        j                  j                  t        j                  d   d      |d<   d|v r|d= d|d<   |S t        j                  d	k(  rp| j                  rbt
        j                  j                  t        j                  d   j                  d
d      d      }d|v r|d   }|dz   |z   |d<   n||d<   d|v r|d= |S t        j                  dk(  rd| _        |S )N"SCALENE_ALLOCATION_SAMPLING_WINDOWdarwinr   zlibscalene.dylibDYLD_INSERT_LIBRARIESPYTHONMALLOCYES#OBJC_DISABLE_INITIALIZE_FORK_SAFETYlinux z\ zlibscalene.so
LD_PRELOAD:win32F)strallocation_sampling_windowsysplatformmemoryospathjoinscalene__path__replace)r   envnew_ld_preloadold_ld_preloads       W/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/scalene/scalene_preload.pyget_preload_environz"ScalenePreload.get_preload_environ   s'    1#//3
 <<8#{{/1ww||$$Q');0+, "S(N+9>C56* 
' \\W${{!#$$Q'//U;_"  3&%(%6N(6(<~(MC%(6C%!S(N+ 
	 \\W$DK
    c                 ,   | j                   r@t        j                         dvst        j                  d      dk7  rd| _         t        d       t        j                  t              5  ddl	m
}  |       r2t        j                  t        _        t        j                  t        _        ddd       t         j#                  |       }t%        d	 |j'                         D              rt(        j*                  j-                  |       t        j.                  d
dgt        j0                  dd z   }t3        j4                  |dd      }t        j                  t              5  t)        j6                         t)        j8                  t        j:                  j=                               k7  rHt        d|j>                          t        d|j>                          t        d|j>                          ddd       	 |jA                          |jD                  dk  r4t        dtG        jH                  |jD                         jJ                         t        j                  |jD                         yy# 1 sw Y   xY w# 1 sw Y   xY w# tB        $ r
 d|_"        Y w xY w)z
        Ensures that Scalene runs with libscalene preloaded, if necessary,
        as well as any other required environment variables.
        Returns true iff we had to run another process.
        )x86_64AMD64arm64aarch64P   FzlScalene warning: currently only 64-bit x86-64 and ARM platforms are supported for memory and copy profiling.r   )get_ipythonNc              3   \   K   | ]$  }|t         j                  j                         v & y w)N)r   environitems).0k_vs     r"   	<genexpr>z/ScalenePreload.setup_preload.<locals>.<genexpr>V   s"     Hs"****,,Hs   *,z-mr      T)	close_fdsshellzScalene now profiling process z?  to disable profiling: python3 -m scalene.profile --off --pid z?  to resume profiling:  python3 -m scalene.profile --on  --pid zScalene error: received signal)&r   r   machinestructcalcsizeprint
contextlibsuppress	ExceptionIPythonr,   Scalene
clean_exitr   exit_exitr   r#   anyr/   r   r.   update
executableargv
subprocessPopengetpgrp	tcgetpgrpstdoutfilenopidwaitKeyboardInterrupt
returncodesignalSignalsname)r   r,   req_envnew_argsresults        r"   setup_preloadzScalenePreload.setup_preload9   s    ;;&MMs#q(DK~   + 	/+}"--#..		/ !44T:HHHJJg& 	H
  %%h$eLF$$Y/ 
::<2<<

0A0A0C#DD:6::,GHYZ`ZdZdYef YZ`ZdZdYef
&   1$4NNF$5$5#56;; HHV&&'S	/ 	/$
 
 % &$%!&s,   &A I'BI43J  'I14I= JJN)__name__
__module____qualname__staticmethodargparse	Namespacer   r   r#   boolrV    r$   r"   r   r      sY    '("4"4 'c3h ' 'R ;H.. ;4 ; ;r$   r   )r[   r:   r   r   rP   r7   rF   r   typingr   r   r   r^   r$   r"   <module>r`      s/      	     
  g gr$   