[Cherrypick:2.4] Fix an exception when profiler is stopped twice
This commit is contained in:
parent
df05368807
commit
ace5b10475
@ -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.
|
||||
|
@ -1370,4 +1370,7 @@ def trace_off():
|
||||
context.context().disable_run_metadata()
|
||||
|
||||
if profiler:
|
||||
_profiler.stop()
|
||||
try:
|
||||
_profiler.stop()
|
||||
except _profiler.ProfilerNotRunningError:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user