Added --profile CLI flag for running the Python profiler
This commit is contained in:
parent
e2123f8090
commit
c5a02423cb
@ -8,6 +8,7 @@ from . import common, pack, list_deps
|
|||||||
|
|
||||||
def cli_main():
|
def cli_main():
|
||||||
parser = argparse.ArgumentParser(description='BAT: Blender Asset Tracer')
|
parser = argparse.ArgumentParser(description='BAT: Blender Asset Tracer')
|
||||||
|
common.add_flag(parser, 'profile', help='Run the profiler, write to bam.prof')
|
||||||
|
|
||||||
# func is set by subparsers to indicate which function to run.
|
# func is set by subparsers to indicate which function to run.
|
||||||
parser.set_defaults(func=None,
|
parser.set_defaults(func=None,
|
||||||
@ -36,7 +37,19 @@ def cli_main():
|
|||||||
|
|
||||||
if not args.func:
|
if not args.func:
|
||||||
parser.error('No subcommand was given')
|
parser.error('No subcommand was given')
|
||||||
return args.func(args)
|
|
||||||
|
if args.profile:
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
prof_fname = 'bam.prof'
|
||||||
|
cProfile.runctx('args.func(args)',
|
||||||
|
globals=globals(),
|
||||||
|
locals=locals(),
|
||||||
|
filename=prof_fname)
|
||||||
|
print('Profiler exported data to', prof_fname)
|
||||||
|
print('Run "pyprof2calltree -i %r -k" to convert and open in KCacheGrind' % prof_fname)
|
||||||
|
else:
|
||||||
|
return args.func(args)
|
||||||
|
|
||||||
|
|
||||||
def config_logging(args):
|
def config_logging(args):
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
-e .
|
-e .
|
||||||
pytest==3.4.1
|
pytest==3.4.1
|
||||||
pytest-cov==2.5.1
|
pytest-cov==2.5.1
|
||||||
radon==2.2.0
|
radon==2.2.0 # for the 'radon cc' command
|
||||||
|
pyprof2calltree==1.4.3 # for converting profiler output to KCacheGrind input
|
||||||
|
|
||||||
# Secondary requirements
|
# Secondary requirements
|
||||||
attrs==17.4.0
|
attrs==17.4.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user