diff --git a/.tools/build_docker.sh b/.tools/build_docker.sh index 7a06c180d2ed0a99c2826ebba916aa9cbd842767..a277d57177d100df8a801a307f18b54b95e95dd7 100755 --- a/.tools/build_docker.sh +++ b/.tools/build_docker.sh @@ -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/"] diff --git a/.tools/profile/get_stats.py b/.tools/profile/get_stats.py new file mode 100755 index 0000000000000000000000000000000000000000..f10fd9ee8418fe9a4ad4e57a18b5874cb1d549f6 --- /dev/null +++ b/.tools/profile/get_stats.py @@ -0,0 +1,12 @@ +#!/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() diff --git a/.tools/profile/profile.sh b/.tools/profile/profile.sh new file mode 100755 index 0000000000000000000000000000000000000000..f3543bd4b3bbe250e7485c8f5ade1118a8898344 --- /dev/null +++ b/.tools/profile/profile.sh @@ -0,0 +1,22 @@ +#!/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