From aea95cb8b1eef994fb714bb4f00c214347e53452 Mon Sep 17 00:00:00 2001 From: "wu.zhihui" Date: Sat, 11 Mar 2017 00:29:41 +0800 Subject: 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 (cherry picked from commit dc92e5ae19dd026bf6a14c1e0d2b9c50497845d5) --- qtip/collector/calculator.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 qtip/collector/calculator.py (limited to 'qtip/collector/calculator.py') 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 -- cgit 1.2.3-korg