summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-info
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbin/bcfg2-info')
-rwxr-xr-xsrc/sbin/bcfg2-info36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index 4d4e1aea1..72e6c42e0 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -2,7 +2,7 @@
'''This tool loads the Bcfg2 core into an interactive debugger'''
__revision__ = '$Revision$'
-import copy, logging, lxml.etree, sys, cmd
+import copy, logging, lxml.etree, sys, cmd, tempfile
import Bcfg2.Logger, Bcfg2.Server.Core, os
import Bcfg2.Server.Plugins.Metadata, Bcfg2.Server.Plugin
import Bcfg2.Options
@@ -287,6 +287,16 @@ Usage: [quit|exit]"""
continue
print cand[0].name
+def main(repo, plugins, password, encoding, debug, args=[]):
+ loop = infoCore(repo, plugins, password, encoding, debug)
+ if args == ['exit']:
+ raise SystemExit(0)
+ elif args:
+ loop.onecmd(" ".join(args))
+ raise SystemExit(0)
+ else:
+ loop.do_loop()
+
if __name__ == '__main__':
Bcfg2.Logger.setup_logging('bcfg2-info', to_syslog=False)
optinfo = {
@@ -297,15 +307,25 @@ if __name__ == '__main__':
'plugins': Bcfg2.Options.SERVER_PLUGINS,
'password': Bcfg2.Options.SERVER_PASSWORD,
'event debug': Bcfg2.Options.DEBUG,
+ 'profile': Bcfg2.Options.CORE_PROFILE,
'encoding': Bcfg2.Options.ENCODING})
setup = Bcfg2.Options.OptionParser(optinfo)
setup.parse(sys.argv[1:])
print setup
- loop = infoCore(setup['repo'], setup['plugins'],
- setup['password'], setup['encoding'],
- '-d' in sys.argv)
- if "args" in setup and setup['args']:
- loop.onecmd(" ".join(setup['args']))
- raise SystemExit(0)
+ if not setup['profile']:
+ main(setup['repo'], setup['plugins'], setup['password'], setup['encoding'],
+ '-d' in sys.argv, [])
else:
- loop.do_loop()
+ import hotshot, hotshot.stats
+ pfd, pfile = tempfile.mkstemp()
+ prof = hotshot.Profile(pfile)
+ try:
+ prof.runcall(main, setup['repo'], setup['plugins'], setup['password'],
+ setup['encoding'], '-d' in sys.argv, ['exit'])
+ except SystemExit:
+ stats = hotshot.stats.load(pfile)
+ stats.strip_dirs()
+ stats.sort_stats('time', 'calls')
+ stats.print_stats(80)
+ print pfile
+ raise