diff --git a/tensorflow/python/kernel_tests/summary_ops_test.py b/tensorflow/python/kernel_tests/summary_ops_test.py index 0cf35b9e342..3009541a6b6 100644 --- a/tensorflow/python/kernel_tests/summary_ops_test.py +++ b/tensorflow/python/kernel_tests/summary_ops_test.py @@ -1206,6 +1206,26 @@ class SummaryOpsTest(test_util.TensorFlowTestCase): # Reset to default state for other tests. summary_ops.set_step(None) + @test_util.run_v2_only + def testTrace_withProfiler(self): + + @def_function.function + def f(): + x = constant_op.constant(2) + y = constant_op.constant(3) + return x**y + + assert context.executing_eagerly() + logdir = self.get_temp_dir() + writer = summary_ops.create_file_writer(logdir) + summary_ops.trace_on(graph=True, profiler=True) + profiler_outdir = self.get_temp_dir() + with writer.as_default(): + f() + summary_ops.trace_export( + name='foo', step=1, profiler_outdir=profiler_outdir) + writer.close() + def events_from_file(filepath): """Returns all events in a single event file. diff --git a/tensorflow/python/ops/summary_ops_v2.py b/tensorflow/python/ops/summary_ops_v2.py index db9227c97cb..ca0be073d94 100644 --- a/tensorflow/python/ops/summary_ops_v2.py +++ b/tensorflow/python/ops/summary_ops_v2.py @@ -1370,4 +1370,7 @@ def trace_off(): context.context().disable_run_metadata() if profiler: - _profiler.stop() + try: + _profiler.stop() + except _profiler.ProfilerNotRunningError: + pass