[Erp5-report] r45926 arnaud.fontaine - /erp5/trunk/utils/erp5.utils.benchmark/src/erp5/util...

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jun 20 19:08:28 CEST 2011


Author: arnaud.fontaine
Date: Mon Jun 20 19:08:27 2011
New Revision: 45926

URL: http://svn.erp5.org?rev=45926&view=rev
Log:
Allow to publish results into ERP5 test_result_module.

Modified:
    erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/benchmark.py
    erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/performance_tester.py

Modified: erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/benchmark.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/benchmark.py?rev=45926&r1=45925&r2=45926&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/benchmark.py [utf8] (original)
+++ erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/benchmark.py [utf8] Mon Jun 20 19:08:27 2011
@@ -168,7 +168,14 @@ import abc
 class BenchmarkResult(object):
   __metaclass__ = abc.ABCMeta
 
-  def __init__(self):
+  def __init__(self, argument_namespace, nb_users, user_index):
+    self._argument_namespace = argument_namespace
+    self._nb_users = nb_users
+    self._user_index = user_index
+
+    self._log_level = self._argument_namespace.enable_debug and \
+        logging.DEBUG or logging.INFO
+
     self._stat_list = []
     self._suite_idx = 0
     self._result_idx = 0
@@ -180,11 +187,10 @@ class BenchmarkResult(object):
     self.label_list = []
     self.logger = self._getLogger()
 
-  @abc.abstractmethod
   def _getLogger(self):
-    pass
+    logging.basicConfig(stream=self.log_file, level=self._log_level)
+    return logging.getLogger('erp5.utils.benchmark')
 
-  @abc.abstractmethod
   def __enter__(self):
     return self
 
@@ -241,32 +247,24 @@ class BenchmarkResult(object):
 
   @abc.abstractmethod
   def __exit__(self, exc_type, exc_value, traceback):
+    self.flush()
     return True
 
 class CSVBenchmarkResult(BenchmarkResult):
   def __init__(self, argument_namespace, nb_users, user_index):
-    self._argument_namespace = argument_namespace
-    self._nb_users = nb_users
-    self._user_index = user_index
-
     filename_prefix = self.getFilenamePrefix()
 
     self.result_filename = "%s.csv" % filename_prefix
     self.result_filename_path = os.path.join(
-      self._argument_namespace.report_directory, self.result_filename)
+      argument_namespace.report_directory, self.result_filename)
 
-    self.log_filename = "%s.log" % filename_prefix
-    self.log_filename_path = os.path.join(
-      self._argument_namespace.report_directory, self.log_filename)
-
-    super(CSVBenchmarkResult, self).__init__()
+    self._log_filename = "%s.log" % filename_prefix
+    self._log_filename_path = os.path.join(
+      argument_namespace.report_directory, self._log_filename)
 
-  def _getLogger(self):
-    logging.basicConfig(filename=self.log_filename_path, filemode='w',
-                        level=self._argument_namespace.enable_debug and \
-                          logging.DEBUG or logging.INFO)
+    self.log_file = open(self._log_filename_path, 'w')
 
-    return logging.getLogger('erp5.utils.benchmark')
+    super(CSVBenchmarkResult, self).__init__()
 
   def getFilenamePrefix(self):
     max_nb_users = isinstance(self._argument_namespace.users, int) and \
@@ -298,16 +296,54 @@ class CSVBenchmarkResult(BenchmarkResult
     super(CSVBenchmarkResult, self).flush()
 
   def __exit__(self, exc_type, exc_value, traceback):
-    self.flush()
+    super(CSVBenchmarkResult, self).__exit__(exc_type, exc_value, traceback)
     self._result_file.close()
 
     if exc_type:
-      msg = "An error occured, see: %s" % self.log_filename_path
+      msg = "An error occured, see: %s" % self._log_filename_path
       if isinstance(exc_type, StopIteration):
         raise StopIteration, msg
       else:
         raise RuntimeError, msg
 
+from cStringIO import StringIO
+
+import xmlrpclib
+
+class ERP5BenchmarkResult(BenchmarkResult):
+  def __init__(self, *args, **kwargs):
+    self.log_file = StringIO()
+    self._log_buffer_list = []
+
+    super(ERP5BenchmarkResult, self).__init__(*args, **kwargs)
+
+  def iterationFinished(self):
+    super(ERP5BenchmarkResult, self).iterationFinished()
+
+    # TODO: garbage?
+    self._log_buffer_list.append(self.log_file.getvalue())
+    self.log_file.seek(0)
+
+  def flush(self):
+    benchmark_result = xmlrpclib.ServerProxy(
+      self._argument_namespace.erp5_publish_url,
+      verbose=True,
+      allow_none=True)
+
+    benchmark_result.BenchmarkResult_addResultLineList(
+      self._argument_namespace.user_tuple[self._user_index][0],
+      self._argument_namespace.repeat,
+      self._nb_users,
+      self._argument_namespace.benchmark_suite_name_list,
+      self.getLabelList(),
+      self._all_result_list,
+      self._log_buffer_list)
+
+    super(ERP5BenchmarkResult, self).flush()
+
+  def __exit__(self, exc_type, exc_value, traceback):
+    super(ERP5BenchmarkResult, self).__exit__(exc_type, exc_value, traceback)
+
 import multiprocessing
 import csv
 import traceback
@@ -336,13 +372,13 @@ class BenchmarkProcess(multiprocessing.P
   def stopGracefully(self, *args, **kwargs):
     raise StopIteration, "Interrupted by user"
 
-  def getBrowser(self, log_filename_path):
+  def getBrowser(self, log_file):
     info_list = tuple(self._argument_namespace.url) + \
         tuple(self._argument_namespace.user_tuple[self._user_index])
 
     return Browser(*info_list,
                    is_debug=self._argument_namespace.enable_debug,
-                   log_filename=log_filename_path,
+                   log_file=log_file,
                    is_legacy_listbox=self._argument_namespace.is_legacy_listbox)
 
   def runBenchmarkSuiteList(self, result):
@@ -392,7 +428,7 @@ class BenchmarkProcess(multiprocessing.P
       signal.signal(signal.SIGTERM, self.stopGracefully)
 
     try:
-      self._browser = self.getBrowser(result_instance.log_filename_path)
+      self._browser = self.getBrowser(result_instance.log_file)
     except:
       self._logger.error(traceback.format_exc())
       raise

Modified: erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/performance_tester.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/performance_tester.py?rev=45926&r1=45925&r2=45926&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/performance_tester.py [utf8] (original)
+++ erp5/trunk/utils/erp5.utils.benchmark/src/erp5/utils/benchmark/performance_tester.py [utf8] Mon Jun 20 19:08:27 2011
@@ -32,6 +32,8 @@ import argparse
 import os
 import sys
 import multiprocessing
+import datetime
+import xmlrpclib
 
 from benchmark import ArgumentType, BenchmarkProcess
 
@@ -106,6 +108,15 @@ class PerformanceTester(object):
                         help='Index of the first user within userInfo '
                              '(default: 0)')
 
+    parser.add_argument('--erp5-publish-url',
+                        metavar='ERP5_PUBLISH_URL',
+                        help='ERP5 URL to publish the results to '
+                             '(default: disabled, thus writing to CSV files)')
+
+    parser.add_argument('--erp5-publish-project',
+                        metavar='ERP5_PUBLISH_PROJECT',
+                        help='ERP5 publish project')
+
     # Mandatory arguments
     parser.add_argument('url',
                         type=ArgumentType.ERP5UrlType,
@@ -132,6 +143,7 @@ class PerformanceTester(object):
       object_benchmark_suite_list.append(ArgumentType.objectFromModule(benchmark_suite,
                                                                        callable_object=True))
 
+    namespace.benchmark_suite_name_list = namespace.benchmark_suite_list
     namespace.benchmark_suite_list = object_benchmark_suite_list
 
     max_nb_users = isinstance(namespace.users, tuple) and namespace.users[1] or \
@@ -141,6 +153,11 @@ class PerformanceTester(object):
     if max_nb_users > len(namespace.user_tuple):
       raise argparse.ArgumentTypeError("Not enough users in the given file")
 
+    if (namespace.erp5_publish_url and not namespace.erp5_publish_project) or \
+       (not namespace.erp5_publish_url and namespace.erp5_publish_project):
+      raise argparse.ArgumentTypeError("Publish ERP5 URL and project must "
+                                       "be specified")
+
     return namespace
 
   @staticmethod
@@ -151,13 +168,41 @@ class PerformanceTester(object):
     return namespace
 
   def getResultClass(self):
-    from benchmark import CSVBenchmarkResult
-    return CSVBenchmarkResult
+    if self._argument_namespace.erp5_publish_url:
+      from benchmark import ERP5BenchmarkResult
+      return ERP5BenchmarkResult
+    else:
+      from benchmark import CSVBenchmarkResult
+      return CSVBenchmarkResult
+
+  def preRun(self):
+    if not self._argument_namespace.erp5_publish_url:
+      return
+
+    test_result_module = xmlrpclib.ServerProxy(
+      self._argument_namespace.erp5_publish_url, verbose=True, allow_none=True)
+
+    # TODO: range of users?
+    benchmark_result = test_result_module.TestResultModule_addBenchmarkResult(
+      '%d repeat with %d concurrent users' % (self._argument_namespace.repeat,
+                                              self._argument_namespace.users),
+      self._argument_namespace.erp5_publish_project,
+      datetime.datetime.now())
+
+    try:
+      benchmark_result_id = benchmark_result['id']
+    except:
+      raise RuntimeError, "Cannot create the benchmark result"
+
+    self._argument_namespace.erp5_publish_url += \
+        'test_result_module/%s' % benchmark_result_id
 
   def _run_constant(self, nb_users):
     process_list = []
     exit_msg_queue = multiprocessing.Queue(nb_users)
+
     result_class = self.getResultClass()
+    self.preRun()
 
     for user_index in range(nb_users):
       process = BenchmarkProcess(exit_msg_queue, result_class,



More information about the Erp5-report mailing list