
    BVhv                         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j                  ddd        ej                  d	d
d        G d dej                        Zy)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                       e Zd ZdZd ZddZy)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                    |rRt        j                  d      }t        j                  j	                  t
        j                  j                  |dz         }nNt        j                  d      }t        j                  j	                  t
        j                  j                  |      }t        j                  ||      5   ||||      }	d d d        t        dj                  	dz  |z              }
||
fS # 1 sw Y   -xY w)N   )python_tracer_level_with_pythonr   {0:.3f}    .A)profilerProfilerOptionsospathjoinr   FLAGSr   Profilefloatformat)selfenable_python_tracerun_benchmarkfuncnum_iters_xprofexecution_modesuidoptionsr   
total_timeus_per_examples              \/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/eager/benchmarks_test_base.pyrun_with_xprofz"MicroBenchmarksBase.run_with_xprof$   s    ((Q?gww||EKK..~0EFf((Q?gww||EKK..5f			&'	* H GjH9++J,<,NOPN>!!H Hs   9C00C9Nc                      ||||      }|dz  |z  }t        dj                  ||z              t        dj                  |dz  |z              d}t        j                  j                  rot        t        j                               }t        d|      }	| j                  d|||	||      \  }
}|
|d<   ||d<   | j                  d|||	||      \  }
}|
|d	<   ||d
<   | j                         }| j                  ||||       y)z!Run and report benchmark results.r   r   )examples_per_secr"   d   Tzxprof link with python tracez$us_per_example with xprof and pythonFz
xprof linkzus_per_example with xprof)iters	wall_timeextrasnameN)r   r   r   r   r   struuiduuid4minr$   _get_benchmark_namereport_benchmark)r   r   r   	num_itersr   r!   mean_usr*   r   r   
xprof_linkr"   benchmark_names                r#   
run_reportzMicroBenchmarksBase.run_report1   s*   tY?J3*G!)"2"29z3I"JK	 0 0c1AI1M NOF
 {{dC+o#'#6#6t]7;_7Et$M j. 0:f+,7Ef34 $(#6#6um7;_7Et$M j. (f\,:f()--/N76  P    )N)__name__
__module____qualname____doc__r$   r6    r7   r#   r	   r	      s    "Pr7   r	   )r;   r   r-   tensorflow.python.eagerr   tensorflow.python.platformr   tensorflow.python.profilerr   r   DEFINE_boolDEFINE_string	Benchmarkr	   r<   r7   r#   <module>rC      sU    ; 	  ( , >   '5"K L   Hm-L M1P$.. 1Pr7   