diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-03-09 16:27:24 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-03-09 16:27:24 +0000 |
commit | 96be3de87556d37f94d07eea726f6dd1a5b561b6 (patch) | |
tree | 65f4c5b79f459315f9fcab96c29c4f13a521a7ec /src/sbin | |
parent | 27e1b2cf031f6bcd58a3ebd74e5acf25f1ba2009 (diff) | |
download | bcfg2-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/sbin')
-rwxr-xr-x | src/sbin/bcfg2-info | 36 |
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 |