aboutsummaryrefslogtreecommitdiffstats
path: root/qtip/ansible_library
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-25 13:49:21 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-25 16:58:26 +0800
commit6463b6635a8094a0ddcf83605cd231ba46104f72 (patch)
tree4ec7c0381f4447f5462fb2cac556a473b4b3c36e /qtip/ansible_library
parentec63540ec6cd3e6310407826b99cf0b3327bdf02 (diff)
Add ssl aes metrics in qpi calculation
Change-Id: Id568aa3942849e105ca24892babff2acaec21121 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip/ansible_library')
-rw-r--r--qtip/ansible_library/plugins/action/calculate.py29
-rw-r--r--qtip/ansible_library/plugins/action/collect.py11
2 files changed, 30 insertions, 10 deletions
diff --git a/qtip/ansible_library/plugins/action/calculate.py b/qtip/ansible_library/plugins/action/calculate.py
index fade367f..01c80a02 100644
--- a/qtip/ansible_library/plugins/action/calculate.py
+++ b/qtip/ansible_library/plugins/action/calculate.py
@@ -9,12 +9,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import humanfriendly
+import numbers
from numpy import mean
import yaml
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display
+from qtip.util.export_to import export_to_file
+
+
display = Display()
@@ -33,11 +38,12 @@ class ActionModule(ActionBase):
spec = yaml.safe_load(stream)
metrics = self._task.args.get('metrics')
+ export_to = self._task.args.get('export_to')
- return calc_qpi(spec, metrics)
+ return calc_qpi(spec, metrics, export_to)
-def calc_qpi(qpi_spec, metrics):
+def calc_qpi(qpi_spec, metrics, dest=None):
display.vv("calculate QPI {}".format(qpi_spec['name']))
display.vvv("spec: {}".format(qpi_spec))
@@ -49,13 +55,19 @@ def calc_qpi(qpi_spec, metrics):
# TODO(yujunz): use formula in spec
standard_score = 2048
qpi_score = int(mean([r['result']['score'] for r in section_results]) * standard_score)
- return {
+
+ results = {
'spec': qpi_spec,
'score': qpi_score,
'section_results': section_results,
'metrics': metrics
}
+ if dest is not None:
+ export_to_file(results, dest)
+
+ return results
+
def calc_section(section_spec, metrics):
@@ -80,11 +92,18 @@ def calc_metric(metric_spec, metrics):
display.vvv("metrics: {}".format(metrics))
# TODO(yujunz): use formula in spec
- # TODO(yujunz): convert metric to float in collector
- workload_results = [{'name': w['name'], 'score': mean([float(m) for m in metrics[w['name']]]) / w['baseline']}
+ workload_results = [{'name': w['name'], 'score': calc_score(metrics[w['name']], w['baseline'])}
for w in metric_spec['workloads']]
metric_score = mean([r['score'] for r in workload_results])
return {
'score': metric_score,
'workload_results': workload_results
}
+
+
+def calc_score(metrics, baseline):
+ if not isinstance(baseline, numbers.Number):
+ baseline = humanfriendly.parse_size(baseline)
+
+ return mean([m if isinstance(m, numbers.Number) else humanfriendly.parse_size(m)
+ for m in metrics]) / baseline
diff --git a/qtip/ansible_library/plugins/action/collect.py b/qtip/ansible_library/plugins/action/collect.py
index e51b8072..c54cbe7d 100644
--- a/qtip/ansible_library/plugins/action/collect.py
+++ b/qtip/ansible_library/plugins/action/collect.py
@@ -10,11 +10,12 @@
##############################################################################
from collections import defaultdict
-import json
import re
from ansible.plugins.action import ActionBase
+from qtip.util.export_to import export_to_file
+
class ActionModule(ActionBase):
@@ -31,7 +32,7 @@ class ActionModule(ActionBase):
return collect(patterns, string, export_to)
-def collect(patterns, string, export_to=None):
+def collect(patterns, string, dest=None):
"""collect all named subgroups of the match into a list keyed by subgroup name
"""
captured = defaultdict(list)
@@ -44,7 +45,7 @@ def collect(patterns, string, export_to=None):
for (key, value) in match_obj.groupdict().items():
captured[key].append(value)
- if export_to is not None:
- with open(export_to, 'w+') as f:
- f.write(json.dumps(captured, indent=2))
+ if dest is not None:
+ export_to_file(captured, dest)
+
return captured