diff options
author | Benjamin Schubert <contact@benschubert.me> | 2020-07-04 16:52:33 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-07-06 18:07:53 +0000 |
commit | 472e3d165df3f9866c0665d4f3ffa19f864d33a4 (patch) | |
tree | db03e12fc6f617545c5e0e9fc1fa0bc473227ad6 /src | |
parent | 3cb61cfee0fb7c66be1af9d19b3316f966ce3090 (diff) | |
download | buildstream-472e3d165df3f9866c0665d4f3ffa19f864d33a4.tar.gz |
_state.py: Only use a single place of truth for the start time
This moves all implementations of 'start_time' into a single place
for easier handling and removing roundtrips of notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/_frontend/app.py | 4 | ||||
-rw-r--r-- | src/buildstream/_frontend/status.py | 2 | ||||
-rw-r--r-- | src/buildstream/_scheduler/scheduler.py | 7 | ||||
-rw-r--r-- | src/buildstream/_state.py | 14 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 11 |
5 files changed, 19 insertions, 19 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py index e7831dac3..3160e8b1e 100644 --- a/src/buildstream/_frontend/app.py +++ b/src/buildstream/_frontend/app.py @@ -311,7 +311,7 @@ class App: # Print a nice summary if this is a session if session_name: - elapsed = self.stream.elapsed_time + elapsed = self._state.elapsed_time() if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member self._message(MessageType.WARN, session_name + " Terminated", elapsed=elapsed) @@ -339,7 +339,7 @@ class App: else: # No exceptions occurred, print session time and summary if session_name: - self._message(MessageType.SUCCESS, session_name, elapsed=self.stream.elapsed_time) + self._message(MessageType.SUCCESS, session_name, elapsed=self._state.elapsed_time()) if self._started: self._print_summary() diff --git a/src/buildstream/_frontend/status.py b/src/buildstream/_frontend/status.py index a3f0d8aa7..e0505b45b 100644 --- a/src/buildstream/_frontend/status.py +++ b/src/buildstream/_frontend/status.py @@ -109,7 +109,7 @@ class Status: if not self._term_caps: return - elapsed = self._stream.elapsed_time + elapsed = self._state.elapsed_time() self.clear() self._check_term_width() diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py index a7d3ff471..38d656623 100644 --- a/src/buildstream/_scheduler/scheduler.py +++ b/src/buildstream/_scheduler/scheduler.py @@ -58,7 +58,6 @@ class NotificationType(FastEnum): TICK = "tick" TERMINATE = "terminate" QUIT = "quit" - SCHED_START_TIME = "sched_start_time" RUNNING = "running" TERMINATED = "terminated" SUSPEND = "suspend" @@ -135,7 +134,6 @@ class Scheduler: # Private members # self._active_jobs = [] # Jobs currently being run in the scheduler - self._starttime = start_time # Initial application start time self._suspendtime = None # Session time compensation for suspended state self._queue_jobs = True # Whether we should continue to queue jobs self._state = state @@ -364,7 +362,7 @@ class Scheduler: self._active_jobs.append(job) job.start() - self._state.add_task(job.action_name, job.name, self._state.elapsed_time(start_time=self._starttime)) + self._state.add_task(job.action_name, job.name, self._state.elapsed_time()) # _sched_queue_jobs() # @@ -485,9 +483,8 @@ class Scheduler: job.resume() self.suspended = False # Notify that we're unsuspended + self._state.offset_start_time(datetime.datetime.now() - self._suspendtime) self._notify(Notification(NotificationType.SUSPENDED)) - self._starttime += datetime.datetime.now() - self._suspendtime - self._notify(Notification(NotificationType.SCHED_START_TIME, time=self._starttime)) self._suspendtime = None # _interrupt_event(): diff --git a/src/buildstream/_state.py b/src/buildstream/_state.py index ec4f895fe..b8479e2b9 100644 --- a/src/buildstream/_state.py +++ b/src/buildstream/_state.py @@ -354,6 +354,20 @@ class State: start_time = self._session_start or time_now return time_now - start_time + # offset_start_time() + # + # Update the 'start' time of the application by a given offset + # + # This allows modifying the time spent building when BuildStream + # gets paused then restarted, to give an accurate view of the real + # time spend building. + # + # Args: + # offset: the offset to add to the start time + # + def offset_start_time(self, offset: datetime.timedelta) -> None: + self._session_start += offset + # _Task # diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 277ea7394..fb0b2f6e1 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -90,7 +90,6 @@ class Stream: self._pipeline = None self._state = State(session_start) # Owned by Stream, used by Core to set state self._notification_queue = deque() - self._starttime = session_start # Synchronised with Scheduler's relative start time context.messenger.set_state(self._state) @@ -1081,14 +1080,6 @@ class Stream: def terminated(self): return self._scheduler_terminated - # elapsed_time - # - # Elapsed time since the session start - # - @property - def elapsed_time(self): - return self._state.elapsed_time(start_time=self._starttime) - # terminate() # # Terminate jobs @@ -1661,8 +1652,6 @@ class Stream: self._interrupt_callback() elif notification.notification_type == NotificationType.TICK: self._ticker_callback() - elif notification.notification_type == NotificationType.SCHED_START_TIME: - self._starttime = notification.time elif notification.notification_type == NotificationType.RUNNING: self._scheduler_running = not self._scheduler_running elif notification.notification_type == NotificationType.TERMINATED: |