tf.profiler.experimental.Trace
Stay organized with collections
Save and categorize content based on your preferences.
Context manager that generates a trace event in the profiler.
tf.profiler.experimental.Trace(
name, **kwargs
)
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
https://tensorflow.org/guide/profiler
Example usage:
tf.profiler.experimental.start('logdir')
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, _r=1):
train_fn()
tf.profiler.experimental.stop()
Args |
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:
tf.profiler.experimental.start('logdir')
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):
train_fn()
tf.profiler.experimental.stop()
The example above uses the keyword argument "step_num" to specify the
training step being traced.
|
Methods
View source
set_metadata(
**kwargs
)
Sets metadata in this trace event.
Args |
**kwargs
|
metadata in key-value pairs.
|
This method enables setting metadata in a trace event after it is
created.
Example usage:
def call(function):
with tf.profiler.experimental.Trace("call",
function_name=function.name) as tm:
binary, in_cache = jit_compile(function)
tm.set_metadata(in_cache=in_cache)
execute(binary)
In this example, we want to trace how much time spent on
calling a function, which includes compilation and execution.
The compilation can be either getting a cached copy of the
binary or actually generating the binary, which is indicated
by the boolean "in_cache" returned by jit_compile(). We need
to use set_metadata() to pass in_cache because we did not know
the in_cache value when the trace was created (and we cannot
create the trace after jit_compile(), because we want
to measure the entire duration of call()).
__enter__
View source
__enter__()
__exit__
View source
__exit__(
exc_type, exc_val, exc_tb
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[],null,["# tf.profiler.experimental.Trace\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/profiler/trace.py#L27-L123) |\n\nContext manager that generates a trace event in the profiler. \n\n tf.profiler.experimental.Trace(\n name, **kwargs\n )\n\nA trace event will start when entering the context, and stop and save the\nresult to the profiler when exiting the context. Open TensorBoard Profile tab\nand choose trace viewer to view the trace event in the timeline.\n\nTrace events are created only when the profiler is enabled. More information\non how to use the profiler can be found at\n\u003chttps://tensorflow.org/guide/profiler\u003e\n\n#### Example usage:\n\n tf.profiler.experimental.start('logdir')\n for step in range(num_steps):\n # Creates a trace event for each training step with the step number.\n with tf.profiler.experimental.Trace(\"Train\", step_num=step, _r=1):\n train_fn()\n tf.profiler.experimental.stop()\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `name` | The name of the trace event. |\n| `**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. \u003cbr /\u003e Example usage: tf.profiler.experimental.start('logdir') 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): train_fn() tf.profiler.experimental.stop() The example above uses the keyword argument \"step_num\" to specify the training step being traced. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `set_metadata`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/profiler/trace.py#L87-L119) \n\n set_metadata(\n **kwargs\n )\n\nSets metadata in this trace event.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|------------------------------|\n| `**kwargs` | metadata in key-value pairs. |\n\n\u003cbr /\u003e\n\nThis method enables setting metadata in a trace event after it is\ncreated.\n\n#### Example usage:\n\n\n def call(function):\n with tf.profiler.experimental.Trace(\"call\",\n function_name=function.name) as tm:\n binary, in_cache = jit_compile(function)\n tm.set_metadata(in_cache=in_cache)\n execute(binary)\n\nIn this example, we want to trace how much time spent on\ncalling a function, which includes compilation and execution.\nThe compilation can be either getting a cached copy of the\nbinary or actually generating the binary, which is indicated\nby the boolean \"in_cache\" returned by jit_compile(). We need\nto use set_metadata() to pass in_cache because we did not know\nthe in_cache value when the trace was created (and we cannot\ncreate the trace after jit_compile(), because we want\nto measure the entire duration of call()).\n\n### `__enter__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/profiler/trace.py#L83-L85) \n\n __enter__()\n\n### `__exit__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/profiler/trace.py#L121-L123) \n\n __exit__(\n exc_type, exc_val, exc_tb\n )"]]