From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CEE39A034F; Tue, 30 Mar 2021 09:12:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CA13D140DCD; Tue, 30 Mar 2021 09:12:48 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 5FF36140DCD for ; Tue, 30 Mar 2021 09:12:47 +0200 (CEST) IronPort-SDR: pJ6SZSxNrBujXK/LD5Wyih3G0M5O+NZpV/gbCpkti63FIbW8KSsJDDNk+w2ZpbTQcy1sPi1K6o U6RCqs6yzzuQ== X-IronPort-AV: E=McAfee;i="6000,8403,9938"; a="191805914" X-IronPort-AV: E=Sophos;i="5.81,290,1610438400"; d="scan'208";a="191805914" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2021 00:12:47 -0700 IronPort-SDR: J8B27wQiPsXOr+lOepYP88Y90NLbBCgWWeJu5FWI+mg6XqxQoza08ZB8NRt0cswfnDhovudUXV rkG6L0c2PPcQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,290,1610438400"; d="scan'208";a="411473248" Received: from dpdk-moyufen06.sh.intel.com ([10.67.116.208]) by fmsmga008.fm.intel.com with ESMTP; 30 Mar 2021 00:12:45 -0700 From: yufengmx To: dts@dpdk.org, lijuan.tu@intel.com Cc: yufengmx Date: Tue, 30 Mar 2021 15:05:25 +0800 Message-Id: <20210330070525.5056-14-yufengx.mo@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210330070525.5056-1-yufengx.mo@intel.com> References: <20210330070525.5056-1-yufengx.mo@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dts] [PATCH V4 13/13] tests/perf_test_base: script X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" stage 2 demand as below #. accepted_tolerance in [test suit].cfg are changed to percentage, if not set, it will be set to 2% by default. #. delta in json are chagned to percentage. #. add expected throughput in json. #. expected_throughput will be forced to NA if it not set. #. add new conf throughput_stat_sample_interval in conf/.cfg, which indicates interval of getting throughput statistics in second, e.g. throughput_stat_sample_interval = 10 if not set, it will be set to 5 seconds by default. #. collect better statistics , get multiple throughput statistics during the test run, and compute the average as the final results. Every seconds get throughput once, so it gets multiple throughput statistics during the test run, remove the max and the min, then compute the average of the left as the final throughput. Signed-off-by: yufengmx --- tests/perf_test_base.py | 84 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/tests/perf_test_base.py b/tests/perf_test_base.py index 4b76e6b1..ba18560c 100644 --- a/tests/perf_test_base.py +++ b/tests/perf_test_base.py @@ -38,6 +38,7 @@ import time import traceback import texttable import json +import numpy as np from enum import Enum, unique from pprint import pformat from itertools import product @@ -109,6 +110,12 @@ class STREAM_TYPE(Enum): RAW = 'RAW' +@unique +class STAT_ALGORITHM(Enum): + ONE = "one" + MEAN = "mean" + + HEADER_SIZE = { 'ether': 18, 'ipv4': 20, @@ -449,6 +456,37 @@ class PerfTestBase(object): time.sleep(self.__traffic_stop_wait_time) return result + def __throughput_set_traffic_opt(self, duration): + option = { + 'method': 'throughput', + 'duration': duration, + 'interval': self.__throughput_stat_sample_interval, + } + return option + + def __throughput_calculate_result(self, result): + if self.__stat_algorithm is STAT_ALGORITHM.ONE: + return result + + if not result or len(result) <= 0: + msg = "failed to get throughput stat" + self.logger.error(msg) + return (0.0, 0.0) + + result = sorted(result) + if self.__stat_algorithm is STAT_ALGORITHM.MEAN: + result = result[1:-1] if len(result) >= 5 else result + bps, pps = [], [] + for v1, v2 in result: + bps.append(v1), pps.append(v2) + ret_stat = round(np.array(bps).mean(), 1), round(np.array(pps).mean(), 1) + else: + msg = f"current not support algorithm <{self.__stat_algorithm}>" + self.logger.warning(msg) + ret_stat = (0.0, 0.0) + + return ret_stat + def __throughput(self, l3_proto, mode, frame_size): """ measure __throughput according to Layer-3 Protocol and Lookup Mode @@ -464,11 +502,11 @@ class PerfTestBase(object): option = { 'stream': streams, 'rate': 100, - 'traffic_opt': { - 'method': 'throughput', - 'duration': duration, }} + 'traffic_opt': self.__throughput_set_traffic_opt(duration), + } # run traffic result = self.__send_packets_by_pktgen(option) + result = self.__throughput_calculate_result(result) # statistics result _, pps = result self.verify(pps > 0, "No traffic detected") @@ -871,7 +909,8 @@ class PerfTestBase(object): def __json_throughput(self, value): return {"unit": "Mpps", "name": "Throughput", "value": round(value[0], 3), - "delta": round(value[1], 3), + "delta": value[1], + "expected": value[2], } def __json_rate_percent(self, value): @@ -987,12 +1026,16 @@ class PerfTestBase(object): expected, pps, round(gap, 2)) self.logger.error(msg) else: - expected = pps + expected = None msg = ('{0} {1} expected throughput value is not set, ' 'ignore check').format(config, frame_size) self.logger.warning(msg) status = 'pass' - js_results.append([status, [pps, pps - expected], percentage, config, frame_size]) + js_results.append([ + status, + [pps, (str(round((pps - expected)/expected, 3))) if expected is not None else "N/A", + round(expected, 3) if expected is not None else "N/A"], + percentage, config, frame_size]) # save data with json format self.__save_throughput_result(self.__cur_case, js_results) # display result table @@ -1394,11 +1437,40 @@ class PerfTestBase(object): self.__valports = port_list return port_list + @property + def __stat_algorithm(self): + algorithm_type = get_enum_name( + self.__test_content.get('stat_algorithm') or 'one', STAT_ALGORITHM) + return algorithm_type + + @property + def __throughput_stat_sample_interval(self): + if self.__stat_algorithm is STAT_ALGORITHM.ONE: + return None + else: + return self.__test_content.get('throughput_stat_sample_interval') or 5 + + def __parse_accepted_tolerance(self): + tolerance = self.__test_content.get('accepted_tolerance') + def get_num(value): + pat = "(\d+\.?\d?)" + result = re.findall(pat, value) + return result[0] if result else '2.0' + + if isinstance(tolerance, int): + _tolerance = float(tolerance) + elif isinstance(tolerance, str): + _tolerance = float(tolerance if tolerance.isdigit() else get_num(tolerance)) + else: + _tolerance = None + self.__test_content['accepted_tolerance'] = float(_tolerance or 2.0) + def perf_preset_test_environment(self, test_content): # if user set port list in cfg file, use port_list = self.__preset_port_list(test_content) # get test content self.__test_content = self.__get_test_content_from_cfg(test_content) + self.__parse_accepted_tolerance() # prepare target source code application self.__preset_compilation() # set up testing environment -- 2.21.0