o
    ?e.                     @   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.Nc                 C   s~   t jj| ||||d tj|}t|r-t|s!t	d| t
|r,t	d| nt| || _d| _t | _dS )a  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.

    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	    r   q/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/debug/wrappers/dumping_wrapper.pyr      s*    



z#DumpingDebugWrapperSession.__init__c           	      C   sD  | 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   n1 sZw   Y  t }|rkt| nt||j_tj|tjtj }t
tj|d}||  W d   n1 sw   Y  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reprZ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_urlsQ   s8   





z1DumpingDebugWrapperSession.prepare_run_debug_urls)NNN)__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   