restrictions = [] profile_pattern = getattr(settings, 'PROFILE_PATTERN', None) if profile_pattern: restrictions.append(profile_pattern) max_results = getattr(settings, 'MAX_PROFILE_RESULTS', 80) if max_results and max_results != 'all': restrictions.append(max_results) stats.print_stats(*restrictions) extra_output = getattr(settings, 'EXTRA_PROFILE_OUTPUT', None) or () if not isinstance(sort_by, (list, tuple)): extra_output = (extra_output,) if 'callees' in extra_output: stats.print_callees() if 'callers' in extra_output: stats.print_callers() logging.info("Profile data:\n%s.", stream.getvalue()) def make_profileable(func): if getattr(settings, 'ENABLE_PROFILER', False): return lambda: profile_main(func) return func main = make_profileable(real_main) if __name__ == '__main__': from ghostnames.models import Ghost Ghost.initialize() main()