summaryrefslogtreecommitdiffstats
path: root/qtip/collector/calculator.py
diff options
context:
space:
mode:
authorwu.zhihui <wu.zhihui1@zte.com.cn>2017-03-11 00:29:41 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-03-14 14:36:48 +0000
commitaea95cb8b1eef994fb714bb4f00c214347e53452 (patch)
treed4ff8c6256728238da30876f7340f9ab5b58b2de /qtip/collector/calculator.py
parent89743ab8134e54fe606310e3bf5c65ebab93c62a (diff)
parse benchmark result from logfile
- Put all the regex rules in regex.yaml. - According to benchmark name, we can find related regexes. Change-Id: Ic15bd1c77b525be3751011fa94d582da077b0345 Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn> (cherry picked from commit dc92e5ae19dd026bf6a14c1e0d2b9c50497845d5)
Diffstat (limited to 'qtip/collector/calculator.py')
-rw-r--r--qtip/collector/calculator.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/qtip/collector/calculator.py b/qtip/collector/calculator.py
new file mode 100644
index 00000000..c3d961b3
--- /dev/null
+++ b/qtip/collector/calculator.py
@@ -0,0 +1,38 @@
+##############################################################################
+# 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
+##############################################################################
+
+from operator import add
+
+from qtip.util.logger import QtipLogger
+
+logger = QtipLogger('calculator').get
+
+
+def dpi_calculator(samples):
+ try:
+ float_pps = map(lambda x: float(x), samples['pps'])
+ float_bps = map(lambda x: float(x), samples['bps'])
+ sum_dpi_pps = reduce(add,
+ map(lambda x: x / 1000 if x > 100 else x, float_pps))
+ sum_dpi_bps = reduce(add,
+ map(lambda x: x / 1000 if x > 100 else x, float_bps))
+
+ return {'pps': round(sum_dpi_pps / 10, 3), 'bps': round(sum_dpi_bps / 10, 3)}
+ except Exception as error:
+ logger.error(error)
+ return {'pps': None, 'bps': None}
+
+
+def calculate_cpu_usage(cpu_idle):
+ try:
+ cpu_usage = round((100.0 - float(cpu_idle)), 3)
+ return '{0}%'.format(str(cpu_usage))
+ except Exception, error:
+ logger.error(error)
+ return None