Skip to content

Commit

Permalink
Improve profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Nov 4, 2023
1 parent fb04ee6 commit 61bd787
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ pyprover/
bbopt/
coconut-prelude/
index.rst
vprof.json
/coconut/icoconut/coconut/
__coconut_cache__/

# Profiling
vprof.json
profile.svg
profile.speedscope
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ dev-py3: clean setup-py3

.PHONY: setup
setup:
python -m ensurepip
-python -m ensurepip
python -m pip install --upgrade setuptools wheel pip pytest_remotedata cython

.PHONY: setup-py2
setup-py2:
python2 -m ensurepip
-python2 -m ensurepip
python2 -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata cython

.PHONY: setup-py3
setup-py3:
python3 -m ensurepip
-python3 -m ensurepip
python3 -m pip install --upgrade setuptools wheel pip pytest_remotedata cython

.PHONY: setup-pypy
setup-pypy:
pypy -m ensurepip
-pypy -m ensurepip
pypy -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: setup-pypy3
setup-pypy3:
pypy3 -m ensurepip
-pypy3 -m ensurepip
pypy3 -m pip install --upgrade setuptools wheel pip pytest_remotedata

.PHONY: install
Expand Down Expand Up @@ -337,10 +337,21 @@ profile-parser: export COCONUT_PURE_PYTHON=TRUE
profile-parser:
coconut ./coconut/tests/src/cocotest/agnostic ./coconut/tests/dest/cocotest --force --jobs 0 --profile --verbose --stack-size 4096 --recursion-limit 4096 2>&1 | tee ./profile.log

.PHONY: pyspy
pyspy:
py-spy record -o profile.svg --native -- python -m coconut ./coconut/tests/src/cocotest/agnostic ./coconut/tests/dest/cocotest --force --jobs 0
open profile.svg
.PHONY: open-speedscope
open-speedscope:
npm install -g speedscope
speedscope ./profile.speedscope

.PHONY: pyspy-purepy
pyspy-purepy: export COCONUT_PURE_PYTHON=TRUE
pyspy-purepy:
py-spy record -o profile.speedscope --format speedscope --subprocesses -- python -m coconut ./coconut/tests/src/cocotest/agnostic ./coconut/tests/dest/cocotest --force
open-speedscope

.PHONY: pyspy-native
pyspy-native:
py-spy record -o profile.speedscope --format speedscope --native -- python -m coconut ./coconut/tests/src/cocotest/agnostic ./coconut/tests/dest/cocotest --force --jobs 0
open-speedscope

.PHONY: vprof-time
vprof-time:
Expand Down
2 changes: 2 additions & 0 deletions coconut/compiler/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
univ_open,
get_target_info,
assert_remove_prefix,
memoize,
)
from coconut.compiler.util import (
split_comment,
Expand Down Expand Up @@ -96,6 +97,7 @@ def minify_header(compiled):
template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")


@memoize()
def get_template(template):
"""Read the given template file."""
with univ_open(os.path.join(template_dir, template) + template_ext, "r") as template_file:
Expand Down
2 changes: 1 addition & 1 deletion coconut/compiler/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def get_pyparsing_cache():
else: # on pyparsing we have to do this
try:
# this is sketchy, so errors should only be complained
return get_func_closure(packrat_cache.get.__func__)["cache"]
return get_func_closure(packrat_cache.set.__func__)["cache"]
except Exception as err:
complain(err)
return {}
Expand Down
1 change: 1 addition & 0 deletions coconut/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def everything_in(req_dict):

extras["dev"] = uniqueify_all(
everything_in(extras),
get_reqs("purepython"),
get_reqs("dev"),
)

Expand Down

0 comments on commit 61bd787

Please sign in to comment.