[jhbuild] Add new nice_build key, implement it



commit 0e453d9470ad8c3fa4e57ff02d4b93881647c715
Author: Colin Walters <walters verbum org>
Date:   Tue Jun 21 08:43:05 2011 -0400

    Add new nice_build key, implement it
    
    This improves desktop interactivity, especially with high make -j
    values.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653102

 doc/C/jhbuild.xml                |   14 ++++++++++++++
 jhbuild/config.py                |    2 +-
 jhbuild/defaults.jhbuildrc       |    5 +++++
 jhbuild/frontends/autobuild.py   |    2 ++
 jhbuild/frontends/buildscript.py |   19 +++++++++++++++++++
 jhbuild/frontends/gtkui.py       |    2 ++
 jhbuild/frontends/terminal.py    |    4 +++-
 jhbuild/frontends/tinderbox.py   |    2 ++
 8 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/doc/C/jhbuild.xml b/doc/C/jhbuild.xml
index 8481258..4f081c4 100644
--- a/doc/C/jhbuild.xml
+++ b/doc/C/jhbuild.xml
@@ -1906,6 +1906,20 @@ libgnomecanvas is missing branch definition for gnome-2-20
           </listitem>
         </varlistentry>
         <varlistentry>
+          <term id="cfg-nice-build">
+            <varname>nice_build</varname>
+          </term>
+          <listitem>
+            <simpara>
+	      Run builds under the <constant>SCHED_IDLE</constant>
+	      priority on Linux, <command>nice</command> on other
+	      Unix.  This can dramatically improve desktop
+	      interactivity for parallel builds while having only a
+	      negligible impact on build throughput.
+            </simpara>
+          </listitem>
+        </varlistentry>
+        <varlistentry>
           <term id="cfg-nobuild">
             <varname>nobuild</varname>
           </term>
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 7c9d39b..69dee0f 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -41,7 +41,7 @@ _default_jhbuildrc = os.path.join(os.environ['HOME'], '.jhbuildrc')
 
 _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'partial_build', 'checkoutroot', 'buildroot', 'top_builddir',
-                'autogenargs', 'makeargs',
+                'autogenargs', 'makeargs', 'nice_build'
                 'installprog', 'repos', 'branches', 'noxvfb', 'xvfbargs',
                 'builddir_pattern', 'module_autogenargs', 'module_makeargs',
                 'interact', 'buildscript', 'nonetwork',
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index 9381d26..d7c49df 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -119,6 +119,11 @@ except AttributeError:
 # In particular, don't set it to 'gtk'.
 buildscript = 'terminal'
 
+# If True, run builds under "chrt --idle 0" on Linux ("nice" on other Unix)
+# This can dramatically improve desktop interactivity for builds with make -j X while
+# having only a tiny impact on build throughput.
+nice_build = True
+
 # where to put tinderbox output
 tinderbox_outputdir = None
 
diff --git a/jhbuild/frontends/autobuild.py b/jhbuild/frontends/autobuild.py
index c962058..8392bc5 100644
--- a/jhbuild/frontends/autobuild.py
+++ b/jhbuild/frontends/autobuild.py
@@ -172,6 +172,8 @@ class AutobuildBuildScript(buildscript.BuildScript, TerminalBuildScript):
             kws['env'] = os.environ.copy()
             kws['env'].update(extra_env)
 
+        command = self._prepare_execute(command)
+
         try:
             p = subprocess.Popen(command, **kws)
         except OSError, e:
diff --git a/jhbuild/frontends/buildscript.py b/jhbuild/frontends/buildscript.py
index 672d714..b281910 100644
--- a/jhbuild/frontends/buildscript.py
+++ b/jhbuild/frontends/buildscript.py
@@ -23,6 +23,7 @@ import logging
 
 from jhbuild.utils import packagedb
 from jhbuild.utils import trigger
+from jhbuild.utils import cmds
 from jhbuild.errors import FatalError, CommandError, SkipToPhase, SkipToEnd
 
 class BuildScript:
@@ -73,6 +74,24 @@ class BuildScript:
 
         self.packagedb = packagedb.PackageDB(new_pkgdb_path)
 
+        self.subprocess_nice_args = []
+        if config.nice_build:
+            if cmds.has_command('chrt'):
+                self.subprocess_nice_args.extend(['chrt', '--idle', '0'])
+            elif cmds.has_command('nice'):
+                self.subprocess_nice_args.append('nice')
+                
+            if cmds.has_command('ionice'):
+                self.subprocess_nice_args.extend(['ionice', '-c', '3', '-t'])
+
+    def _prepare_execute(self, command):
+        if self.subprocess_nice_args:
+            if isinstance(command, (str, unicode)):
+                command = ' '.join(self.subprocess_nice_args) + ' ' + command
+            else:
+                command = self.subprocess_nice_args + command
+        return command
+
     def execute(self, command, hint=None, cwd=None, extra_env=None):
         '''Executes the given command.
 
diff --git a/jhbuild/frontends/gtkui.py b/jhbuild/frontends/gtkui.py
index 3907f18..3211367 100644
--- a/jhbuild/frontends/gtkui.py
+++ b/jhbuild/frontends/gtkui.py
@@ -475,6 +475,8 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
                 kws['env'] = os.environ.copy()
                 kws['env'].update(extra_env)
 
+            command = self._prepare_execute(command)
+
             try:
                 p = subprocess.Popen(command, **kws)
             except OSError, e:
diff --git a/jhbuild/frontends/terminal.py b/jhbuild/frontends/terminal.py
index 1e403ce..31bb521 100644
--- a/jhbuild/frontends/terminal.py
+++ b/jhbuild/frontends/terminal.py
@@ -84,7 +84,7 @@ class TerminalBuildScript(buildscript.BuildScript):
         buildscript.BuildScript.__init__(self, config, module_list)
         self.trayicon = trayicon.TrayIcon(config)
         self.notify = notify.Notify(config)
-
+        
     def message(self, msg, module_num=-1):
         '''Display a message to the user'''
         
@@ -191,6 +191,8 @@ class TerminalBuildScript(buildscript.BuildScript):
             kws['env'] = os.environ.copy()
             kws['env'].update(extra_env)
 
+        command = self._prepare_execute(command)
+
         try:
             p = subprocess.Popen(command, **kws)
         except OSError, e:
diff --git a/jhbuild/frontends/tinderbox.py b/jhbuild/frontends/tinderbox.py
index 149ebac..5f684c4 100644
--- a/jhbuild/frontends/tinderbox.py
+++ b/jhbuild/frontends/tinderbox.py
@@ -256,6 +256,8 @@ class TinderboxBuildScript(buildscript.BuildScript):
             kws['env'] = os.environ.copy()
             kws['env'].update(extra_env)
 
+        command = self._prepare_execute(command)
+
         try:
             p = subprocess.Popen(command, **kws)
         except OSError, e:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]