def _handle(self, *args, **options):
    pass

def handle(self, *args, **options):
    if options['profile']:
        profiler = Profile()
profiler.runcall(self._handle, *args, **options)
profiler.print_stats()
How to profile a Django custom management command exclusively