summaryrefslogtreecommitdiffstats
path: root/qtip
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-08-30 14:43:41 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-08-30 14:43:41 +0800
commit59cc506c563a12e0a11b12e7b3742fec25e1e0f3 (patch)
tree410ae9fe30db8277d6a81174c5011378b936d89a /qtip
parentb15b028f061858de71fc98459d562dd76e3aecfe (diff)
Add score calculation module for storperf
Change-Id: I469ee4d768e16a27c3bde660bc1029d5a3507b72 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip')
-rw-r--r--qtip/loader/qpi.py2
-rw-r--r--qtip/score.py59
2 files changed, 60 insertions, 1 deletions
diff --git a/qtip/loader/qpi.py b/qtip/loader/qpi.py
index 48f52e84..294fd2ff 100644
--- a/qtip/loader/qpi.py
+++ b/qtip/loader/qpi.py
@@ -24,7 +24,7 @@ class QPISpec(YamlFileLoader):
def __init__(self, name, paths=None):
super(QPISpec, self).__init__(name, paths=paths)
content = self.content
- self.formula = Formula(content[SpecProp.FORMULA])
+ self.formula = Formula(content.get(SpecProp.FORMULA, FormulaName.ARITHMETIC_MEAN))
self.sections = [Section(record, paths=paths)
for record in content[SpecProp.SECTIONS]]
diff --git a/qtip/score.py b/qtip/score.py
new file mode 100644
index 00000000..da391290
--- /dev/null
+++ b/qtip/score.py
@@ -0,0 +1,59 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Corp and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import json
+from os import path
+import re
+import yaml
+
+
+RESOURCE_ROOT = path.join(path.dirname(__file__), '..', 'resources')
+
+
+def normalize(score, base=2048):
+ """ Use 2048 as base score if the performance equals baseline """
+ return int(base * score)
+
+
+def storperf(report_file, qpi_spec=None, baseline_file=None):
+ if qpi_spec is None:
+ qpi_spec = path.join(RESOURCE_ROOT, 'QPI', 'storage.yaml')
+
+ with open(qpi_spec) as f:
+ # load QPI spec as base template for report
+ qpi_report = yaml.safe_load(f.read())
+
+ if baseline_file is None:
+ baseline_file = path.join(RESOURCE_ROOT, 'baselines', 'storage.json')
+
+ with open(baseline_file) as f:
+ baseline_report = json.load(f)
+ baseline_metrics = baseline_report['report']['metrics']
+
+ with open(report_file) as f:
+ storperf_report = json.load(f)
+ reported_metrics = storperf_report['report']['metrics']
+
+ sections = qpi_report['sections']
+ for section in sections:
+ section_regex = re.compile(section['regex'])
+ ignored_regex = re.compile('^_') # ignore metrics starting with '_"
+ valid_metrics = [k for k in reported_metrics
+ if section_regex.search(k) and not ignored_regex.search(k) and k in baseline_metrics and
+ reported_metrics[k] != 0 and baseline_metrics[k] != 0]
+ if len(valid_metrics) == 0:
+ raise Exception('No valid metrics found')
+
+ section['score'] = sum([reported_metrics[k] / baseline_metrics[k]
+ if not section.get('use_reciprocal', False)
+ else baseline_metrics[k] / reported_metrics[k]
+ for k in valid_metrics]) / len(valid_metrics)
+ qpi_report['score'] = normalize(sum([section['score'] for section in sections]) / len(sections))
+
+ return qpi_report