From d03b16e88bfa4c9d53818de5138350e5075f3389 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 31 May 2017 14:00:01 -0400 Subject: [PATCH] start of 'profiling utils' --- hacking/ansible_profile | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 hacking/ansible_profile diff --git a/hacking/ansible_profile b/hacking/ansible_profile new file mode 100755 index 0000000000..6612402da6 --- /dev/null +++ b/hacking/ansible_profile @@ -0,0 +1,51 @@ +#!/usr/bin/env python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import cProfile +import sys +import traceback + +import ansible.constants as C +from ansible.module_utils._text import to_text + +#__requires__ = ['ansible'] +try: + import pkg_resources +except Exception: + # Use pkg_resources to find the correct versions of libraries and set + # sys.path appropriately when there are multiversion installs. But we + # have code that better expresses the errors in the places where the code + # is actually used (the deps are optional for many code paths) so we don't + # want to fail here. + pass + +target = sys.argv.pop(1) +myclass = "%sCLI" % target.capitalize() + +try: + # define cli + mycli = getattr(__import__("ansible.cli.%s" % target, fromlist=[myclass]), myclass) +except ImportError as e: + msg = getattr(e, 'msg', getattr(e, message, '')) + if msg.endswith(' %s' % target): + raise Exception("Ansible sub-program not implemented: %s" % target) + else: + raise + +try: + args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv] +except UnicodeError: + sys.stderr.write(u"The full traceback was:\n\n%s" % to_text(traceback.format_exc())) + sys.exit(u'Command line args are parsable to utf-8') + +# init cli +cli = mycli(args) + +print(cli.__class__.version_info(gitinfo=True)) + +# parse args +cli.parse() + +# run +cProfile.run('cli.run()')