From a28e58b95481fd846a26714ec06469ed37e3fdec Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Tue, 6 Feb 2024 16:58:14 +0100 Subject: [PATCH] output classes usage --- Changelog | 2 ++ coshsh/datainterface.py | 13 +++++++++++++ coshsh/generator.py | 3 +++ setup.py | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index c3fc808..93b54d7 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +* 2024-02-06 10.1 + output usage count of all classes * 2023-10-10 10.0.0.5 another bugfix in logging (affects only tests) * 2023-10-09 10.0.0.4 diff --git a/coshsh/datainterface.py b/coshsh/datainterface.py index 04b959b..57b378c 100644 --- a/coshsh/datainterface.py +++ b/coshsh/datainterface.py @@ -20,6 +20,8 @@ class CoshshDatainterface(object): class_file_ident_function = "" my_type = "" + usage_numbers = {} + @classmethod def init_class_factory(cls, classpath): class_factory = [] @@ -53,9 +55,20 @@ def get_class(cls, params={}): try: newcls = class_func(params) if newcls: + try: + cls.usage_numbers[path+"___"+newcls.__name__] += 1 + except Exception: + cls.usage_numbers[path+"___"+newcls.__name__] = 1 return newcls except Exception as exp: print(cls.__name__+".get_class exception", exp) logger.debug("found no matching class for this %s %s" % (cls.my_type, params)) return None + @classmethod + def dump_classes_usage(cls): + print("Classes usage overview") + print("count path__class") + for pmc in sorted(cls.usage_numbers.items(), key=lambda x: x[1]): + print("{:6d} {}".format(pmc[1], pmc[0])) + diff --git a/coshsh/generator.py b/coshsh/generator.py index dfecc01..921cecd 100644 --- a/coshsh/generator.py +++ b/coshsh/generator.py @@ -14,6 +14,7 @@ import getpass from tempfile import gettempdir import coshsh +from coshsh.datainterface import CoshshDatainterface from logging import INFO, DEBUG, getLogger logger = logging.getLogger('coshsh') @@ -123,6 +124,8 @@ def run(self): else: if recipe_completed: logger.info("recipe {} completed with {} problems".format(recipe.name, recipe.render_errors)) + if logger.level <= DEBUG: + CoshshDatainterface.dump_classes_usage() coshsh.util.restore_logging() def read_cookbook(self, cookbook_files, default_recipe, default_log_level, force, safe_output): diff --git a/setup.py b/setup.py index 89618e1..aa375d4 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def run(self): setup(name='coshsh', - version='10.0.0.5', + version='10.1', setup_requires=['wheel'], description='Coshsh - config generator for monitoring systems', long_description=open('README.md').read(),