
    YfG                    |    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mZ d dlmZ d	Z G d
 d      Zy)    )annotationsN)deque)Any)Frameframe_info_get_identifier)FrameRecordTypebuild_frame_tree)	PathOrStrzrPlease raise an issue at https://github.com/joerick/pyinstrument/issues and let me know how you caused this error!c                      e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
dZedd       ZddZd Zedd       Zedd       Z	dddZ
ddZy	)Sessionc                f    || _         || _        || _        || _        || _        || _        || _        y)zSession()

        Represents a profile session, contains the data collected during a profile session.

        :meta private:
        Nframe_records
start_timedurationsample_countstart_call_stackprogramcpu_time)selfr   r   r   r   r   r   r   s           T/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/pyinstrument/session.py__init__zSession.__init__   s8      +$ ( 0     c                    t        |       5 }t        j                  t        j                  |            cddd       S # 1 sw Y   yxY w)z
        Load a previously saved session from disk.

        :param filename: The path to load from.
        :rtype: Session
        N)openr   	from_jsonjsonload)filenamefs     r   r   zSession.load.   s8     (^ 	3q$$TYYq\2	3 	3 	3s	   (>Ac                    t        |d      5 }t        j                  | j                         |       ddd       y# 1 sw Y   yxY w)z
        Saves a Session object to disk, in a JSON format.

        :param filename: The path to save to. Using the ``.pyisession`` extension is recommended.
        wN)r   r   dumpto_json)r   r    r!   s      r   savezSession.save9   s9     (C  	)AIIdllna(	) 	) 	)s	   %;Ac                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  dS )Nr   r   )r   s    r   r%   zSession.to_jsonB   sC    !//// -- $ 5 5||
 	
r   c           
     X    t        | d   | d   | d   | d   | d   | d   | d   xs d	      S )
Nr   r   r   r   r   r   r   r   r   )r   )	json_dicts    r   r   zSession.from_jsonM   sM    #O4 .z*">2&'9:i(z*/a
 	
r   c           
     T   | j                   |j                   kD  r|| }} t        | j                  |j                  z   | j                   | j                  |j                  z   | j                  |j                  z   | j
                  | j                  | j                  |j                  z         S )a&  
        Combines two :class:`Session` objects.

        Sessions that are joined in this way probably shouldn't be interpreted
        as timelines, because the samples are simply concatenated. But
        aggregate views (the default) of this data will work.

        :rtype: Session
        r   )r   r   r   r   r   r   r   r   )session1session2s     r   combinezSession.combineY   s     !4!44!)8hH"0083I3II**&&):)::!..1F1FF%66$$&&):)::
 	
r   c                \    t        | j                        }|y|r| j                  |      }|S )z
        Parses the internal frame records and returns a tree of :class:`Frame`
        objects. This object can be rendered using a :class:`Renderer`
        object.

        :rtype: A :class:`Frame` object, or None if the session is empty.
        N)r
   r   
_trim_stem)r   	trim_stem
root_frames      r   r1   zSession.root_framer   s4     &d&8&89
4Jr   c                   t        d | j                  D              }|j                         |j                  k7  r|S |j                  dk(  rt        |j                        dk(  rpt        |      dk(  s*|j                  d   j                  |j                         k7  rn7|j                  d   }|j                  dk(  rt        |j                        dk(  rp|j                          |S )Nc              3  2   K   | ]  }t        |        y w)Nr   ).0infos     r   	<genexpr>z%Session._trim_stem.<locals>.<genexpr>   s     ^5d;^s   r      )r   r   popleft
identifiertotal_self_timelenchildrenremove_from_parent)r   framestart_stacks      r   r/   zSession._trim_stem   s     ^H]H]^^ E$4$44L##q(S-@A-E;1$q(9(D(DH[H[H](]NN1%E ##q(S-@A-E 	  "r   N)r   zlist[FrameRecordType]r   floatr   r@   r   intr   z	list[str]r   strr   r@   )r    r   returnr   )r    r   rC   None)r)   zdict[str, Any])r+   r   r,   r   rC   r   )T)r0   boolrC   zFrame | None)r>   r   )__name__
__module____qualname__r   staticmethodr   r&   r%   r   r-   r1   r/    r   r   r   r      s    !,! ! 	!
 ! $! ! !0 3 3)	
 	
 	
 
 
0$r   r   )
__future__r   r   collectionsr   typingr   pyinstrument.framer   pyinstrument.frame_infor   pyinstrument.frame_opsr	   r
   pyinstrument.typingr   ASSERTION_MESSAGEr   rJ   r   r   <module>rS      s3    "    $ = D )- A Ar   