o
    ?ev                     @   sj   d Z ddlZddlZddlmZ ddlmZ ddlmZ	 e
ddd ed	d
d G dd dejZdS )z3Benchmark base to run and report benchmark results.    N)test)flags)profiler_v2xprofFz'Run and report benchmarks with xprof onlogdirz/tmp/xprof/zDirectory to store xprof datac                   @   s"   e Zd ZdZdd ZdddZdS )MicroBenchmarksBasezRun and report benchmark results.

  The first run is without any profilng.
  Second run is with xprof and python trace. Third run is with xprof without
  python trace. Note: xprof runs are with fewer iterations.
  c                 C   s   |rt jdd}tjtjj|d }nt jdd}tjtjj|}t || ||||}	W d    n1 s:w   Y  t	d
|	d | }
||
fS )N   )Zpython_tracer_levelZ_with_pythonr   {0:.3f}    .A)profilerZProfilerOptionsospathjoinr   FLAGSr   ZProfilefloatformat)selfZenable_python_tracerun_benchmarkfuncnum_iters_xprofexecution_modesuidoptionsr   
total_timeus_per_example r   m/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/eager/benchmarks_test_base.pyrun_with_xprof$   s   z"MicroBenchmarksBase.run_with_xprofNc                 C   s   ||||}|d | }t d|| t d|d | d}tjjrXtt }td|}	| 	d|||	||\}
}|
|d< ||d< | 	d|||	||\}
}|
|d	< ||d
< | 
 }| j||||d dS )z!Run and report benchmark results.r
   r	   )Zexamples_per_secr   d   Tzxprof link with python tracez$us_per_example with xprof and pythonFz
xprof linkzus_per_example with xprof)ZitersZ	wall_timeextrasnameN)r   r   r   r   r   struuiduuid4minr   Z_get_benchmark_nameZreport_benchmark)r   r   r   Z	num_itersr   r   Zmean_usr   r   r   Z
xprof_linkr   Zbenchmark_namer   r   r   
run_report1   s0   

zMicroBenchmarksBase.run_report)N)__name__
__module____qualname____doc__r   r%   r   r   r   r   r      s    r   )r)   r   r"   Ztensorflow.python.eagerr   Ztensorflow.python.platformr   Ztensorflow.python.profilerr   r   ZDEFINE_boolZDEFINE_stringZ	Benchmarkr   r   r   r   r   <module>   s   