Skip to content

Commit

Permalink
output classes usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lausser committed Feb 6, 2024
1 parent 70b014a commit a28e58b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions coshsh/datainterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CoshshDatainterface(object):
class_file_ident_function = ""
my_type = ""

usage_numbers = {}

@classmethod
def init_class_factory(cls, classpath):
class_factory = []
Expand Down Expand Up @@ -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]))

3 changes: 3 additions & 0 deletions coshsh/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a28e58b

Please sign in to comment.