Skip to content
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ python pyheat/setup.py install
```bash
# To view the heatmap.
pyheat <path_to_python_file>
# To view the heatmap of a script with arguments.
pyheat <path_to_python_file> [arg1 arg2 ...]
# To output the heatmap as a file.
pyheat <path_to_python_file> --out image_file.png
pyheat --out image_file.png <path_to_python_file>
pyheat --help
```

### As a module

```python
from pyheat import PyHeat
ph = PyHeat(<file_path>)
# PyHeat initializer takes two arguments: script name and the
# list of command line arguments which can be possibly empty.
ph = PyHeat(<file_path>, [arg1, arg2, ...])
ph.create_heatmap()
# To view the heatmap.
ph.show_heatmap()
Expand Down
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ As a command

# To view the heatmap.
pyheat <path_to_python_file>
# To view the heatmap of a script with arguments.
pyheat <path_to_python_file> [arg1 arg2 ...]
# To output the heatmap as a file.
pyheat <path_to_python_file> --out image_file.png
pyheat --out image_file.png <path_to_python_file>
pyheat --help

As a module
Expand All @@ -75,7 +77,9 @@ As a module
.. code:: python

from pyheat import PyHeat
ph = PyHeat(<file_path>)
# PyHeat initializer takes two arguments: script name and the
# list of command line arguments which can be possibly empty.
ph = PyHeat(<file_path>, [arg1, arg2, ...])
ph.create_heatmap()
# To view the heatmap.
ph.show_heatmap()
Expand Down
3 changes: 2 additions & 1 deletion pyheat/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def main():
# Adding command line arguments.
parser.add_argument('-o', '--out', help='Output file', default=None)
parser.add_argument('pyfile', help='Python file to be profiled', default=None)
parser.add_argument('argv', help='Arguments of the python file', nargs='*', default=[])
# Parse command line arguments.
arguments = parser.parse_args()
if arguments.pyfile is not None:
# Core functionality.
pyheat = PyHeat(arguments.pyfile)
pyheat = PyHeat(arguments.pyfile, arguments.argv)
pyheat.create_heatmap()
pyheat.show_heatmap(output_file=arguments.out, enable_scroll=True)
pyheat.close_heatmap()
Expand Down
9 changes: 5 additions & 4 deletions pyheat/pyheat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FileDetails(object):
heatmaps.
"""

def __init__(self, filepath):
def __init__(self, filepath, argv):
"""Constructor.

@param filepath: Path of the file to profile.
Expand All @@ -32,13 +32,14 @@ def __init__(self, filepath):
self.lines = []
self.length = 0
self.data = None
self.argv = [filepath] + argv

def __init__(self, filepath):
def __init__(self, filepath, argv):
"""Constructor.

@param filepath: Path of the file to profile.
"""
self.pyfile = PyHeat.FileDetails(filepath)
self.pyfile = PyHeat.FileDetails(filepath, argv)
self.line_profiler = None

def create_heatmap(self):
Expand Down Expand Up @@ -83,7 +84,7 @@ def close_heatmap(self):
def __profile_file(self):
"""Method used to profile the given file line by line."""
self.line_profiler = pprofile.Profile()
self.line_profiler.runfile(open(self.pyfile.path, 'r'), {}, self.pyfile.path)
self.line_profiler.runfile(open(self.pyfile.path, 'r'), self.pyfile.argv, self.pyfile.path)

def __get_line_profile_data(self):
"""Method to procure line profiles.
Expand Down