提交 38d3e84e 编写于 作者: Q qijun

add profiling scripts

上级 15013709
......@@ -32,9 +32,10 @@ RUN ${update_mirror_cmd}
apt-get update && \
apt-get install -y locales && \
apt-get -y install gcc && \
apt-get -y install graphviz && \
apt-get -y clean && \
localedef -f UTF-8 -i en_US en_US.UTF-8 && \
pip install -U matplotlib jupyter numpy requests scipy
pip install -U matplotlib jupyter numpy requests scipy gprof2dot
EXPOSE 8888
CMD ["sh", "-c", "jupyter notebook --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token='' --NotebookApp.disable_check_xsrf=True /book/"]
......
#!/usr/local/bin/python
import pstats
import sys
file_readable = sys.argv[1] + ".readable"
stream = open(file_readable, "w")
p = pstats.Stats(sys.argv[1], stream=stream)
p.strip_dirs().sort_stats("time").print_stats(20)
p.strip_dirs().sort_stats("cumtime").print_stats(20)
stream.close()
#!/bin/bash
book_dir=/book
work_dir=/book/.tools/profile
pushd $book_dir
array=()
while IFS= read -r -d $'\0'; do
array+=("$REPLY")
done < <(find ${book_dir} -name train.py -print0)
for file in "${array[@]}"; do
echo $file
dir=$(dirname "${file}")
result=${file%.*}'.prof'
result_png=${result}'.png'
pushd $dir
python -m cProfile -o $result $file
popd
${work_dir}/get_stats.py $result
gprof2dot -f pstats $result | dot -Tpng -o $result_png
done
popd
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册