add logging to find hot spots for tuning

This commit is contained in:
Helmut Merz 2015-09-06 15:08:33 +02:00
parent b8f485d2d3
commit bd1f12ffa0
2 changed files with 13 additions and 9 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de # Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
""" """
Adapters and others classes for analyzing resources. Adapters and others classes for analyzing resources.
$Id$
""" """
from itertools import tee from itertools import tee
@ -41,6 +39,7 @@ from loops.resource import Resource
from loops.setup import addAndConfigureObject from loops.setup import addAndConfigureObject
from loops.type import TypeInterfaceSourceList from loops.type import TypeInterfaceSourceList
logger = getLogger('Classifier')
TypeInterfaceSourceList.typeInterfaces += (IClassifier,) TypeInterfaceSourceList.typeInterfaces += (IClassifier,)
@ -102,15 +101,15 @@ class Classifier(AdapterBase):
if resource not in resources: if resource not in resources:
concept.assignResource(resource, predicate) concept.assignResource(resource, predicate)
message = u'Assigning: %s %s %s' message = u'Assigning: %s %s %s'
self.log(message % (resource.title, predicate.title, concept.title), 5)
else: else:
message = u'Already assigned: %s %s %s' message = u'Already assigned: %s %s %s'
self.log(message % (resource.title, predicate.title, concept.title), 4) self.log(message % (resource.title, predicate.title, concept.title), 4)
def log(self, message, level=5): def log(self, message, level=5):
if level >= self.logLevel: if level >= self.logLevel:
#print 'Classifier %s:' % getName(self.context), message #print 'Classifier %s:' % getName(self.context), message
getLogger('Classifier').info( logger.info(u'%s: %s' % (getName(self.context), message))
u'%s: %s' % (getName(self.context), message))
class Extractor(object): class Extractor(object):

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de # Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -18,17 +18,19 @@
""" """
View class(es) for resource classifiers. View class(es) for resource classifiers.
$Id$
""" """
from logging import getLogger
from zope import interface, component from zope import interface, component
from zope.app.pagetemplate import ViewPageTemplateFile from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.traversing.api import getName
from loops.browser.concept import ConceptView from loops.browser.concept import ConceptView
from loops.common import adapted from loops.common import adapted
logger = getLogger('ClassifierView')
class ClassifierView(ConceptView): class ClassifierView(ConceptView):
@ -44,10 +46,12 @@ class ClassifierView(ConceptView):
if cta is not None: if cta is not None:
for r in collectResources(self.context): for r in collectResources(self.context):
cta.process(r) cta.process(r)
logger.info('Finished processing')
return True return True
def collectResources(concept, checkedConcepts=None, result=None): def collectResources(concept, checkedConcepts=None, result=None):
logger.info('Start collecting resources for %s' % getName(concept))
if result is None: if result is None:
result = [] result = []
if checkedConcepts is None: if checkedConcepts is None:
@ -59,4 +63,5 @@ def collectResources(concept, checkedConcepts=None, result=None):
if c not in checkedConcepts: if c not in checkedConcepts:
checkedConcepts.append(c) checkedConcepts.append(c)
collectResources(c, checkedConcepts, result) collectResources(c, checkedConcepts, result)
logger.info('Collected %s resources' % len(result))
return result return result