Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Enable profiling in scripts provided from entry_points #366

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,10 +1816,25 @@ def ensureArtifactsExist(cache, cachekey, reason, objectFile, compilerResult, ex
extraCallable()
return returnCode, compilerOutput, compilerStderr, cleanupRequired

class ProfilerError(Exception):
def __init__(self, returnCode):
self.returnCode = returnCode

if __name__ == '__main__':
def mainWrapper():
if 'CLCACHE_PROFILE' in os.environ:
INVOCATION_HASH = getStringHash(','.join(sys.argv))
cProfile.run('main()', filename='clcache-{}.prof'.format(INVOCATION_HASH))
CALL_SCRIPT = '''
import clcache
returnCode = clcache.__main__.main()
if returnCode != 0:
raise clcache.__main__.ProfilerError(returnCode)
'''
try:
cProfile.run(CALL_SCRIPT, filename='clcache-{}.prof'.format(INVOCATION_HASH))
except ProfilerError as e:
sys.exit(e.returnCode)
else:
sys.exit(main())

if __name__ == '__main__':
mainWrapper()
4 changes: 2 additions & 2 deletions pyinstaller/clcache_main.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from clcache.__main__ import main
main()
from clcache.__main__ import mainWrapper
mainWrapper()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
entry_points={
'console_scripts': [
'clcache = clcache.__main__:main',
'clcache = clcache.__main__:mainWrapper',
'clcache-server = clcache.server.__main__:main',
]
},
Expand Down