Skip to content

Commit d03b16e

Browse files
committed
start of 'profiling utils'
1 parent c3ffc49 commit d03b16e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

hacking/ansible_profile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
2+
from __future__ import (absolute_import, division, print_function)
3+
__metaclass__ = type
4+
5+
import cProfile
6+
import sys
7+
import traceback
8+
9+
import ansible.constants as C
10+
from ansible.module_utils._text import to_text
11+
12+
#__requires__ = ['ansible']
13+
try:
14+
import pkg_resources
15+
except Exception:
16+
# Use pkg_resources to find the correct versions of libraries and set
17+
# sys.path appropriately when there are multiversion installs. But we
18+
# have code that better expresses the errors in the places where the code
19+
# is actually used (the deps are optional for many code paths) so we don't
20+
# want to fail here.
21+
pass
22+
23+
target = sys.argv.pop(1)
24+
myclass = "%sCLI" % target.capitalize()
25+
26+
try:
27+
# define cli
28+
mycli = getattr(__import__("ansible.cli.%s" % target, fromlist=[myclass]), myclass)
29+
except ImportError as e:
30+
msg = getattr(e, 'msg', getattr(e, message, ''))
31+
if msg.endswith(' %s' % target):
32+
raise Exception("Ansible sub-program not implemented: %s" % target)
33+
else:
34+
raise
35+
36+
try:
37+
args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv]
38+
except UnicodeError:
39+
sys.stderr.write(u"The full traceback was:\n\n%s" % to_text(traceback.format_exc()))
40+
sys.exit(u'Command line args are parsable to utf-8')
41+
42+
# init cli
43+
cli = mycli(args)
44+
45+
print(cli.__class__.version_info(gitinfo=True))
46+
47+
# parse args
48+
cli.parse()
49+
50+
# run
51+
cProfile.run('cli.run()')

0 commit comments

Comments
 (0)