Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-adding pycallgraph control script #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ Features
- Modules can be visually grouped together.
- Easily extendable to create your own output formats.

Command-line interface
----------------------

The following commands shall collect the call graph into the specified output file in .dot format, which can then be visualized as an SVG image:

```
pycallgraph graphviz --output-format=dot --output-file=script.dot -- ./script.py
dot -Tsvg script.dot > script.svg
```

Development
-----------

Clone this repository and issue a `poetry install` command, in order to install the current version of package.
21 changes: 21 additions & 0 deletions pycallgraph/pycallgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,24 @@ def prepare_output(self, output):
output.sanity_check()
output.set_processor(self.tracer.processor)
output.reset()

def main():
import os, sys
# Inject the current working directory so modules can be imported.
sys.path.insert(0, os.getcwd())

import pycallgraph as __pycallgraph

__config = __pycallgraph.Config()
__config.parse_args()
__config.strip_argv()

globals()['__file__'] = __config.command

__file_content = open(__config.command).read()

with __pycallgraph.PyCallGraph(config=__config):
exec(__file_content)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion pycallgraph/test/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def execute(arguments):
command = "PYTHONPATH=. scripts/pycallgraph " + arguments
command = "pycallgraph " + arguments
return subprocess.check_output(command, shell=True).decode("utf-8")


Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name = 'default'
url = 'https://pypi.python.org/simple'
secondary = true

[tool.poetry.scripts]
pycallgraph = "pycallgraph.pycallgraph:main"

[tool.poetry.dependencies]
python = "^3.6.1"
memory_profiler="^0.58.0"
Expand All @@ -37,4 +40,4 @@ sphinx = "^3.4.1"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
build-backend = "poetry.masonry.api"
26 changes: 0 additions & 26 deletions scripts/pycallgraph

This file was deleted.