diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 05a36c82..e2aef5a2 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -411,7 +411,7 @@ class CoreClient: else: emane_config = None - start = time.time() + start = time.perf_counter() response = self.client.start_session( self.session_id, nodes, @@ -425,7 +425,7 @@ class CoreClient: service_configs, file_configs, ) - process_time = time.time() - start + process_time = time.perf_counter() - start logging.debug("start session(%s), result: %s", self.session_id, response.result) self.app.statusbar.start_session_callback(process_time) @@ -439,9 +439,9 @@ class CoreClient: def stop_session(self, session_id=None): if not session_id: session_id = self.session_id - start = time.time() + start = time.perf_counter() response = self.client.stop_session(session_id) - process_time = time.time() - start + process_time = time.perf_counter() - start self.app.statusbar.stop_session_callback(process_time) logging.debug("stopped session(%s), result: %s", session_id, response.result) diff --git a/coretk/coretk/menuaction.py b/coretk/coretk/menuaction.py index d8dc89cb..1a64800c 100644 --- a/coretk/coretk/menuaction.py +++ b/coretk/coretk/menuaction.py @@ -33,10 +33,10 @@ class MenuAction: def cleanup_old_session(self, quitapp=False): logging.info("cleaning up old session") - start = time.time() + start = time.perf_counter() self.app.core.stop_session() self.app.core.delete_session() - process_time = time.time() - start + process_time = time.perf_counter() - start self.app.statusbar.stop_session_callback(process_time) if quitapp: self.app.quit() diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index a914d617..6a6747f1 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -660,7 +660,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): last_check = None last_stats = None while self._is_running(context): - now = time.time() + now = time.monotonic() stats = get_net_stats() # calculate average diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index 321306a2..009cb067 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -1710,7 +1710,7 @@ class CoreHandler(socketserver.BaseRequestHandler): event_type=event_type, name=name, data=fail_data + ";" + unknown_data, - time=str(time.time()), + time=str(time.monotonic()), ) self.session.broadcast_event(event_data) diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index fee2bde4..1a01bdaa 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -103,7 +103,7 @@ class Session: # TODO: should the default state be definition? self.state = EventTypes.NONE.value - self._state_time = time.time() + self._state_time = time.monotonic() self._state_file = os.path.join(self.session_dir, "state") # hooks handlers @@ -1030,7 +1030,7 @@ class Session: return self.state = state_value - self._state_time = time.time() + self._state_time = time.monotonic() logging.info("changing session(%s) to state %s", self.id, state_name) self.write_state(state_value) @@ -1038,7 +1038,7 @@ class Session: self.run_state_hooks(state_value) if send_event: - event_data = EventData(event_type=state_value, time=str(time.time())) + event_data = EventData(event_type=state_value, time=str(time.monotonic())) self.broadcast_event(event_data) def write_state(self, state): @@ -1821,7 +1821,7 @@ class Session: if not in runtime. """ if self.state == EventTypes.RUNTIME_STATE.value: - return time.time() - self._state_time + return time.monotonic() - self._state_time else: return 0.0 diff --git a/daemon/core/location/event.py b/daemon/core/location/event.py index 11e535d3..f930d9b7 100644 --- a/daemon/core/location/event.py +++ b/daemon/core/location/event.py @@ -145,7 +145,7 @@ class EventLoop: with self.lock: if not self.running or not self.queue: break - now = time.time() + now = time.monotonic() if self.queue[0].time > now: schedule = True break @@ -170,7 +170,7 @@ class EventLoop: raise ValueError("scheduling event while not running") if not self.queue: return - delay = self.queue[0].time - time.time() + delay = self.queue[0].time - time.monotonic() if self.timer: raise ValueError("timer was already set") self.timer = Timer(delay, self.__run_events) @@ -187,7 +187,7 @@ class EventLoop: if self.running: return self.running = True - self.start = time.time() + self.start = time.monotonic() for event in self.queue: event.time += self.start self.__schedule_event() @@ -225,7 +225,7 @@ class EventLoop: self.eventnum += 1 evtime = float(delaysec) if self.running: - evtime += time.time() + evtime += time.monotonic() event = Event(eventnum, evtime, func, *args, **kwds) if self.queue: diff --git a/daemon/core/location/mobility.py b/daemon/core/location/mobility.py index 6a796526..b3eb4884 100644 --- a/daemon/core/location/mobility.py +++ b/daemon/core/location/mobility.py @@ -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): diff --git a/daemon/core/nodes/network.py b/daemon/core/nodes/network.py index 6fe291dd..f0639649 100644 --- a/daemon/core/nodes/network.py +++ b/daemon/core/nodes/network.py @@ -57,7 +57,7 @@ class EbtablesQueue: :return: nothing """ with self.updatelock: - self.last_update_time[wlan] = time.time() + self.last_update_time[wlan] = time.monotonic() if self.doupdateloop: return @@ -108,9 +108,9 @@ class EbtablesQueue: :rtype: float """ try: - elapsed = time.time() - self.last_update_time[wlan] + elapsed = time.monotonic() - self.last_update_time[wlan] except KeyError: - self.last_update_time[wlan] = time.time() + self.last_update_time[wlan] = time.monotonic() elapsed = 0.0 return elapsed @@ -122,7 +122,7 @@ class EbtablesQueue: :param wlan: wlan entity :return: nothing """ - self.last_update_time[wlan] = time.time() + self.last_update_time[wlan] = time.monotonic() self.updates.remove(wlan) def updateloop(self): diff --git a/daemon/core/services/coreservices.py b/daemon/core/services/coreservices.py index 80168425..361061be 100644 --- a/daemon/core/services/coreservices.py +++ b/daemon/core/services/coreservices.py @@ -538,13 +538,13 @@ class CoreServices: time.sleep(service.validation_timer) # non-blocking, attempt to validate periodically, up to validation_timer time elif service.validation_mode == ServiceMode.NON_BLOCKING: - start = time.time() + start = time.monotonic() while True: status = self.validate_service(node, service) if not status: break - if time.time() - start > service.validation_timer: + if time.monotonic() - start > service.validation_timer: break time.sleep(service.validation_period) diff --git a/daemon/tests/test_grpc.py b/daemon/tests/test_grpc.py index 28005dbb..56523e81 100644 --- a/daemon/tests/test_grpc.py +++ b/daemon/tests/test_grpc.py @@ -1042,7 +1042,7 @@ class TestGrpc: client.events(session.id, handle_event) time.sleep(0.1) event = EventData( - event_type=EventTypes.RUNTIME_STATE.value, time=str(time.time()) + event_type=EventTypes.RUNTIME_STATE.value, time=str(time.monotonic()) ) session.broadcast_event(event) diff --git a/daemon/tests/test_gui.py b/daemon/tests/test_gui.py index c2a8c9fc..91324d08 100644 --- a/daemon/tests/test_gui.py +++ b/daemon/tests/test_gui.py @@ -523,7 +523,7 @@ class TestGui: MessageFlags.ADD.value, [ (EventTlvs.TYPE, EventTypes.SCHEDULED.value), - (EventTlvs.TIME, str(time.time() + 100)), + (EventTlvs.TIME, str(time.monotonic() + 100)), (EventTlvs.NODE, node.id), (EventTlvs.NAME, "event"), (EventTlvs.DATA, "data"),