<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/summary_ops_v2.py#L1354-L1405) |

Starts a trace to record computation graphs and profiling information.

    tf.summary.trace_on(
        graph=True, profiler=False, profiler_outdir=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Introduction to modules, layers, and models](https://www.tensorflow.org/guide/intro_to_modules) | - [Examining the TensorFlow Graph](https://www.tensorflow.org/tensorboard/graphs) |

Must be invoked in eager mode.

When enabled, TensorFlow runtime will collect information that can later be
exported and consumed by TensorBoard. The trace is activated across the entire
TensorFlow runtime and affects all threads of execution.

To stop the trace and export the collected information, use
[`tf.summary.trace_export`](https://www.tensorflow.org/api_docs/python/tf/summary/trace_export). To stop the trace without exporting, use
[`tf.summary.trace_off`](https://www.tensorflow.org/api_docs/python/tf/summary/trace_off).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `graph` | If True, enables collection of executed graphs. It includes ones from tf.function invocation and ones from the legacy graph mode. The default is True. |
| `profiler` | If True, enables the advanced profiler. Enabling profiler implicitly enables the graph collection. The profiler may incur a high memory overhead. The default is False. |
| `profiler_outdir` | Output directory for profiler. It is required when profiler is enabled when trace was started. Otherwise, it is ignored. |

<br />