updated usage of time.time to time.monotonic or time.perf_counter due to time.time possibly rolling backwards

This commit is contained in:
Blake Harnden 2019-12-06 09:42:41 -08:00
parent b9bbf397c9
commit 45a23a6c14
11 changed files with 29 additions and 29 deletions

View file

@ -174,7 +174,7 @@ class MobilityManager(ModelManager):
event_type=event_type,
name=f"mobility:{model.name}",
data=data,
time=str(time.time()),
time=str(time.monotonic()),
)
self.session.broadcast_event(event_data)
@ -612,7 +612,7 @@ class WayPointMobility(WirelessModel):
if self.state != self.STATE_RUNNING:
return
t = self.lasttime
self.lasttime = time.time()
self.lasttime = time.monotonic()
now = self.lasttime - self.timezero
dt = self.lasttime - t
@ -664,7 +664,7 @@ class WayPointMobility(WirelessModel):
:return: nothing
"""
logging.info("running mobility scenario")
self.timezero = time.time()
self.timezero = time.monotonic()
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
self.movenodesinitial()
self.runround()
@ -844,7 +844,7 @@ class WayPointMobility(WirelessModel):
self.lasttime = 0
self.run()
elif laststate == self.STATE_PAUSED:
now = time.time()
now = time.monotonic()
self.timezero += now - self.lasttime
self.lasttime = now - (0.001 * self.refresh_ms)
self.runround()
@ -871,7 +871,7 @@ class WayPointMobility(WirelessModel):
:return: nothing
"""
self.state = self.STATE_PAUSED
self.lasttime = time.time()
self.lasttime = time.monotonic()
class Ns2ScriptedMobility(WayPointMobility):