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():
|
||||
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.
|
||||
parser.set_defaults(func=None,
|
||||
@ -36,6 +37,18 @@ def cli_main():
|
||||
|
||||
if not args.func:
|
||||
parser.error('No subcommand was given')
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
-e .
|
||||
pytest==3.4.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
|
||||
attrs==17.4.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user