Commit b5d386ef authored by Arnaud Fontaine's avatar Arnaud Fontaine

Implement use case statistics when running benchmarks.

An use case represents for example the process of creating one Sale
Order including generation of the related Sale Packing List.

It allows to record the number of use cases processed per benchmark
suite and the total time spent on these for each suite.
parent aba28bf1
......@@ -119,6 +119,11 @@ class BenchmarkProcess(multiprocessing.Process):
result.exitSuite(with_error)
try:
self._logger.info(str(result.getCurrentSuiteUseCaseStat()))
except:
pass
result.iterationFinished()
def run(self):
......
......@@ -90,6 +90,7 @@ class NothingFlushedException(Exception):
pass
import abc
import time
class BenchmarkResult(object):
__metaclass__ = abc.ABCMeta
......@@ -128,14 +129,21 @@ class BenchmarkResult(object):
return self
def enterSuite(self, name):
self._current_use_case_elapsed_time = time.time()
self._current_use_case_counter = 0
try:
self._current_suite_dict = self._all_suite_list[self._current_suite_index]
except IndexError:
self._current_suite_dict = {'name': name,
'all_result_list': [],
'stat_list': [],
# Number of expected results
'expected': -1}
self._current_suite_dict = {
'name': name,
'all_result_list': [],
'stat_list': [],
# Number of expected results
'expected': -1,
'all_use_case_result_list': [],
'use_case_stat': BenchmarkResultStatistic(name, 'Use cases/minutes')}
self._all_suite_list.append(self._current_suite_dict)
......@@ -145,7 +153,6 @@ class BenchmarkResult(object):
try:
result_statistic = \
self._current_suite_dict['stat_list'][len(self._current_result_list)]
except IndexError:
result_statistic = BenchmarkResultStatistic(
self._current_suite_dict['name'], label)
......@@ -155,6 +162,9 @@ class BenchmarkResult(object):
result_statistic.add(value)
self._current_result_list.append(value)
def incrementCurrentSuiteUseCase(self):
self._current_use_case_counter += 1
@property
def label_list(self):
if self._label_list:
......@@ -166,7 +176,10 @@ class BenchmarkResult(object):
if suite_dict['expected'] == -1:
return None
label_list.extend([ stat.full_label for stat in suite_dict['stat_list'] ])
suite_label_list = [ stat.full_label for stat in suite_dict['stat_list']]
suite_label_list.extend(('Use cases', 'Use cases seconds elapsed'))
label_list.extend(suite_label_list)
self._label_list = label_list
return label_list
......@@ -174,6 +187,9 @@ class BenchmarkResult(object):
def getCurrentSuiteStatList(self):
return self._current_suite_dict['stat_list']
def getCurrentSuiteUseCaseStat(self):
return self._current_suite_dict['use_case_stat']
@staticmethod
def _addResultWithError(result_list, expected_len):
missing_result_n = expected_len - len(result_list)
......@@ -181,12 +197,17 @@ class BenchmarkResult(object):
result_list.extend(missing_result_n * [-1])
def exitSuite(self, with_error=False):
elapsed_time = int(time.time() - self._current_use_case_elapsed_time)
if with_error:
if self._current_suite_dict['expected'] != -1:
self._addResultWithError(self._current_result_list,
self._current_suite_dict['expected'])
else:
if self._current_use_case_counter == 0:
self._current_use_case_counter = 1
if self._current_suite_dict['expected'] == -1:
self._current_suite_dict['expected'] = len(self._current_result_list)
......@@ -195,6 +216,13 @@ class BenchmarkResult(object):
self._addResultWithError(result_list,
self._current_suite_dict['expected'])
self._current_suite_dict['all_use_case_result_list'].append(
(self._current_use_case_counter, elapsed_time))
if self._current_use_case_counter != 0:
self._current_suite_dict['use_case_stat'].add(
self._current_use_case_counter / (elapsed_time / 60.0))
self._current_suite_dict['all_result_list'].append(self._current_result_list)
self._current_suite_index += 1
......@@ -210,12 +238,15 @@ class BenchmarkResult(object):
raise NothingFlushedException()
for index, result_list in enumerate(result_dict['all_result_list']):
result_list.extend(result_dict['all_use_case_result_list'][index])
try:
all_result_list[index].extend(result_list)
except IndexError:
all_result_list.append(result_list)
result_dict['all_result_list'] = []
result_dict['all_use_case_result_list'] = []
return all_result_list
......
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