Last active
October 6, 2017 00:08
-
-
Save jart/d64aa49ff5c0093c2caa2c2975e89a5d to your computer and use it in GitHub Desktop.
TensorBoard Profiling Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install yappi | |
# tensorboard-profile-wall-time --logdir=/google/data/ro/users/ja/jart/tensorboard/userlogdirs/1 | |
tensorboard-profile-wall-time() { | |
-tensorboard-profile wall "$@" | |
} | |
tensorboard-profile-cpu-time() { | |
-tensorboard-profile cpu "$@" | |
} | |
-tensorboard-profile() { | |
clock=$1 | |
shift | |
bazel build //tensorboard || return | |
# yappi -o profile.txt bazel-bin/tensorboard/tensorboard "$@" | |
python <(cat <<EOF | |
import sys | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_html5lib') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_mozilla_bleach') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_pocoo_werkzeug') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_pythonhosted_markdown') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_pythonhosted_six') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/org_tensorflow_tensorboard') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/protobuf') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles/protobuf/python') | |
sys.path.insert(0, 'bazel-bin/tensorboard/tensorboard.runfiles') | |
import yappi | |
import atexit | |
@atexit.register | |
def done(): | |
yappi.convert2pstats(yappi.get_func_stats()).dump_stats('profile.binary') | |
yappi.set_clock_type('$clock') | |
yappi.start() | |
from tensorboard import main | |
main.main() | |
EOF | |
) "$@" | |
python <(cat <<'EOF' | |
import os | |
import pstats | |
with open('profile.txt', 'w') as out: | |
pstats.Stats('profile.binary', stream=out).print_stats() | |
os.unlink('profile.binary') | |
EOF | |
) | |
sed -i -e 's! [^ ]*/tensorboard.runfiles/! !' profile.txt | |
sed -i -e 's! [^ ]*/site-packages/! !' profile.txt | |
( | |
sed -n 1,7p profile.txt | |
head -n20 profile-ncalls.txt | |
echo '... [see profile-ncalls.txt]' | |
echo | |
echo '=== TOTAL TIME ===' | |
sed -n 7p profile.txt | |
sed 1,7d profile.txt | sort -nrk2 >profile-tottime.txt | |
head -n20 profile-tottime.txt | |
echo '... [see profile-tottime.txt]' | |
echo | |
echo '=== TOTAL TIME PER CALL ===' | |
sed -n 7p profile.txt | |
sed 1,7d profile.txt | sort -nrk3 >profile-tottime-percall.txt | |
head -n20 profile-tottime-percall.txt | |
echo '... [see profile-tottime-percall.txt]' | |
echo | |
echo '=== CUMULATIVE TIME ===' | |
sed -n 7p profile.txt | |
sed 1,7d profile.txt | sort -nrk4 >profile-cumtime.txt | |
head -n20 profile-cumtime.txt | |
echo '... [see profile-cumtime.txt]' | |
echo | |
echo '=== CUMULATIVE TIME PER CALL ===' | |
sed -n 7p profile.txt | |
sed 1,7d profile.txt | sort -nrk5 >profile-cumtime-percall.txt | |
head -n20 profile-cumtime-percall.txt | |
echo '... [see profile-cumtime-percall.txt]' | |
) | less -S | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment