From c585d631dde54732d04b2f3ee5661f15e7648719 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 10 Feb 2016 13:58:41 -0500 Subject: fixed two bugs: 1. deque race between two threads in the stats 2. max stream ID + 1 for port --- .../trex_control_plane/stl/trex_stl_lib/trex_stl_port.py | 2 +- .../trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index b1cf9ebc..de96f1ac 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -132,7 +132,7 @@ class Port(object): # TODO: handle syncing the streams into stream_db - self.next_available_id = long(rc.data()['max_stream_id']) + self.next_available_id = long(rc.data()['max_stream_id']) + 1 return self.ok() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 3f09e47c..183ae0c6 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -12,6 +12,7 @@ import time import re import math import copy +import threading GLOBAL_STATS = 'g' PORT_STATS = 'p' @@ -272,6 +273,7 @@ class CTRexStats(object): self.latest_stats = {} self.last_update_ts = time.time() self.history = deque(maxlen = 10) + self.lock = threading.Lock() def __getitem__(self, item): # override this to allow quick and clean access to fields @@ -313,7 +315,9 @@ class CTRexStats(object): def update(self, snapshot): # update self.latest_stats = snapshot - self.history.append(snapshot) + + with self.lock: + self.history.append(snapshot) diff_time = time.time() - self.last_update_ts @@ -365,7 +369,9 @@ class CTRexStats(object): if self.latest_stats[field] < percision: return 0 - field_samples = [sample[field] for sample in self.history] + # must lock, deque is not thread-safe for iteration + with self.lock: + field_samples = [sample[field] for sample in self.history] if use_raw: return calculate_diff_raw(field_samples) -- cgit 1.2.3-korg