Context manager that generates a trace event in the profiler.

A trace event will start when entering the context, and stop and save the result to the profiler when exiting the context. Open TensorBoard Profile tab and choose trace viewer to view the trace event in the timeline.

Trace events are created only when the profiler is enabled. More information on how to use the profiler can be found at

Example usage:

for step in range(num_steps):
  # Creates a trace event for each training step with the step number.
  with tf.profiler.experimental.Trace("Train", step_num=step):

name The name of the trace event.
**kwargs Keyword arguments added to the trace event. Both the key and value are of types that can be converted to strings, which will be interpreted by the profiler according to the traceme name.

Example usage: