diff --git a/blender_asset_tracer/cli/__init__.py b/blender_asset_tracer/cli/__init__.py index 327d7db..966cda7 100644 --- a/blender_asset_tracer/cli/__init__.py +++ b/blender_asset_tracer/cli/__init__.py @@ -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,7 +37,19 @@ def cli_main(): if not args.func: 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): diff --git a/requirements-dev.txt b/requirements-dev.txt index 77420ed..55c08a1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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