Exemplo n.º 1
0
    def test_context_manager_with_options(self):
        logdir = self.get_temp_dir()
        options = profiler.ProfilerOptions(host_tracer_level=3,
                                           python_tracer_level=1)
        with profiler.Profile(logdir, options):
            with trace.Trace('three_times_five'):
                three = constant_op.constant(3)
                five = constant_op.constant(5)
                product = three * five
            self.assertAllEqual(15, product)

        file_list = gfile.ListDirectory(logdir)
        self.assertEqual(len(file_list), 2)
Exemplo n.º 2
0
 def run_with_xprof(self, enable_python_trace, run_benchmark, func,
                    num_iters_xprof, execution_mode, suid):
     if enable_python_trace:
         options = profiler.ProfilerOptions(python_tracer_level=1)
         logdir = os.path.join(flags.FLAGS.logdir, suid + "_with_python")
     else:
         options = profiler.ProfilerOptions(python_tracer_level=0)
         logdir = os.path.join(flags.FLAGS.logdir, suid)
     with profiler.Profile(logdir, options):
         total_time = run_benchmark(func, num_iters_xprof, execution_mode)
     us_per_example = float("{0:.3f}".format(total_time * 1e6 /
                                             num_iters_xprof))
     return logdir, us_per_example
Exemplo n.º 3
0
def run_with_xprof(self,
                   func,
                   num_iters_xprof=100,
                   enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
    suid = str(uuid.uuid4())
    if enable_python_trace:
        options = profiler.ProfilerOptions(python_tracer_level=1)
        logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
    else:
        options = profiler.ProfilerOptions(python_tracer_level=0)
        logdir = os.path.join(logdir, suid)

    start = time.time()
    with profiler.Profile(logdir, options):
        for _ in range(num_iters_xprof):
            func()
    total_time = time.time() - start
    us_per_example = float("{0:.3f}".format(total_time * 1e6 /
                                            num_iters_xprof))
    return logdir, us_per_example