
    BVhus                         d 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mZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ e	j                  Zd	Zd
ZdZdZdZdZdZdZdZ G d de      Z	 	 ddZd Z G d de      Z	 	 	 ddZy)z+Formats and displays profiling information.    N)
cli_shared)command_parser)debugger_cli_common)
ui_factory)	profiling)source_utilsnodeop_typeop_time	exec_time
start_timelinedevice_name_filternode_name_filterop_type_filterc                   T    e Zd ZdZej
                  fdZ	 	 	 d	dZd Zd Z	d Z
d Zy)
ProfileDataTableViewzTable View of profiling data.c                    || _         |D cg c]  }|j                   c}| _        |D cg c]#  }t        j                  |j
                  |      % c}| _        |D cg c]-  }t        j                  |j                  j                  |      / c}| _	        dddd|z  d|z  dg| _
        t        t        t        t        t        t         g| _        yc c}w c c}w c c}w )	zConstructor.

    Args:
      profile_datum_list: List of `ProfileDatum` objects.
      time_unit: must be in cli_shared.TIME_UNITS.
    force_time_unitNodezOp TypezStart Time (us)zOp Time (%s)zExec Time (%s)zFilename:Lineno(function)N)_profile_datum_listr   formatted_start_timer   time_to_readable_strr   formatted_op_timenode_exec_statsall_end_rel_microsformatted_exec_time_column_namesSORT_OPS_BY_OP_NAMESORT_OPS_BY_OP_TYPESORT_OPS_BY_START_TIMESORT_OPS_BY_OP_TIMESORT_OPS_BY_EXEC_TIMESORT_OPS_BY_LINE_column_sort_ids)selfprofile_datum_list	time_unitdatums       `/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/debug/cli/profile_analyzer_cli.py__init__zProfileDataTableView.__init__/   s      2D&8!:"!:D
 ()  	''8A	C)D (	 )  	''!!44%	' )D !#+(94*Y657D 12E35H24DFD%!:) )s   C(C2CNc                    d}|dk(  r%| j                   |   j                  j                  }n*|dk(  r| j                   |   j                  }n
|dk(  rt	        | j
                  |         }n|dk(  rt	        | j                  |         }n|dk(  rt	        | j                  |         }n|dk(  rd}|r|d	t        d
|z  }|r|d	t        d
|z  }|r|d	t        d
|z  }|d| j                   |   j                  | j                   |   j                  fz  z  }t        j                  d|      }| j                   |   j                  }nt!        d|z        t#        ||      S )a  Get the content of a cell of the table.

    Args:
      row: (int) row index.
      col: (int) column index.
      device_name_filter: Regular expression to filter by device name.
      node_name_filter: Regular expression to filter by node name.
      op_type_filter: Regular expression to filter by op type.

    Returns:
      A debuggre_cli_common.RichLine object representing the content of the
      cell, potentially with a clickable MenuItem.

    Raises:
      IndexError: if row index is out of range.
    Nr                  ps -- z %s --init_line %dzInvalid column index %d.	font_attr)r   r   	node_namer
   strr   r   r   _DEVICE_NAME_FILTER_FLAG_NODE_NAME_FILTER_FLAG_OP_TYPE_FILTER_FLAG	file_pathline_numberr   MenuItemfile_line_func
IndexErrorRL)	r'   rowcolr   r   r   	menu_itemtextcommands	            r+   valuezProfileDataTableView.valueM   so   , I
ax%%c*::DDd	%%c*22d	**3/0d	'',-d	))#./d	g	!9!35 	5	!79IJJ	!5~FF%

"
"3
'
1
1

"
"3
'
3
3)5 5 5g &..tW=i%%c*99d1C788di((    c                 ,    t        | j                        S N)lenr   r'   s    r+   	row_countzProfileDataTableView.row_count   s    t''((rI   c                 ,    t        | j                        S rK   )rL   r   rM   s    r+   column_countz!ProfileDataTableView.column_count   s    t!!""rI   c                     | j                   S rK   )r   rM   s    r+   column_namesz!ProfileDataTableView.column_names   s    rI   c                      | j                   |   S rK   )r&   )r'   rD   s     r+   column_sort_idz#ProfileDataTableView.column_sort_id   s      %%rI   )NNN)__name__
__module____qualname____doc__r   TIME_UNIT_USr,   rH   rN   rP   rR   rT    rI   r+   r   r   ,   s:    %3=3J3J FB  $!2)h)#&rI   r   c                    |r&|j                  | j                  j                        sy|r(| j                  r|j                  | j                        sy|dkD  r| j                  r| j                  |k  ry|dkD  r| j                  r| j                  |k\  ry| j
                  |r|j                  | j
                        sy||j                  | j                        sy|r&|j                  | j                  j                        syy)a  Filter function for list_profile command.

  Args:
    profile_datum: A `ProfileDatum` object.
    node_name_regex: Regular expression pattern object to filter by name.
    file_path_regex: Regular expression pattern object to filter by file path.
    op_type_regex: Regular expression pattern object to filter by op type.
    op_time_interval: `Interval` for filtering op time.
    exec_time_interval: `Interval` for filtering exec time.
    min_lineno: Lower bound for 1-based line number, inclusive.
      If <= 0, has no effect.
    max_lineno: Upper bound for 1-based line number, exclusive.
      If <= 0, has no effect.
    # TODO(cais): Maybe filter by function name.

  Returns:
    True iff profile_datum should be included.
  Fr   T)	matchr   r8   r=   r>   r
   containsr   r   )profile_datumnode_name_regexfile_path_regexop_type_regexop_time_intervalexec_time_interval
min_lineno
max_linenos           r+   _list_profile_filterrf      s    6 _22##--/##!!-"9"9:1n22*,1n22:-'M


m33
4!*:*C*C+ 2 ; ;##66!8	rI   c                 (   |t         k(  r| j                  j                  S |t        k(  r| j                  S |t
        k(  r| j                  S |t        k(  r| j                  S |t        k(  r| j                  j                  S | j                  j                  S )a  Get a profile_datum property to sort by in list_profile command.

  Args:
    profile_datum: A `ProfileDatum` object.
    sort_by: (string) indicates a value to sort by.
      Must be one of SORT_BY* constants.

  Returns:
    profile_datum property to sort by.
  )r    r   r8   r!   r
   r%   r@   r#   r   r$   r   all_start_micros)r^   sort_bys     r+   _list_profile_sort_keyrj      s     ##((222%%   ""'''%%   ''((;;;((999rI   c                       e Zd ZdZd ZddZd Z	 	 ddZd Ze	j                  Ze	j                  ZdZd	Zd
ZdZddZd Zd Zd Zy)ProfileAnalyzerzAnalyzer for profiling data.c                 |   || _         |st        d      || _        i | _        t	        j
                  dt        j                        }|j                  ddt        z  t        t        dd       |j                  d	dt        z  t        t        dd
       |j                  ddt        z  t        t        dd       |j                  dddt        dd       |j                  ddt        dd       |j                  ddt        dd       |j                  dddt        dd       |j                  dddt        dd       |j                  d d!d"t        t        d#d$j                  t        t         t        t"        t$        t&        g      z         |j                  d%d&d'd(d)*       |j                  d+d,t        t(        j*                  d-d$j                  t(        j,                        z   d.z          || j                  d/<   t	        j
                  d0t        j                        }|j                  d1t        d23       |j                  d4t        d5dgd5d67       |j                  d+d,t        t(        j*                  d-d$j                  t(        j,                        z   d.z          |j                  ddt        z  t        t        dd8       |j                  d	dt        z  t        t        dd9       |j                  ddt        z  t        t        dd:       |j                  d;d<t        d=d>       || j                  d?<   y@)AzProfileAnalyzer constructor.

    Args:
      graph: (tf.Graph) Python graph object.
      run_metadata: A `RunMetadata` protobuf object.

    Raises:
      ValueError: If run_metadata is None.
    z+No RunMetadata passed for profile analysis.zList nodes profile information.)descriptionusagez-dz--%s zfilter device name by regex.)desttypedefaulthelpz-nzfilter node name by regex.z-tzfilter op type by regex.z-fz--file_path_filterfile_path_filterzlfilter by file name at the top position of node's creation stack that does not belong to TensorFlow library.z--min_linenord   zW(Inclusive) lower bound for 1-based line number in source file. If <= 0, has no effect.z--max_linenore   zW(Exclusive) upper bound for 1-based line number in source file. If <= 0, has no effect.z-ez--execution_timeexecution_timezFilter by execution time interval (includes compute plus pre- and post -processing time). Supported units are s, ms and us (default). E.g. -e >100s, -e <100, -e [100us,1000ms]z-oz	--op_timer   zFilter by op time interval (only includes compute time). Supported units are s, ms and us (default). E.g. -e >100s, -e <100, -e [100us,1000ms]z-sz	--sort_byri   z#the field to sort the data by: (%s)z | z-rz	--reversereverse
store_truez+sort the data in reverse (descending) order)rq   actionrt   z--time_unitr)   zTime unit ()list_profilez>Print a Python source file with line-level profile informationsource_file_pathzPath to the source_file_path)rr   rt   z--cost_typer   zType of cost to display)rr   choicesrs   rt   zFilter device name by regex.zFilter node name by regex.zFilter op type by regex.z--init_line	init_liner   z/The 1-based line number to scroll to initially.print_sourceN)_graph
ValueError_run_metadata_arg_parsersargparseArgumentParserSUPPRESSadd_argumentr:   r9   r;   r<   intr"   joinr    r!   r#   r$   r%   r   rY   
TIME_UNITS)r'   graphrun_metadataaps       r+   r,   zProfileAnalyzer.__init__   s    DKDEE%DD		 	 5
!B OO))%+  - OO''#)  + OO%%!'  ) OOA  B OO'  ( OO'  ( OO9  	: OO9  : OO&3jj-/B02E/1AC DD  	F OO:  < OO''UZZ
(=(=>>D  F )+Dn%		 	 "
!B OO+  - OOi(&  ( OO''UZZ
(=(=>>D  F OO))%+  - OO''#)  + OO%%!'  ) OO>  @ )+Dn%rI   Nc                 X   d}|r	d|v r|d   }| j                   d   j                  |      j                  rt        j                  j                        nd}j
                  rt        j                  j
                        nd}j                  rt        j                  j                        nd}j                  rt        j                  j                        nd}j                  rt        j                  j                        nd}t        j                  dg      }	j                  rt        j                  j                        nd}
| j                         }t        | j                   j"                  j$                        }t'        |      D ]  }| j                   j"                  j$                  |   }|
r|
j)                  |j*                        sE ||      D cg c]+  }t-        ||||||j.                  j0                        r|- }}t3        |fdj4                        }|	j7                  | j9                  |j*                  |||j:                  j4                  j<                  j                  j                  j                  |	              |	S c c}w )
aV  Command handler for list_profile.

    List per-operation profile information.

    Args:
      args: Command-line arguments, excluding the command prefix, as a list of
        str.
      screen_info: Optional dict input containing screen information such as
        cols.

    Returns:
      Output text lines as a RichTextLines object.
    P   colsr|   Nrp   )rd   re   c                 0    t        | j                        S rK   )rj   ri   )r*   parseds    r+   <lambda>z.ProfileAnalyzer.list_profile.<locals>.<lambda>  s    4UFNNK rI   )keyrx   )r   r   r   screen_cols)r   
parse_argsr   r   parse_time_intervalrw   r   recompileru   r   r   RichTextLinesr   _get_profile_data_generatorrL   r   
step_stats	dev_statsranger\   devicerf   rd   re   sortedrx   extend_get_list_profile_linesri   r)   )r'   argsscreen_infor   rb   rc   r_   r`   ra   outputdevice_name_regexdata_generatordevice_countindexdevice_statsr*   profile_datar   s                    @r+   r|   zProfileAnalyzer.list_profilez  s{    Kv,'k~.99$?F!>> '::6>>J/3     	**6+@+@A&*  !11 zz&"9"9:7;  !11 zz&"9"9:7;  -- ZZ 5 5637  !..t4F"55 F$=$=>;? 557Nt))44>>?L|$ *''22<<UCl"3"9"9,:M:M"N-l;M# "4!,,9J9JL M M KNN$ 	((##ULfnnfnnf>N>N#)#<#<!'!8!8%44' ) )	*** M%Ms   $0J'c                 x  	
 i i 	i i 
| j                   j                         D ]  }t        |j                        D ](  }|d   }|d   }|d   }t	        j
                  |      r( n |j                  <   	|j                  <   |j                  <   |j                  
|j                  <    	
fd}|S )z~Get function that generates `ProfileDatum` objects.

    Returns:
      A function that generates `ProfileDatum` objects.
    r   r.   r/   c              3     K   | j                   D ]  }|j                  dk(  s|j                  dk(  r"t        j                  | j                  |j                  |j                  d      j                  |j                  d      j                  |j                  d      j                  |j                  d              y w)N_SOURCE_SINKrp   r   )
node_statsr8   r   ProfileDatumr   get)device_step_statsr   node_to_file_pathnode_to_func_namenode_to_line_numbernode_to_op_types     r+   profile_data_generatorzKProfileAnalyzer._get_profile_data_generator.<locals>.profile_data_generator  s     )44 	;*9,
0D0D0O
$$$$!!*"6"6;##J$8$8!<!!*"6"6;
 4 4b9; 	;	;s   C C)r   get_operationsreversed	tracebackr   guess_is_tensorflow_py_librarynamerr   )r'   optrace_entryr=   line_num	func_namer   r   r   r   r   s          @@@@r+   r   z+ProfileAnalyzer._get_profile_data_generator  s     Okk((* 
)!",,/ +N	q>N	::9E
 $- %-"''"#, !#obgg
)
; "!rI   c                    t        ||      }t        d |D              }t        d |D              }ddt        j                  ||      t        j                  ||      g}|j	                         D cg c]  }t        |       }}t        t        |            D ]   }t        ||   t        ||               ||<   " t        t        |            D ]\  }t        |j                               D ]1  }t        ||   t        |j                  ||||	|
                  ||<   3 ||xx   dz  cc<   ^ t        d	|z        g}d
|dz   ||fz  }|j                  t        |             |j                  t                      d}t               }t        |j                               D ]  }|j	                         |   }|j                  |      }|d|}||k(  r|s|dz  }t        j                  d|      }|t        ||dg      z  }|t        d||   t        |      z
  z        z  } |j                  |       t        |j                               D ]v  }t               }t        |j                               D ]=  }|j                  ||||	|
      }||z  }|t        d||   t        |      z
  z        z  }? |j                  |       x d}t!        ||      D ]  \  }}|d|z  j#                  |      z  } |j                  t                      |j                  t        |             t        j$                  |      S c c}w )a6  Get `RichTextLines` object for list_profile command for a given device.

    Args:
      device_name: (string) Device name.
      device_index: (int) Device index.
      device_count: (int) Number of devices.
      profile_datum_list: List of `ProfileDatum` objects.
      sort_by: (string) Identifier of column to sort. Sort identifier
          must match value of SORT_OPS_BY_OP_NAME, SORT_OPS_BY_OP_TYPE,
          SORT_OPS_BY_EXEC_TIME, SORT_OPS_BY_MEMORY or SORT_OPS_BY_LINE.
      sort_reverse: (bool) Whether to sort in descending instead of default
          (ascending) order.
      time_unit: time unit, must be in cli_shared.TIME_UNITS.
      device_name_filter: Regular expression to filter by device name.
      node_name_filter: Regular expression to filter by node name.
      op_type_filter: Regular expression to filter by op type.
      screen_cols: (int) Number of columns available on the screen (i.e.,
        available screen width).

    Returns:
      `RichTextLines` object containing a table that displays profiling
      information for each op.
    )r)   c              3   4   K   | ]  }|j                     y wrK   )r   .0r*   s     r+   	<genexpr>z:ProfileAnalyzer._get_list_profile_lines.<locals>.<genexpr>  s     F%Fs   c              3   H   K   | ]  }|j                   j                    y wrK   )r   r   r   s     r+   r   z:ProfileAnalyzer._get_list_profile_lines.<locals>.<genexpr>  s$      ;#  //BB ;s    "zDevice Totalrp   r   )r   r   r   r/   -zDevice %d of %d: %sr.   r|   z -s z -rNboldr6   r5   z{:<%d})r   sumr   r   rR   rL   r   maxrN   rH   rB   appendrP   rT   r   r?   zipformat#rich_text_lines_from_rich_line_list)r'   device_namedevice_indexr   r(   ri   sort_reverser)   r   r   r   r   r   total_op_timetotal_exec_timedevice_total_rowcolumn_namecolumn_widthsrD   rC   r   
device_rowbase_commandsort_idrG   head_menu_itemnew_rownew_cellrow_strwidths                                 r+   r   z'ProfileAnalyzer._get_list_profile_lines  s   8 ((:iPL F3EFFM ;'9; ;O 	''8A	C''8A	C	D -9,E,E,GI(KIM IS)*+ O}S137G7L3MNmCOS'( 	|--/0 1# #L$6$6#5!1- %7 %/ !01c1 CA	 {"#$F&q,*5 5J
MM"Z.!
MM"$ "L
$C\..01 ? --/4k++C0g*G4g	G	L5*33D'Bn	R'?@@c	R}S)C,<<=>>c? MM# \++-. g|0023 B#%%1-) & + 	82c]3/#h-?@AAB mmG G-)9: 0
s(U"**3//g0
MM"$
MM"W+BB6JJsIs   4M c                 \   t        |j                               }|j                         D cg c]  }t        |       }}t        |j                               D ]K  }t        |      D ];  }t	        ||   t        t        |j                  |      |               dz         ||<   = M |S c c}w )zDetermine the maximum column widths for each data list.

    Args:
      profile_data: list of ProfileDatum objects.

    Returns:
      List of column widths in the same order as columns in data.
    r/   )rL   rR   r   rN   r   r9   
row_values)r'   r   num_columnsr   widthsrC   rD   s          r+   #_measure_list_profile_column_widthsz3ProfileAnalyzer._measure_list_profile_column_widths=  s     l//12K2>2K2K2MN;c+NFN\++-. J{# J#3KS!8!8!=c!BCDqHJsJJ M Os   B)z#nodesz(#execs)linenosourcec           	      ~  ! ~| j                   d   j                  |      }|j                  rt        j                  |j                        nd}g }| j                         }t        | j                  j                  j                        }t        |      D ]Z  }| j                  j                  j                  |   }	|r|j                  |	j                        sD|j                   ||	             \ t        j                  |t         j"                  j%                  |j&                        |j(                  |j*                        }
|
sbt-        j.                  d|j&                  z  dt0        d|j                  dt2        d|j(                  dt4        d|j*                  g      S d}|
D ]-  }| j7                  |
|   |j8                        }t;        ||      }/ t        j<                  |j&                        \  }}d}|j8                  }|d	z   t        |      d	z   t        | j>                        d
z   |d!tA        d!d   z  |z   d!d   t        |      z
  z  z   | jB                  z   d!d   t        | jB                        z
  z  z   | jD                        }|tA        | jF                  | jH                        z  }tA        d!d   !d   z   z  | j>                  z   d!d   t        | j>                        z
  z  z   d!d   z  z   | jD                        }|tA        | jJ                  d      z  }||g}i }tM        |      D ]c  \  }}|d
z   }||
v r|
|   }| jO                  | j7                  ||j8                        ||      }|}|d!d   t        |      z
  z  z  }tA        tQ        jR                  | j7                  ||j8                        |jT                        | jD                        }|d!d   t        |      z
  z  z  }||z  }t        jV                  |j&                        dz   }d|||d
z   fz  }|j                  r|dt0        d|j                  z  }|j(                  r|dt2        d|j(                  z  }|j*                  r|dt4        d|j*                  z  }t-        jX                  d|      }tA        d|jZ                  |j\                  fz  | jD                  |g      }|d!d   t        |      z
  z  z  }||z  }n tA        dt_        !fd!D              z        }tA        d|z  | jH                        } | d!d   t        |       z
  z  z  } || z  }||z  }|ja                  |       |jb                  |k(  sEt        |      d
z
  |t,        jd                  <   f t-        jf                  ||      S )aG  Print a Python source file with line-level profile information.

    Args:
      args: Command-line arguments, excluding the command prefix, as a list of
        str.
      screen_info: Optional dict input containing screen information such as
        cols.

    Returns:
      Output text lines as a RichTextLines object.
    r   N)r   r   zuThe source file %s does not contain any profile information for the previous Session run under the following filters:z  --z: r   
   r0   r.   )cost_bar
total_costnum_nodes_execsr>   r5   r   r   r   r6   r>   r   r   $z8lp --file_path_filter %s --min_lineno %d --max_lineno %dr4   z%d(%d)c              3   2   K   | ]  }|d k7  r|     yw)r>   NrZ   )r   col_namer   s     r+   r   z/ProfileAnalyzer.print_source.<locals>.<genexpr>  s%      4(!]2 $H- 4s   z L%d)annotations)4r   r   r   r   r   r   rL   r   r   r   r   r\   r   r   r   annotate_source_against_profileospath
expanduserr}   r   r   r   r   r:   r;   r<   _get_total_cost	cost_typer   load_source_NUM_EXECS_SUB_HEADrB   _NUM_NODES_HEAD_LINE_COST_ATTR_LINENO_HEAD_LINE_NUM_ATTR_SOURCE_HEAD	enumerate_render_normalized_cost_barr   r   r)   escaper?   
node_countnode_exec_countr   r   r   INIT_SCROLL_POS_KEYr   )"r'   r   r   r   r   r   r   r   r   r   source_annotationmax_total_cost
line_indexr   source_linesline_num_widthcost_bar_max_lengthtotal_cost_headheadsub_headlinesoutput_annotationsir   r   
annotationr   annotated_lineru   rG   rE   r   line_num_columnr   s"                                    @r+   r   zProfileAnalyzer.print_sourceU  s9    	~.99$?F #55 F$=$=>;?  L557Nt))44>>?L|$ 8''22<<UCl	#4#:#:<;N;N#O.67	8 %DD
622300,,	.
  ..//0 4V5N5NO163J3JK/1F1FGIJ J N' 7
''(9*(E(.(8(8:j>:6n7
 $0#;#;$! L. &&O'!+/*Q.t7781<%	M mJ''	}\*S-AAB	C 		 	}./#d6J6J2KKL		M
 &&(D 	Bt  D,?,?@@D}Z(\*+ 	,  	! 	}./4++,- 	.	.
 	mM**	+ &&(H 4$$77H8E\* 2F41uf	$	$&v.
33  V-=-=>! "#z!:S]!JKK
77  V-=-=>",,. #'"6"68
 	c]<83z?JKK
*$99V%<%<=CLffqjP2 2$$
#;#)#<#<> >'""
#9#)#:#:< <'  
#7#)#8#8: :''00w?	X)>)>)3)C)C)E E(,(<(<i'HJ 	3+,s?/CCE 	E/)# 4m 4 4 45 6V,d.A.ABo

&_)=
=? ?o'nnll>"			V	#7:5zA~ 	33	5c2Fh BB-/ /rI   c                 b    |dk(  r|j                   S |dk(  r|j                  S t        d|z        )Nr   r   zUnsupported cost type: %s)r   r   r   )r'   aggregated_profiler   s      r+   r   zProfileAnalyzer._get_total_cost  s;    K///	i	---2Y>??rI   c                    t        t        j                  t        |      |z  |z              }|xs d}t	        d| j
                        }|t	        d|z  d||z
  z  z   d| j
                  g      z  }|t	        d| j
                        z  }|S )as  Render a text bar representing a normalized cost.

    Args:
      cost: the absolute value of the cost.
      max_cost: the maximum cost value to normalize the absolute cost with.
      length: (int) length of the cost bar, in number of characters, excluding
        the brackets on the two ends.

    Returns:
      An instance of debugger_cli_common.RichTextLine.
    r.   [r6   |r5   r   ])r   npceilfloatrB   r   )r'   costmax_costlength	num_ticksr   s         r+   r   z+ProfileAnalyzer._render_normalized_cost_bar  s     BGGE$K(2V;<=IQIt334F
by3&9*<#=="D$8$89; ;F
b 4 455FMrI   c                 <    | j                   |   j                         S rK   )r   format_help)r'   handler_names     r+   get_helpzProfileAnalyzer.get_help  s    \*6688rI   rK   )NNNr   )rU   rV   rW   rX   r,   r|   r   r   r   r   
COLOR_CYANr   COLOR_YELLOWr   r   r   r   r   r   r   r   r#  rZ   rI   r+   rl   rl      ss    $Z+x9v!"L FJ	cKJ" ))/**./",,E/N@(9rI   rl   c                 
   ~t        | |      }t        j                  ||      }|j                  d|j                  |j                  d      dg       |j                  d|j                  |j                  d      dg       |S )a  Create an instance of ReadlineUI based on a `tf.Graph` and `RunMetadata`.

  Args:
    graph: Python `Graph` object.
    run_metadata: A `RunMetadata` protobuf object.
    ui_type: (str) requested UI type, e.g., "readline".
    on_ui_exit: (`Callable`) the callback to be called when the UI exits.
    config: An instance of `cli_config.CLIConfig`.

  Returns:
    (base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer
      commands and tab-completions registered.
  )
on_ui_exitr|   lp)prefix_aliasesr   r3   )rl   r   get_uiregister_command_handlerr|   r#  r   )r   r   ui_typer'  configanalyzerclis          r+   create_profiler_uir0    s    $ UL1('j9#'V	  
 'V	   
*rI   )rv   rv   )readlineNN)rX   r   r   r   numpyr  tensorflow.python.debug.clir   r   r   r   tensorflow.python.debug.libr   r   RichLinerB   r    r!   r#   r$   r"   r%   r:   r;   r<   objectr   rf   rj   rl   r0  rZ   rI   r+   <module>r7     s    2  	 	  2 6 ; 2 1 4!!   # %  / + ' _&6 _&R 1h:2^9f ^9F  *"&"	"rI   