summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-03 10:10:52 +0200
committerimarom <imarom@cisco.com>2015-11-03 10:10:52 +0200
commitc2928039f199d3cef6d130201cf825d5b6b67937 (patch)
treeedf7dec90f6f1c13f27d5d5b21843ee5ffe58789 /scripts/automation
parent3fb4e4c130da10e58af07e1f783f093515e90f96 (diff)
fields for specific ports on the status screen
Diffstat (limited to 'scripts/automation')
-rw-r--r--scripts/automation/trex_control_plane/client/trex_async_client.py40
-rw-r--r--scripts/automation/trex_control_plane/console/trex_status.py44
2 files changed, 47 insertions, 37 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_async_client.py b/scripts/automation/trex_control_plane/client/trex_async_client.py
index 1ce10288..4c17603d 100644
--- a/scripts/automation/trex_control_plane/client/trex_async_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_async_client.py
@@ -25,6 +25,15 @@ class TrexAsyncStats(object):
self.current = {}
self.last_update_ts = datetime.datetime.now()
+ def __format_num (self, size, suffix = ""):
+
+ for unit in ['','K','M','G','T','P']:
+ if abs(size) < 1000.0:
+ return "%3.2f %s%s" % (size, unit, suffix)
+ size /= 1000.0
+
+ return "NaN"
+
def update (self, snapshot):
#update
@@ -36,18 +45,25 @@ class TrexAsyncStats(object):
self.ref_point = self.current
- def get (self, field):
+ def get (self, field, format = False, suffix = ""):
if not field in self.current:
- return 0
+ return "N/A"
- return self.current[field]
+ if not format:
+ return self.current[field]
+ else:
+ return self.__format_num(self.current[field], suffix)
- def get_rel (self, field):
+
+ def get_rel (self, field, format = False, suffix = ""):
if not field in self.current:
- return 0
+ return "N/A"
- return self.current[field] - self.ref_point[field]
+ if not format:
+ return (self.current[field] - self.ref_point[field])
+ else:
+ return self.__format_num(self.current[field] - self.ref_point[field], suffix)
# return true if new data has arrived in the past 2 seconds
@@ -80,10 +96,10 @@ class TrexAsyncStatsManager():
def get_port_stats (self, port_id):
- if not port_id in self.port_stats:
+ if not str(port_id) in self.port_stats:
return None
- return self.port_stats[port_id]
+ return self.port_stats[str(port_id)]
def update (self, snapshot):
@@ -103,14 +119,16 @@ class TrexAsyncStatsManager():
for key, value in snapshot.iteritems():
# match a pattern of ports
- m = re.search('.*\-([0-8])', key)
+ m = re.search('(.*)\-([0-8])', key)
if m:
- port_id = m.group(1)
+
+ port_id = m.group(2)
+ field_name = m.group(1)
if not port_id in port_stats:
port_stats[port_id] = {}
- port_stats[port_id][key] = value
+ port_stats[port_id][field_name] = value
else:
# no port match - general stats
diff --git a/scripts/automation/trex_control_plane/console/trex_status.py b/scripts/automation/trex_control_plane/console/trex_status.py
index 4e73e0bb..ac8e7411 100644
--- a/scripts/automation/trex_control_plane/console/trex_status.py
+++ b/scripts/automation/trex_control_plane/console/trex_status.py
@@ -18,15 +18,6 @@ def percentage (a, total):
x = int ((float(a) / total) * 100)
return str(x) + "%"
-# simple float to human readable
-def float_to_human_readable (size, suffix = "bps"):
- for unit in ['','K','M','G','T']:
- if abs(size) < 1000.0:
- return "%3.2f %s%s" % (size, unit, suffix)
- size /= 1000.0
- return "NaN"
-
-
################### panels #################
# panel object
@@ -37,6 +28,8 @@ class TrexStatusPanel(object):
self.log = status_obj.log
self.stateless_client = status_obj.stateless_client
+
+ self.stats = status_obj.stats
self.general_stats = status_obj.general_stats
self.h = h
@@ -120,17 +113,17 @@ class GeneralInfoPanel(TrexStatusPanel):
self.getwin().addstr(3, 2, "{:<30} {:0.2f} %".format("CPU util.:", self.general_stats.get("m_cpu_util")))
self.getwin().addstr(5, 2, "{:<30} {:} / {:}".format("Total Tx. rate:",
- float_to_human_readable(self.general_stats.get("m_tx_bps")),
- float_to_human_readable(self.general_stats.get("m_tx_pps"), suffix = "pps")))
+ self.general_stats.get("m_tx_bps", format = True, suffix = "bps"),
+ self.general_stats.get("m_tx_pps", format = True, suffix = "pps")))
# missing RX field
#self.getwin().addstr(5, 2, "{:<30} {:} / {:}".format("Total Rx. rate:",
- # float_to_human_readable(self.general_stats.get("m_rx_bps")),
- # float_to_human_readable(self.general_stats.get("m_rx_pps"), suffix = "pps")))
+ # self.general_stats.get("m_rx_bps"),
+ # self.general_stats.get("m_rx_pps"), suffix = "pps"))
self.getwin().addstr(7, 2, "{:<30} {:} / {:}".format("Total Tx:",
- float_to_human_readable(self.general_stats.get_rel("m_total_tx_bytes"), suffix = "B"),
- float_to_human_readable(self.general_stats.get_rel("m_total_tx_pkts"), suffix = "pkts")))
+ self.general_stats.get_rel("m_total_tx_bytes", format = True, suffix = "B"),
+ self.general_stats.get_rel("m_total_tx_pkts", format = True, suffix = "pkts")))
# all ports stats
class PortsStatsPanel(TrexStatusPanel):
@@ -142,7 +135,6 @@ class PortsStatsPanel(TrexStatusPanel):
def draw (self):
self.clear()
- return
owned_ports = self.status_obj.owned_ports
if not owned_ports:
@@ -153,23 +145,22 @@ class PortsStatsPanel(TrexStatusPanel):
self.getwin().addstr(3, 2, "{:^15} {:^15} {:^15} {:^15} {:^15} {:^15} {:^15}".format(
"Port ID", "Tx [pps]", "Tx [bps]", "Tx [bytes]", "Rx [pps]", "Rx [bps]", "Rx [bytes]"))
- # port loop
- self.status_obj.stats.query_sync()
+
for i, port_index in enumerate(owned_ports):
port_stats = self.status_obj.stats.get_port_stats(port_index)
if port_stats:
- self.getwin().addstr(5 + (i * 4), 2, "{:^15} {:^15,.2f} {:^15,.2f} {:^15,} {:^15,.2f} {:^15,.2f} {:^15,}".format(
+ self.getwin().addstr(5 + (i * 4), 2, "{:^15} {:^15} {:^15} {:^15} {:^15} {:^15} {:^15}".format(
"{0} ({1})".format(str(port_index), self.status_obj.server_sys_info["ports"][port_index]["speed"]),
- port_stats["tx_pps"],
- port_stats["tx_bps"],
- port_stats["total_tx_bytes"],
- port_stats["rx_pps"],
- port_stats["rx_bps"],
- port_stats["total_rx_bytes"]))
-
+ port_stats.get("m_total_tx_pps", format = True, suffix = "pps"),
+ port_stats.get("m_total_tx_bps", format = True, suffix = "bps"),
+ port_stats.get_rel("obytes", format = True, suffix = "B"),
+ port_stats.get("m_total_rx_pps", format = True, suffix = "pps"),
+ port_stats.get("m_total_rx_bps", format = True, suffix = "bps"),
+ port_stats.get_rel("ibytes", format = True, suffix = "B")))
+
else:
self.getwin().addstr(5 + (i * 4), 2, "{:^15} {:^15} {:^15} {:^15} {:^15} {:^15} {:^15}".format(
"{0} ({1})".format(str(port_index), self.status_obj.server_sys_info["ports"][port_index]["speed"]),
@@ -374,6 +365,7 @@ class TrexStatus():
self.log = TrexStatusLog()
self.cmds = TrexStatusCommands(self)
+ self.stats = stateless_client.get_stats_async()
self.general_stats = stateless_client.get_stats_async().get_general_stats()
# fetch server info