Bug 1310868 - Tie resource collection to lifetime of context manager; r?glandium
Both BuildMonitor and BuildOutputManager are doing similar things and
wrapping the build with forms of monitoring. These classes are only
used in the `mach build` command.
Since the BuildOutputManager takes an instance of BuildMonitor as an
argument and since BuildOutputManager behaves as a context manager,
it makes sense for BuildOutputManager to control the lifetime of
BuildMonitor's collection.
So, we teach BuildOutputManager's context manager to start the
BuildMonitor and ensure its resource collection is stopped when it
exits.
MozReview-Commit-ID: 3l9Hwz0Xe7o
--- a/python/mozbuild/mozbuild/controller/building.py
+++ b/python/mozbuild/mozbuild/controller/building.py
@@ -233,23 +233,26 @@ class BuildMonitor(MozbuildObject):
try:
warning = self._warnings_collector.process_line(line)
except:
pass
return BuildOutputResult(warning, False, True)
- def finish(self, record_usage=True):
- """Record the end of the build."""
- self.end_time = time.time()
-
+ def stop_resource_recording(self):
if self._resources_started:
self.resources.stop()
+ self._resources_started = False
+
+ def finish(self, record_usage=True):
+ """Record the end of the build."""
+ self.stop_resource_recording()
+ self.end_time = time.time()
self._finder_end_cpu = self._get_finder_cpu_usage()
self.elapsed = self.end_time - self.start_time
self.warnings_database.prune()
self.warnings_database.save_to_file(self._warnings_path)
if not record_usage:
return
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -225,16 +225,21 @@ class BuildOutputManager(LoggingMixin):
return self
def __exit__(self, exc_type, exc_value, traceback):
if self.footer:
self.footer.clear()
# Prevents the footer from being redrawn if logging occurs.
self._handler.footer = None
+ # Ensure the resource monitor is stopped because leaving it running
+ # could result in the process hanging on exit because the resource
+ # collection child process hasn't been told to stop.
+ self.monitor.stop_resource_recording()
+
def write_line(self, line):
if self.footer:
self.footer.clear()
print(line)
if self.footer:
self.footer.draw()