B
    Ò»ˆdó  ã               @   sb   d Z ddlZddl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 G dd„ de	jƒZdS )	z?Debugger wrapper session that dumps debug data to file:// URLs.é    N)Ú	event_pb2)Ú
debug_data)Ú	framework)Úgfilec               @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚDumpingDebugWrapperSessionz:Debug Session wrapper that dumps debug data to filesystem.NTc             C   s„   |rt jj| ||||d tj |¡}t |¡r`t |¡sHt	d| ƒ‚qjt 
|¡rjt	d| ƒ‚n
t |¡ || _d| _t ¡ | _dS )aX  Constructor of DumpingDebugWrapperSession.

    Args:
      sess: The TensorFlow `Session` object being wrapped.
      session_root: (`str`) Path to the session root directory. Must be a
        directory that does not exist or an empty directory. If the directory
        does not exist, it will be created by the debugger core during debug
        `tf.Session.run`
        calls.
        As the `run()` calls occur, subdirectories will be added to
        `session_root`. The subdirectories' names has the following pattern:
          run_<epoch_time_stamp>_<zero_based_run_counter>
        E.g., run_1480734393835964_ad4c953a85444900ae79fc1b652fb324
      watch_fn: (`Callable`) A Callable that can be used to define per-run
        debug ops and watched tensors. See the doc of
        `NonInteractiveDebugWrapperSession.__init__()` for details.
      thread_name_filter: Regular-expression white list for threads on which the
        wrapper session will be active. See doc of `BaseDebugWrapperSession` for
        more details.
      pass_through_operrors: If true, all captured OpErrors will be
        propagated. By default this captures all OpErrors.
      log_usage: (`bool`) whether the usage of this class is to be logged.

    Raises:
       ValueError: If `session_root` is an existing and non-empty directory or
       if `session_root` is a file.
    )Úwatch_fnÚthread_name_filterÚpass_through_operrorsz&session_root path points to a file: %sz5session_root path points to a non-empty directory: %sr   N)r   Ú!NonInteractiveDebugWrapperSessionÚ__init__ÚosÚpathÚ
expanduserr   ZExistsZIsDirectoryÚ
ValueErrorZListDirectoryZMakeDirsÚ_session_rootÚ_run_counterÚ	threadingÚLockÚ_run_counter_lock)ÚselfÚsessZsession_rootr   r   r	   Z	log_usage© r   úb/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/debug/wrappers/dumping_wrapper.pyr      s"    #




z#DumpingDebugWrapperSession.__init__c       	   	   C   s  | j  ¡  tj | jdtt ¡ d ƒ| jf ¡}|  jd7  _| j  	¡  t
 |¡ t ¡ }t|ƒ|j_tj |tjtj ¡}t
 tj |¡d¡}| | ¡ ¡ W dQ R X t ¡ }|rÂt| ¡ ƒnt|ƒ|j_tj |tjtj ¡}t
 tj |¡d¡}| | ¡ ¡ W dQ R X d| gS )aW  Implementation of abstract method in superclass.

    See doc of `NonInteractiveDebugWrapperSession.prepare_run_debug_urls()`
    for details. This implementation creates a run-specific subdirectory under
    self._session_root and stores information regarding run `fetches` and
    `feed_dict.keys()` in the subdirectory.

    Args:
      fetches: Same as the `fetches` argument to `Session.run()`
      feed_dict: Same as the `feed_dict` argument to `Session.run()`

    Returns:
      debug_urls: (`str` or `list` of `str`) file:// debug URLs to be used in
        this `Session.run()` call.
    z	run_%d_%dg    €„.Aé   ÚwbNzfile://)r   Úacquirer   r   Újoinr   ÚintÚtimer   Úreleaser   ZMkDirr   ÚEventÚreprÚlog_messageÚmessager   ZMETADATA_FILE_PREFIXZFETCHES_INFO_FILE_TAGZOpenÚwriteZSerializeToStringÚkeysZFEED_KEYS_INFO_FILE_TAG)	r   ZfetchesZ	feed_dictZrun_dirZfetches_eventZfetches_pathÚfZfeed_keys_eventZfeed_keys_pathr   r   r   Úprepare_run_debug_urlsX   s,    


z1DumpingDebugWrapperSession.prepare_run_debug_urls)NNNT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   r   r   r   r   r      s      
4r   )r+   r   r   r   Ztensorflow.core.utilr   Ztensorflow.python.debug.libr   Z tensorflow.python.debug.wrappersr   Ztensorflow.python.platformr   r
   r   r   r   r   r   Ú<module>   s   