From 3757099103ed1bf56f85ccf5bb861a331287cbbb Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Mon, 4 Jan 2016 23:31:18 +0200 Subject: updated stats --- .../trex_control_plane/common/trex_stats.py | 48 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index 9562f1f5..d77d3558 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -17,9 +17,9 @@ COMPACT = {GLOBAL_STATS, PORT_STATS} ExportableStats = namedtuple('ExportableStats', ['raw_data', 'text_table']) -class CTRexStatsGenerator(object): +class CTRexInfoGenerator(object): """ - This object is responsible of generating stats from objects maintained at + This object is responsible of generating stats and information from objects maintained at CTRexStatelessClient and the ports. """ @@ -39,6 +39,20 @@ class CTRexStatsGenerator(object): # ignore by returning empty object return {} + def generate_streams_info(self, port_id_list, stream_id_list): + relevant_ports = self.__get_relevant_ports(port_id_list) + + # TODO: change to dict comperhantion + return_data = {} + for port_id in relevant_ports: + return_data[port_id] = self._generate_single_port_streams_info(port_id, stream_id_list) + + return return_data + + @staticmethod + def _trim_packet_headers(headers_str): + pass + def _generate_global_stats(self): # stats_obj = self._async_stats.get_general_stats() stats_data = self._global_stats.generate_stats() @@ -131,6 +145,36 @@ class CTRexStatsGenerator(object): return {"port_status": ExportableStats(return_stats_data, stats_table)} + def _generate_single_port_streams_info(self, port_id, stream_id_list): + + return_stream_data = [] + port_status = port_obj.generate_port_status() + + for stream_id in sorted(stream_id_list): + return_stream_data.append(OrderedDict([("packet_type", self._trim_packet_headers()), + ("length", ), + ("mode",), + ("rate",), + ("next_stream",) + ])) + + per_field_stats = OrderedDict([("owner", []), + ("state", []), + ("--", []),]) + + + info_table = text_tables.TRexTextTable() + info_table.set_cols_align(["l"] + ["c"]*len(relevant_ports)) + info_table.set_cols_width([10] + [20] * len(relevant_ports)) + + info_table.add_rows([[k] + v + for k, v in per_field_status.iteritems()], + header=False) + info_table.header(["stream id", "packet type", "length", "mode", "rate", "next stream"]) + + return ExportableStats(return_stats_data, info_table) + + def __get_relevant_ports(self, port_id_list): # fetch owned ports ports = [port_obj -- cgit From 9fc980b8aa43cf53446eeeb5184f10a86476da28 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 7 Jan 2016 13:31:11 +0200 Subject: Working version of streams view in TRex console. TODO: sync when console crashes isn't integrated yet --- .../trex_control_plane/common/trex_stats.py | 54 ++++++++++------------ 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index 4c6173c4..f792ab9b 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -55,7 +55,6 @@ def calculate_diff_raw (samples): return total - class CTRexInfoGenerator(object): """ This object is responsible of generating stats and information from objects maintained at @@ -81,17 +80,16 @@ class CTRexInfoGenerator(object): def generate_streams_info(self, port_id_list, stream_id_list): relevant_ports = self.__get_relevant_ports(port_id_list) - # TODO: change to dict comperhantion return_data = {} - for port_id in relevant_ports: - return_data[port_id] = self._generate_single_port_streams_info(port_id, stream_id_list) + for port_obj in relevant_ports: + streams_data = self._generate_single_port_streams_info(port_obj, stream_id_list) + hdr_key = "Port {port}: {yaml_file}".format(port= port_obj.port_id, + yaml_file= streams_data.raw_data.get('referring_file', '')) + # TODO: test for other ports with same stream structure, and join them + return_data[hdr_key] = streams_data return return_data - @staticmethod - def _trim_packet_headers(headers_str): - pass - def _generate_global_stats(self): # stats_obj = self._async_stats.get_general_stats() stats_data = self._global_stats.generate_stats() @@ -184,34 +182,25 @@ class CTRexInfoGenerator(object): return {"port_status": ExportableStats(return_stats_data, stats_table)} - def _generate_single_port_streams_info(self, port_id, stream_id_list): + def _generate_single_port_streams_info(self, port_obj, stream_id_list): - return_stream_data = [] - port_status = port_obj.generate_port_status() - - for stream_id in sorted(stream_id_list): - return_stream_data.append(OrderedDict([("packet_type", self._trim_packet_headers()), - ("length", ), - ("mode",), - ("rate",), - ("next_stream",) - ])) - - per_field_stats = OrderedDict([("owner", []), - ("state", []), - ("--", []),]) + return_streams_data = port_obj.generate_loaded_streams_sum(stream_id_list) + # FORMAT VALUES ON DEMAND + for stream_id, stream_id_sum in return_streams_data['streams'].iteritems(): + stream_id_sum['rate_pps'] = CTRexStats.format_num(stream_id_sum['rate_pps'], suffix='pps') + stream_id_sum['packet_type'] = self._trim_packet_headers(stream_id_sum['packet_type'], 20) info_table = text_tables.TRexTextTable() - info_table.set_cols_align(["l"] + ["c"]*len(relevant_ports)) - info_table.set_cols_width([10] + [20] * len(relevant_ports)) + info_table.set_cols_align(["c"] + ["l"] + ["r"] + ["c"] + ["r"] + ["c"]) + info_table.set_cols_width([4] + [20] + [8] + [16] + [10] + [12]) - info_table.add_rows([[k] + v - for k, v in per_field_status.iteritems()], + info_table.add_rows([v.values() + for k, v in return_streams_data['streams'].iteritems()], header=False) - info_table.header(["stream id", "packet type", "length", "mode", "rate", "next stream"]) + info_table.header(["ID", "packet type", "length", "mode", "rate", "next stream"]) - return ExportableStats(return_stats_data, info_table) + return ExportableStats(return_streams_data, info_table) def __get_relevant_ports(self, port_id_list): @@ -231,6 +220,13 @@ class CTRexInfoGenerator(object): if key in dict_dest_ref: dict_dest_ref[key].append(val) + @staticmethod + def _trim_packet_headers(headers_str, trim_limit): + if len(headers_str) < trim_limit: + # do nothing + return headers_str + else: + return (headers_str[:trim_limit-3] + "...") -- cgit From 859a72101c94a26296efcc713882b472caf6ff8e Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Fri, 8 Jan 2016 13:55:24 +0200 Subject: minor updates --- scripts/automation/trex_control_plane/common/trex_stats.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index f792ab9b..aecf44b4 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -83,6 +83,8 @@ class CTRexInfoGenerator(object): return_data = {} for port_obj in relevant_ports: streams_data = self._generate_single_port_streams_info(port_obj, stream_id_list) + if not streams_data: + continue hdr_key = "Port {port}: {yaml_file}".format(port= port_obj.port_id, yaml_file= streams_data.raw_data.get('referring_file', '')) @@ -186,6 +188,10 @@ class CTRexInfoGenerator(object): return_streams_data = port_obj.generate_loaded_streams_sum(stream_id_list) + if not return_streams_data.get("streams"): + # we got no streams available + return None + # FORMAT VALUES ON DEMAND for stream_id, stream_id_sum in return_streams_data['streams'].iteritems(): stream_id_sum['rate_pps'] = CTRexStats.format_num(stream_id_sum['rate_pps'], suffix='pps') -- cgit