Table of Contents |
---|
Load Testing
...
https://github.com/joerick/pyinstrument
Example of a profile using pyinstrument, writing output to a file:
Code Block | ||||
---|---|---|---|---|
| ||||
from pyinstrument import Profiler profiler = Profiler(use_signal=False) profiler.start() # Do stuff here profiler.stop() # write profile data to file with open('my.log', 'w') as f: f.write(profiler.output_text()) |
...
SnakeViz
Here are the steps to profile your python code with cProfile and then view the results using RunSnakeRunusing SnakeViz.
- export VAGRANT_X11=1
- vagrant ssh
- First time only:
- sudo pip install wxPython
- sudo apt-get install python-profiler python-wxgtk2.8 python-setuptools
- sudo pip install SquareMap RunSnakeRun
- sudo su edxapp
Add the following to the code that you want to profile
Profiling blockimport
cProfile
import
uuid
pr
=
cProfile.Profile()
pr.enable()
try
from openedx.core.djangoapps.performance.utils import collect_profile
with collect_profile:
<python_code_to_profile>
finally
:
pr.disable()
pr.dump_stats(
"<filepath>_{0}_<git_hash>.profile"
.
format
(uuid.uuid4()))
Then use RunSnake SnakeViz by issuing:
runsnake snakeviz DIRECTORY/FILE_NAME.profile
...