Skip to content
Snippets Groups Projects
Unverified Commit a135f810 authored by Simon Désaulniers's avatar Simon Désaulniers
Browse files

benchmark: create function for displaying plot

parent 2da48557
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,21 @@ def display_plot(yvals, xvals=None, yformatter=None, display_time=3, **kwargs): ...@@ -70,6 +70,21 @@ def display_plot(yvals, xvals=None, yformatter=None, display_time=3, **kwargs):
plt.plot(yvals, **kwargs) plt.plot(yvals, **kwargs)
plt.pause(display_time) plt.pause(display_time)
def display_traffic_plot(ifname):
"""Displays the traffic plot for a given interface name.
@param ifname: Interface name.
@type ifname: string
"""
ydata = []
xdata = []
# warning: infinite loop
interval = 2
for rate in iftop_traffic_data(ifname, interval=interval):
ydata.append(rate)
xdata.append((xdata[-1] if len(xdata) > 0 else 0) + interval)
display_plot(ydata, xvals=xdata, yformatter=Kbit_format, color='blue')
def iftop_traffic_data(ifname, interval=2, rate_type='send_receive'): def iftop_traffic_data(ifname, interval=2, rate_type='send_receive'):
""" """
Generator (yields data) function collecting traffic data from iftop Generator (yields data) function collecting traffic data from iftop
...@@ -210,10 +225,10 @@ class DhtFeatureTest(FeatureTest): ...@@ -210,10 +225,10 @@ class DhtFeatureTest(FeatureTest):
def _dhtPut(self, producer, _hash, *values): def _dhtPut(self, producer, _hash, *values):
with FeatureTest.lock: with FeatureTest.lock:
for val in values: for val in values:
vstr = val.__str__()[:100] vstr = val.__str__()[:100]
DhtNetwork.log('[PUT]:', _hash.toString(), '->', vstr + ("..." if len(vstr) > 100 else "")) DhtNetwork.log('[PUT]:', _hash.toString(), '->', vstr + ("..." if len(vstr) > 100 else ""))
FeatureTest.done += 1 FeatureTest.done += 1
producer.put(_hash, val, DhtFeatureTest.putDoneCb) producer.put(_hash, val, DhtFeatureTest.putDoneCb)
while FeatureTest.done > 0: while FeatureTest.done > 0:
FeatureTest.lock.wait() FeatureTest.lock.wait()
...@@ -367,9 +382,10 @@ class PersistenceTest(DhtFeatureTest): ...@@ -367,9 +382,10 @@ class PersistenceTest(DhtFeatureTest):
# initial set of values # initial set of values
i = 0 i = 0
for h in hashes: for h in hashes:
self._dhtPut(bootstrap.front(), h, *[Value(v) for v in values]) # TODO: bloque dans le put??
print("at: ", i) self._dhtPut(bootstrap.front(), h, *[Value(v) for v in values])
i += 1 print("at: ", i)
i += 1
def normalBehavior(do, t, log=None): def normalBehavior(do, t, log=None):
nonlocal nr_values nonlocal nr_values
...@@ -410,14 +426,7 @@ class PersistenceTest(DhtFeatureTest): ...@@ -410,14 +426,7 @@ class PersistenceTest(DhtFeatureTest):
self._trigger_dp(trigger_nodes, h) self._trigger_dp(trigger_nodes, h)
if self._traffic_plot: if self._traffic_plot:
ydata = [] display_traffic_plot('br'+wb.ifname)
xdata = []
# warning: infinite loop
interval = 2
for rate in iftop_traffic_data("br"+wb.ifname, interval=interval):
ydata.append(rate)
xdata.append((xdata[-1] if len(xdata) > 0 else 0) + interval)
display_plot(ydata, xvals=xdata, yformatter=Kbit_format, color='blue')
else: else:
# blocks in matplotlib thread # blocks in matplotlib thread
while True: while True:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment