Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Load Testing

...

https://github.com/joerick/pyinstrument 


Example of a profile using pyinstrument, writing output to a file:

 



 

Code Block
python
python
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.

    1. export VAGRANT_X11=1
    2. vagrant ssh
    3. First time only:
      1. sudo pip install wxPython
      2. sudo apt-get install python-profiler python-wxgtk2.8 python-setuptools
      3. sudo pip install SquareMap RunSnakeRun
      sudo Install SnakeViz.  Please update this document with the steps you used if you do it.
    4. sudo su edxapp
    5. Add the following to the code that you want to profile

      Profiling block


       

      import 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()))
    6. Then use RunSnake SnakeViz by issuing:

      1. runsnake snakeviz DIRECTORY/FILE_NAME.profile

...