summaryrefslogtreecommitdiffstats
path: root/src/lib/Component.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-05-14 02:59:27 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-05-14 02:59:27 +0000
commit65f9f83a1fe481c60d24ef187c424e991208008a (patch)
tree89382806a994d2ebb5056f16fb87feaf1ea26d97 /src/lib/Component.py
parent88f446708cf429818ed17b2460163e622d3ca91c (diff)
downloadbcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.tar.gz
bcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.tar.bz2
bcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.zip
Integrate server-side performance statistics infrastructure
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5225 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Component.py')
-rw-r--r--src/lib/Component.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py
index ee4e5a0c2..6ea788ba5 100644
--- a/src/lib/Component.py
+++ b/src/lib/Component.py
@@ -15,6 +15,7 @@ import urlparse
import xmlrpclib
import Bcfg2.Logger
+from Bcfg2.Statistics import Statistics
from Bcfg2.SSLServer import XMLRPCServer
class NoExposedMethod (Exception):
@@ -132,6 +133,7 @@ class Component (object):
self.statefile = kwargs.get("statefile", None)
self.logger = logging.getLogger("%s %s" % (self.implementation, self.name))
self.lock = threading.Lock()
+ self.instance_statistics = Statistics()
def do_tasks (self):
"""Perform automatic tasks for the component.
@@ -145,7 +147,10 @@ class Component (object):
if (time.time() - func.automatic_ts) > \
func.automatic_period:
if need_to_lock:
+ t1 = time.time()
self.lock.acquire()
+ t2 = time.time()
+ self.instance_statistics.add_value('component_lock', t2-t1)
try:
mt1 = time.time()
func()
@@ -157,6 +162,7 @@ class Component (object):
if need_to_lock:
self.lock.release()
+ self.instance_statistics.add_value(name, mt2-mt1)
func.__dict__['automatic_ts'] = time.time()
def _resolve_exposed_method (self, method_name):
@@ -207,6 +213,9 @@ class Component (object):
finally:
if need_to_lock:
self.lock.release()
+ self.instance_statistics.add_value('component_lock',
+ lock_done - lock_start)
+ self.instance_statistics.add_value(method, method_done - method_start)
return result
@exposed
@@ -239,3 +248,8 @@ class Component (object):
"""The implementation of the component."""
return self.implementation
get_implementation = exposed(get_implementation)
+
+ def get_statistics (self):
+ """Get current statistics about component execution"""
+ return self.instance_statistics.display()
+ get_statistics = exposed(get_statistics)