diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2016-11-29 17:47:42 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-12-07 10:42:22 +0000 |
commit | 083365143e844827599d9b0a78204b3a05df460c (patch) | |
tree | 5862275136012a1f932cee8644f67fbdcd2971c6 /bitbake/lib/bb/server/process.py | |
parent | 1b32c6ed025745cb06b7c28ca0fe9e416ce7abfa (diff) | |
download | poky-083365143e844827599d9b0a78204b3a05df460c.tar.gz |
bitbake: cooker process: fire heartbeat event at regular time intervals
The intended usage is for recording current system statistics from
/proc in buildstats.bbclass during a build and for improving the
BB_DISKMON_DIRS implementation.
All other existing hooks are less suitable because they trigger at
unpredictable rates: too often can be handled by doing rate-limiting
in the event handler, but not often enough (for example, when there is
only one long-running task) cannot because the handler does not get
called at all.
The implementation of the new heartbeat event hooks into the cooker
process event queue. The process already wakes up every 0.1s, which is
often enough for the intentionally coarse 1s delay between
heartbeats. That value was chosen to keep the overhead low while still
being frequent enough for the intended usage.
If necessary, BB_HEARTBEAT_EVENT can be set to a float specifying
the delay in seconds between these heartbeat events.
(Bitbake rev: 7cf22ea057d28c54bd98dc1ab7a43402a29ff1f5)
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server/process.py')
-rw-r--r-- | bitbake/lib/bb/server/process.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 982fcf71c3..1654faf92b 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
@@ -92,6 +92,8 @@ class ProcessServer(Process, BaseImplServer): | |||
92 | self.event = EventAdapter(event_queue) | 92 | self.event = EventAdapter(event_queue) |
93 | self.featurelist = featurelist | 93 | self.featurelist = featurelist |
94 | self.quit = False | 94 | self.quit = False |
95 | self.heartbeat_seconds = 1 # default, BB_HEARTBEAT_EVENT will be checked once we have a datastore. | ||
96 | self.next_heartbeat = time.time() | ||
95 | 97 | ||
96 | self.quitin, self.quitout = Pipe() | 98 | self.quitin, self.quitout = Pipe() |
97 | self.event_handle = multiprocessing.Value("i") | 99 | self.event_handle = multiprocessing.Value("i") |
@@ -101,6 +103,14 @@ class ProcessServer(Process, BaseImplServer): | |||
101 | self.event_queue.put(event) | 103 | self.event_queue.put(event) |
102 | self.event_handle.value = bb.event.register_UIHhandler(self, True) | 104 | self.event_handle.value = bb.event.register_UIHhandler(self, True) |
103 | 105 | ||
106 | heartbeat_event = self.cooker.data.getVar('BB_HEARTBEAT_EVENT', True) | ||
107 | if heartbeat_event: | ||
108 | try: | ||
109 | self.heartbeat_seconds = float(heartbeat_event) | ||
110 | except: | ||
111 | # Throwing an exception here causes bitbake to hang. | ||
112 | # Just warn about the invalid setting and continue | ||
113 | bb.warn('Ignoring invalid BB_HEARTBEAT_EVENT=%s, must be a float specifying seconds.' % heartbeat_event) | ||
104 | bb.cooker.server_main(self.cooker, self.main) | 114 | bb.cooker.server_main(self.cooker, self.main) |
105 | 115 | ||
106 | def main(self): | 116 | def main(self): |
@@ -160,6 +170,21 @@ class ProcessServer(Process, BaseImplServer): | |||
160 | del self._idlefuns[function] | 170 | del self._idlefuns[function] |
161 | self.quit = True | 171 | self.quit = True |
162 | 172 | ||
173 | # Create new heartbeat event? | ||
174 | now = time.time() | ||
175 | if now >= self.next_heartbeat: | ||
176 | # We might have missed heartbeats. Just trigger once in | ||
177 | # that case and continue after the usual delay. | ||
178 | self.next_heartbeat += self.heartbeat_seconds | ||
179 | if self.next_heartbeat <= now: | ||
180 | self.next_heartbeat = now + self.heartbeat_seconds | ||
181 | heartbeat = bb.event.HeartbeatEvent(now) | ||
182 | bb.event.fire(heartbeat, self.cooker.data) | ||
183 | if nextsleep and now + nextsleep > self.next_heartbeat: | ||
184 | # Shorten timeout so that we we wake up in time for | ||
185 | # the heartbeat. | ||
186 | nextsleep = self.next_heartbeat - now | ||
187 | |||
163 | if nextsleep is not None: | 188 | if nextsleep is not None: |
164 | select.select(fds,[],[],nextsleep) | 189 | select.select(fds,[],[],nextsleep) |
165 | 190 | ||