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