def main(arguments=None):
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
parser = HelpfulArgumentParser(description=__doc__, prog='igdiscover')
parser.add_argument('--profile', default=False, action='store_true',
help='Save profiling information to igdiscover.prof')
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
subparsers = parser.add_subparsers()
for command_name in COMMANDS:
module = importlib.import_module('.' + command_name, 'igdiscover')
subparser = subparsers.add_parser(command_name,
help=module.__doc__.split('\n')[1], description=module.__doc__)
subparser.set_defaults(func=module.main)
module.add_arguments(subparser)
args = parser.parse_args(arguments)
if not hasattr(args, 'func'):
parser.error('Please provide the name of a subcommand to run')
elif args.profile:
import cProfile as profile
profile.runctx('args.func(args)', globals(), locals(), filename='igdiscover.prof')
logger.info('Wrote profiling data to igdiscover.prof')
else:
args.func(args)
if sys.platform == 'linux':
rself = resource.getrusage(resource.RUSAGE_SELF)
rchildren = resource.getrusage(resource.RUSAGE_CHILDREN)
memory_kb = rself.ru_maxrss + rchildren.ru_maxrss
cpu_time = rself.ru_utime + rself.ru_stime + rchildren.ru_utime + rchildren.ru_stime
cpu_time_s = format_duration(cpu_time)
logger.info('CPU time {}. Maximum memory usage {:.3f} GB'.format(
cpu_time_s, memory_kb / 1E6))
评论列表
文章目录