summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-03-09 16:27:24 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-03-09 16:27:24 +0000
commit96be3de87556d37f94d07eea726f6dd1a5b561b6 (patch)
tree65f4c5b79f459315f9fcab96c29c4f13a521a7ec /src
parent27e1b2cf031f6bcd58a3ebd74e5acf25f1ba2009 (diff)
downloadbcfg2-96be3de87556d37f94d07eea726f6dd1a5b561b6.tar.gz
bcfg2-96be3de87556d37f94d07eea726f6dd1a5b561b6.tar.bz2
bcfg2-96be3de87556d37f94d07eea726f6dd1a5b561b6.zip
Implement profiler mode for bcfg2-info
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5111 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Options.py2
-rwxr-xr-xsrc/sbin/bcfg2-info36
2 files changed, 30 insertions, 8 deletions
diff --git a/src/lib/Options.py b/src/lib/Options.py
index 2cdc5fcae..b497c138f 100644
--- a/src/lib/Options.py
+++ b/src/lib/Options.py
@@ -220,6 +220,8 @@ CLIENT_EXTRA_DISPLAY = Option('enable extra entry output',
default=False, cmd='-e', )
CLIENT_PARANOID = Option('make automatic backups of config files',
default=False, cmd='-P', )
+CORE_PROFILE = Option('profile server core',
+ default=False, cmd='-p', )
CLIENT_AGENT = Option('run in agent (continuous) mode, wait for reconfigure command from server', default=False, cmd='-A', )
CLIENT_DRIVERS = Option('Specify tool driver set', cmd='-D',
cf=('client', 'drivers'),
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