19π
β
I solved this problem the following way:
from cProfile import Profile
from django.core.management.base import BaseCommand
class Command(BaseCommand):
...
def _handle(self, *args, **options):
# Actual code I want to profile
pass
def handle(self, *args, **options):
if options['profile']:
profiler = Profile()
profiler.runcall(self._handle, *args, **options)
profiler.print_stats()
else:
self._handle(*args, **options)
This way profiling statistics are gathered within the scope of _handle
. So instead of:
python -m cProfile manage.py testrender
Iβll have to run:
python manage.py testrender --profile
which is even better.
π€muhuk
1π
Separate the PIL functionality into its own function/class in its own module, and import it from your management command. Then you can test/profile the PIL functionality independently of Django.
π€Carl Meyer
- How to pass in a starting sequence number to a Django factory_boy factory?
- Args and kwargs in django views
0π
If I canβt find any answers. Gprof2Dot as explained here can be an acceptable hack.
It doesnβt filter out modules Iβm not interested, but hopefully it will make it easier to inspect the results visually seperating my code and Django modules.
π€muhuk
- Django REST Framework (ModelViewSet), 405 METHOD NOT ALLOWED
- Sudo pip install django
- Is there a way to set the id value of new Django objects to start at a certain value?
Source:stackexchange.com