Commit 10cf6d6c authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix logger

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@45935 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2d1c91f2
...@@ -185,12 +185,15 @@ class BenchmarkResult(object): ...@@ -185,12 +185,15 @@ class BenchmarkResult(object):
self._current_suite_name = None self._current_suite_name = None
self._result_idx_checkpoint_list = [] self._result_idx_checkpoint_list = []
self.label_list = [] self.label_list = []
self.logger = self._getLogger() self._logger = None
def _getLogger(self): def getLogger(self):
if not self._logger:
logging.basicConfig(stream=self.log_file, level=self._log_level) logging.basicConfig(stream=self.log_file, level=self._log_level)
return logging.getLogger('erp5.utils.benchmark') return logging.getLogger('erp5.utils.benchmark')
return self._logger
def __enter__(self): def __enter__(self):
return self return self
...@@ -214,7 +217,7 @@ class BenchmarkResult(object): ...@@ -214,7 +217,7 @@ class BenchmarkResult(object):
if self._first_iteration: if self._first_iteration:
self.label_list = self.getLabelList() self.label_list = self.getLabelList()
self.logger.debug("RESULTS: %s" % self.result_list) self.getLogger().debug("RESULTS: %s" % self.result_list)
self.result_list = [] self.result_list = []
self._first_iteration = False self._first_iteration = False
self._suite_idx = 0 self._suite_idx = 0
...@@ -251,22 +254,22 @@ class BenchmarkResult(object): ...@@ -251,22 +254,22 @@ class BenchmarkResult(object):
return True return True
class CSVBenchmarkResult(BenchmarkResult): class CSVBenchmarkResult(BenchmarkResult):
def __init__(self, argument_namespace, nb_users, user_index): def __init__(self, *args, **kwargs):
filename_prefix = self.getFilenamePrefix() super(CSVBenchmarkResult, self).__init__(*args, **kwargs)
filename_prefix = self._getFilenamePrefix()
self.result_filename = "%s.csv" % filename_prefix self.result_filename = "%s.csv" % filename_prefix
self.result_filename_path = os.path.join( self.result_filename_path = os.path.join(
argument_namespace.report_directory, self.result_filename) self._argument_namespace.report_directory, self.result_filename)
self._log_filename = "%s.log" % filename_prefix self._log_filename = "%s.log" % filename_prefix
self._log_filename_path = os.path.join( self._log_filename_path = os.path.join(
argument_namespace.report_directory, self._log_filename) self._argument_namespace.report_directory, self._log_filename)
self.log_file = open(self._log_filename_path, 'w') self.log_file = open(self._log_filename_path, 'w')
super(CSVBenchmarkResult, self).__init__() def _getFilenamePrefix(self):
def getFilenamePrefix(self):
max_nb_users = isinstance(self._argument_namespace.users, int) and \ max_nb_users = isinstance(self._argument_namespace.users, int) and \
self._argument_namespace.users or self._argument_namespace.users[1] self._argument_namespace.users or self._argument_namespace.users[1]
...@@ -301,6 +304,7 @@ class CSVBenchmarkResult(BenchmarkResult): ...@@ -301,6 +304,7 @@ class CSVBenchmarkResult(BenchmarkResult):
if exc_type: if exc_type:
msg = "An error occured, see: %s" % self._log_filename_path msg = "An error occured, see: %s" % self._log_filename_path
self.getLogger().error("%s: %s\n%s" % (exc_type, exc_value, traceback))
if isinstance(exc_type, StopIteration): if isinstance(exc_type, StopIteration):
raise StopIteration, msg raise StopIteration, msg
else: else:
...@@ -422,7 +426,7 @@ class BenchmarkProcess(multiprocessing.Process): ...@@ -422,7 +426,7 @@ class BenchmarkProcess(multiprocessing.Process):
self._nb_users, self._nb_users,
self._user_index) self._user_index)
self._logger = result_instance.logger self._logger = result_instance.getLogger()
if self._argument_namespace.repeat != -1: if self._argument_namespace.repeat != -1:
signal.signal(signal.SIGTERM, self.stopGracefully) signal.signal(signal.SIGTERM, self.stopGracefully)
......
...@@ -274,9 +274,6 @@ class PerformanceTester(object): ...@@ -274,9 +274,6 @@ class PerformanceTester(object):
error_message_set, exit_status = self._run_constant( error_message_set, exit_status = self._run_constant(
self._argument_namespace.users) self._argument_namespace.users)
import pdb
pdb.Pdb(stdin=open('/dev/stdin', 'r+'), stdout=open('/dev/stdout', 'r+')).set_trace()
self.postRun(error_message_set) self.postRun(error_message_set)
return error_message_set, exit_status return error_message_set, exit_status
......
...@@ -34,7 +34,7 @@ class CSVScalabilityBenchmarkResult(CSVBenchmarkResult): ...@@ -34,7 +34,7 @@ class CSVScalabilityBenchmarkResult(CSVBenchmarkResult):
def flush(self): def flush(self):
super(CSVScalabilityBenchmarkResult, self).flush() super(CSVScalabilityBenchmarkResult, self).flush()
self._argument_namespace.notify_method(self._result_filename, self._argument_namespace.notify_method(self._result_filename,
self._result.tell()) self._result_file.tell())
from erp5.utils.benchmark.performance_tester import PerformanceTester from erp5.utils.benchmark.performance_tester import PerformanceTester
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment