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 30EE6A0A0A; Thu, 25 Mar 2021 09:49:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29FC9140D24; Thu, 25 Mar 2021 09:49:27 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 5FC454067B for ; Thu, 25 Mar 2021 09:49:25 +0100 (CET) IronPort-SDR: BTqe1NG03AIQYqvo9p5A1wTHgrt5DpZyRt2s4Zm5zAkTHppGIlK9oN2IAkQipKCFh3yTLLBDq1 44yUtTNaRgvg== X-IronPort-AV: E=McAfee;i="6000,8403,9933"; a="276009517" X-IronPort-AV: E=Sophos;i="5.81,277,1610438400"; d="scan'208";a="276009517" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2021 01:49:25 -0700 IronPort-SDR: S9b60iXNivDcfOngThu1u+JaQ1gV3XxrucRUUdNdhtgjPJzyOG5PCRyi1LkrO8Pwyp9ec+GtzZ xAPCk9vLNksA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,277,1610438400"; d="scan'208";a="376759155" Received: from dpdk-moyufen06.sh.intel.com ([10.67.116.208]) by orsmga006.jf.intel.com with ESMTP; 25 Mar 2021 01:49:23 -0700 From: yufengmx To: dts@dpdk.org, lijuan.tu@intel.com Cc: yufengmx Date: Thu, 25 Mar 2021 16:42:02 +0800 Message-Id: <20210325084202.17856-14-yufengx.mo@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210325084202.17856-1-yufengx.mo@intel.com> References: <20210325084202.17856-1-yufengx.mo@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dts] [PATCH V2 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..378db7db 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 * 100, 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