Skip to content

Instantly share code, notes, and snippets.

@ethanabrooks
Created February 8, 2017 19:11
Show Gist options
  • Save ethanabrooks/61fd8fbb77667f64e0e2d2e48d0c8825 to your computer and use it in GitHub Desktop.
Save ethanabrooks/61fd8fbb77667f64e0e2d2e48d0c8825 to your computer and use it in GitHub Desktop.
This script generates a file called 'timeline.json.' If you navigate to [](chrome://tracing/) in a browser and load this file, the browser will display a runtime and memory profile of the program.
import io
import tensorflow as tf
from tensorflow.python.client import timeline
x = tf.constant([1, 2])
y = tf.constant([3, 4])
res = tf.reduce_sum(x * y)
# Run the graph with full trace option
with tf.Session() as sess:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
sess.run(res, options=run_options, run_metadata=run_metadata)
with open('timeline.json', 'w') as f:
tl = timeline.Timeline(run_metadata.step_stats)
step_analysis = tl.analyze_step_stats()
ctf = step_analysis.chrome_trace.format_to_string()
f.write(ctf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment