From 1e53d240e75d3000d16e706fde5d288d2490afe4 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 29 Aug 2012 15:06:49 -0400 Subject: made bcfg2-admin perf work again --- src/lib/Bcfg2/Server/BuiltinCore.py | 3 ++- src/lib/Bcfg2/Server/CherryPyCore.py | 25 ++++++++++--------------- src/lib/Bcfg2/Server/Core.py | 7 +++++++ 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py index 0a3e740cb..b433595b9 100644 --- a/src/lib/Bcfg2/Server/BuiltinCore.py +++ b/src/lib/Bcfg2/Server/BuiltinCore.py @@ -55,7 +55,8 @@ class Core(BaseCore): try: result = method_func(*args) finally: - method_done = time.time() + self.instance_statistics.add_value(method, + time.time() - method_start) except xmlrpclib.Fault: raise except Exception: diff --git a/src/lib/Bcfg2/Server/CherryPyCore.py b/src/lib/Bcfg2/Server/CherryPyCore.py index 7fc73fd19..e6023173a 100644 --- a/src/lib/Bcfg2/Server/CherryPyCore.py +++ b/src/lib/Bcfg2/Server/CherryPyCore.py @@ -1,11 +1,11 @@ """ the core of the CherryPy-powered server """ import sys -import base64 +import time import atexit import cherrypy import Bcfg2.Options -from Bcfg2.Compat import urlparse, xmlrpclib +from Bcfg2.Compat import urlparse, xmlrpclib, b64decode from Bcfg2.Server.Core import BaseCore from cherrypy.lib import xmlrpcutil from cherrypy._cptools import ErrorTool @@ -44,19 +44,9 @@ class Core(BaseCore): except KeyError: self.critical_error("No authentication data presented") auth_type, auth_content = header.split() + auth_content = b64decode(auth_content) try: - # py3k compatibility - auth_content = base64.standard_b64decode(auth_content) - except TypeError: - auth_content = \ - base64.standard_b64decode(bytes(auth_content.encode('ascii'))) - try: - # py3k compatibility - try: - username, password = auth_content.split(":") - except TypeError: - username, pw = auth_content.split(bytes(":", encoding='utf-8')) - password = pw.decode('utf-8') + username, password = auth_content.split(":") except ValueError: username = auth_content password = "" @@ -86,7 +76,12 @@ class Core(BaseCore): except: raise Exception('method "%s" is not supported' % rpcmethod) - body = handler(*rpcparams, **params) + method_start = time.time() + try: + body = handler(*rpcparams, **params) + finally: + self.instance_statistics.add_value(rpcmethod, + time.time() - method_start) xmlrpcutil.respond(body, 'utf-8', True) return cherrypy.serving.response.body diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index dc29f45eb..4ff0d2b98 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -14,6 +14,7 @@ import Bcfg2.settings import Bcfg2.Server import Bcfg2.Logger import Bcfg2.Server.FileMonitor +from Bcfg2.Statistics import Statistics from Bcfg2.Compat import xmlrpclib, reduce from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError @@ -174,6 +175,8 @@ class BaseCore(object): self.fam_thread.start() self.fam.AddMonitor(self.cfile, self.setup) + self.instance_statistics = Statistics() + def plugins_by_type(self, base_cls): """Return a list of loaded plugins that match the passed type. @@ -638,3 +641,7 @@ class BaseCore(object): """Is the database configured and available""" return self._database_available + @exposed + def get_statistics(self, _): + """Get current statistics about component execution""" + return self.instance_statistics.display() -- cgit v1.2.3-1-g7c22