B
    Ð»ˆdÀ  ã               @   sÖ   d Z ddlZddlZddlZddlmZ ejZe dd„ ¡Z	e dd„ ¡Z
G dd„ deƒZG d	d
„ d
eƒZi ZG dd„ deƒZG dd„ deƒZeƒ ZG dd„ deƒZG dd„ deƒZdd„ Zddd„ZejZejZdS )zGFunctions used to extract and analyze stacks.  Faster than Python libs.é    N)Ú	_tf_stackc               C   s   t ƒ gS )N)ÚSentinelMapper© r   r   úQ/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/util/tf_stack.pyÚ<lambda>#   ó    r   c               C   s   t ƒ gS )N)ÚSentinelFilterr   r   r   r   r   $   r   c               @   s0   e Zd ZdZdZdZdd„ Zdd„ Zdd„ ZdS )	ÚStackTraceTransformz4Base class for stack trace transformation functions.Nc             C   sT   | j d krtƒ | _ n| j tƒ ks(tdƒ‚| j| j  }|d | _| | ¡ |  ¡  | S )NzShared across threads?éÿÿÿÿ)Ú_thread_keyÚ_get_thread_keyÚAssertionErrorÚ_stack_dictÚparentÚappendÚupdate)ÚselfÚstackr   r   r   Ú	__enter__-   s    



zStackTraceTransform.__enter__c             C   s$   | j | j  ¡ }|| ks tdƒ‚d S )NzConcurrent access?)r   r   Úpopr   )r   Zunused_typeZunused_valueZunused_tracebackÚtopr   r   r   Ú__exit__;   s    zStackTraceTransform.__exit__c             C   s   t dƒ‚d S )Nz subclasses need to override this)ÚNotImplementedError)r   r   r   r   r   ?   s    zStackTraceTransform.update)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r	   '   s   r	   c               @   s,   e Zd ZdZeZdd„ Zdd„ Zdd„ ZdS )	ÚStackTraceMapperz@Allows remapping traceback information to different source code.c             C   s   t  ¡ | _d S )N)r   ZPyBindSourceMapÚinternal_map)r   r   r   r   Ú__init__G   s    zStackTraceMapper.__init__c             C   s   | j  t|  ¡  ¡ ƒ¡ d S )N)r   Ú	update_toÚtupleÚget_effective_source_mapÚitems)r   r   r   r   r   J   s    zStackTraceMapper.updatec             C   s   t dƒ‚dS )zFReturns a map (filename, lineno) -> (filename, lineno, function_name).z subclasses need to override thisN)r   )r   r   r   r   r"   M   s    z)StackTraceMapper.get_effective_source_mapN)	r   r   r   r   Ú_source_mapper_stacksr   r   r   r"   r   r   r   r   r   C   s
   r   c               @   s   e Zd Zdd„ ZdS )r   c             C   s   t S )N)Ú
EMPTY_DICT)r   r   r   r   r"   W   s    z'SentinelMapper.get_effective_source_mapN)r   r   r   r"   r   r   r   r   r   U   s   r   c               @   s,   e Zd ZdZeZdd„ Zdd„ Zdd„ ZdS )	ÚStackTraceFilterzFAllows filtering traceback information by removing superfluous frames.c             C   s   t  ¡ | _d S )N)r   ZPyBindFileSetÚinternal_set)r   r   r   r   r   _   s    zStackTraceFilter.__init__c             C   s   | j  t|  ¡ ƒ¡ d S )N)r'   r    ÚsetÚget_filtered_filenames)r   r   r   r   r   b   s    zStackTraceFilter.updatec             C   s   t dƒ‚d S )Nz subclasses need to override this)r   )r   r   r   r   r)   e   s    z'StackTraceFilter.get_filtered_filenamesN)	r   r   r   r   Ú_source_filter_stacksr   r   r   r)   r   r   r   r   r&   [   s
   r&   c               @   s   e Zd Zdd„ ZdS )r   c             C   s   t S )N)Ú	EMPTY_SET)r   r   r   r   r)   n   s    z%SentinelFilter.get_filtered_filenamesN)r   r   r   r)   r   r   r   r   r   l   s   r   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚCurrentModuleFilterzFFilters stack frames from the module where this is used (best effort).c                sV   t ƒ  ¡  d }d }t ¡ }z0|d k	r<|j}|d k	r<t |¡}|| _d | _W d ~~X d S )N)Úsuperr   ÚinspectÚcurrentframeÚf_backÚgetsourcefileÚ	_filenameÚ_cached_set)r   Zfilter_filenameZouter_fÚf)Ú	__class__r   r   r   u   s    


zCurrentModuleFilter.__init__c             C   s>   | j d k	r| j S t| jfƒ}| jd k	r4|| j ¡ O }|| _ |S )N)r3   Ú	frozensetr2   r   r)   )r   Zfiltered_filenamesr   r   r   r)   ‹   s    

z*CurrentModuleFilter.get_filtered_filenames)r   r   r   r   r   r)   Ú__classcell__r   r   )r5   r   r,   r   s   r,   c              C   s&   t ƒ } t t|  d jt|  d j¡S )a#  An eager-friendly alternative to traceback.extract_stack.

  Returns:
    A list-like FrameSummary containing StackFrame-like objects, which are
    namedtuple-like objects with the following fields: filename, lineno, name,
    line, meant to masquerade as traceback.FrameSummary objects.
  r
   )r   r   Úextract_stackr$   r   r*   r'   )Ú
thread_keyr   r   r   r8   –   s    r8   é   c             C   s.   t ƒ }t t| d jt| d j| |¡ dS )zàAttaches the current stack trace to `c_op`.

  Args:
    c_op: a TF_Operation object.
    stacklevel: An integer for ignoring Python wrapper stack frames.
      The default value of 1 ignores this function from the frame.
  r
   N)r   r   Úextract_stack_for_opr$   r   r*   r'   )Zc_opÚ
stacklevelr9   r   r   r   r;   ©   s    
r;   )r:   )r   Úcollectionsr.   Ú	threadingÚtensorflow.python.utilr   Ú	get_identr   Údefaultdictr$   r*   Úobjectr	   r   r%   r   r&   r6   r+   r   r,   r8   r;   ZStackTraceWrapperÚStackSummaryZ
StackFrameÚFrameSummaryr   r   r   r   Ú<module>   s&   $
