diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2014-12-13 15:33:46 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2014-12-13 16:16:28 +0100 |
commit | 1ad55cc4e22aa3c2c1daf0d7f6a99558d3da60bf (patch) | |
tree | 231658fef0d17817194edca3c75f08caa10b7d35 | |
parent | 99eecfc8cc9238833a49f78af24c7aac882212de (diff) | |
download | bcfg2-1ad55cc4e22aa3c2c1daf0d7f6a99558d3da60bf.tar.gz bcfg2-1ad55cc4e22aa3c2c1daf0d7f6a99558d3da60bf.tar.bz2 bcfg2-1ad55cc4e22aa3c2c1daf0d7f6a99558d3da60bf.zip |
Server/Plugin/helpers: remove track_statistics
Bcfg2.Server.Statistics.track_statistics was identical.
-rw-r--r-- | doc/development/plugins.txt | 4 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 16 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugin/helpers.py | 36 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 2 |
4 files changed, 11 insertions, 47 deletions
diff --git a/doc/development/plugins.txt b/doc/development/plugins.txt index 5993c4e29..d292c9dd7 100644 --- a/doc/development/plugins.txt +++ b/doc/development/plugins.txt @@ -171,12 +171,12 @@ perf``. This data can be invaluable for locating bottlenecks or other performance issues. The simplest way to track statistics is to use the -:func:`Bcfg2.Server.Plugin.helpers.track_statistics` decorator to +:func:`Bcfg2.Server.Statistics.track_statistics` decorator to decorate functions that you would like to track execution times for: .. code-block:: python - from Bcfg2.Server.Plugin import track_statistics + from Bcfg2.Server.Statistics import track_statistics @track_statistics() def do_something(self, ...): diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index a6fe02c6b..03ab40343 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -22,7 +22,7 @@ from Bcfg2.Server.Cache import Cache from Bcfg2.Compat import xmlrpclib, wraps # pylint: disable=W0622 from Bcfg2.Server.Plugin.exceptions import * # pylint: disable=W0401,W0614 from Bcfg2.Server.Plugin.interfaces import * # pylint: disable=W0401,W0614 -from Bcfg2.Server.Plugin import track_statistics +from Bcfg2.Server.Statistics import track_statistics try: from django.core.exceptions import ImproperlyConfigured @@ -495,7 +495,7 @@ class Core(object): (self.__class__.__name__, hook), time.time() - start) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def validate_structures(self, metadata, data): """ Checks the data structures by calling the :func:`Bcfg2.Server.Plugin.interfaces.StructureValidator.validate_structures` @@ -522,7 +522,7 @@ class Core(object): self.logger.error("Plugin %s: unexpected structure validation " "failure" % plugin.name, exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def validate_goals(self, metadata, data): """ Checks that the config matches the goals enforced by :class:`Bcfg2.Server.Plugin.interfaces.GoalValidator` plugins @@ -548,7 +548,7 @@ class Core(object): self.logger.error("Plugin %s: unexpected goal validation " "failure" % plugin.name, exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def GetStructures(self, metadata): """ Get all structures (i.e., bundles) for the given client @@ -568,7 +568,7 @@ class Core(object): (metadata.hostname, ':'.join(missing))) return structures - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def BindStructures(self, structures, metadata, config): """ Given a list of structures (i.e. bundles), bind all the entries in them and add the structures to the config. @@ -589,7 +589,7 @@ class Core(object): except: self.logger.error("error in BindStructure", exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def BindStructure(self, structure, metadata): """ Bind all elements in a single structure (i.e., bundle). @@ -822,7 +822,7 @@ class Core(object): % plugin.name, exc_info=1) return result - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def check_acls(self, address, rmi): """ Check client IP address and metadata object against all :class:`Bcfg2.Server.Plugin.interfaces.ClientACLs` plugins. @@ -877,7 +877,7 @@ class Core(object): "%s" % (client, rmi, sys.exc_info()[1])) return False # failsafe - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def build_metadata(self, client_name): """ Build initial client metadata for a client diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py index 559612d1e..2aab231c6 100644 --- a/src/lib/Bcfg2/Server/Plugin/helpers.py +++ b/src/lib/Bcfg2/Server/Plugin/helpers.py @@ -3,7 +3,6 @@ import os import re import sys -import time import copy import glob import logging @@ -35,41 +34,6 @@ except ImportError: LOGGER = logging.getLogger(__name__) -class track_statistics(object): # pylint: disable=C0103 - """ Decorator that tracks execution time for the given - :class:`Plugin` method with :mod:`Bcfg2.Statistics` for reporting - via ``bcfg2-admin perf`` """ - - def __init__(self, name=None): - """ - :param name: The name under which statistics for this function - will be tracked. By default, the name will be - the name of the function concatenated with the - name of the class the function is a member of. - :type name: string - """ - # if this is None, it will be set later during __call_ - self.name = name - - def __call__(self, func): - if self.name is None: - self.name = func.__name__ - - @wraps(func) - def inner(obj, *args, **kwargs): - """ The decorated function """ - name = "%s:%s" % (obj.__class__.__name__, self.name) - - start = time.time() - try: - return func(obj, *args, **kwargs) - finally: - Bcfg2.Server.Statistics.stats.add_value(name, - time.time() - start) - - return inner - - def removecomment(stream): """ A Genshi filter that removes comments from the stream. This function is a generator. diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index f26ded4c5..b6e9f13eb 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -1231,7 +1231,7 @@ class YumSource(Source): self.provides[arch][prov] = list() self.provides[arch][prov].append(pkgname) - @Bcfg2.Server.Plugin.track_statistics() + @track_statistics() def parse_group(self, data): """ parse comps.xml.gz data """ for group in data.getchildren(): |