Orderfile: add option to build for monochrome.

This is helpful for local testing, where our older devices are getting flaky,
and will eventually be necessary when the bot upgrades.

Bug: 758566
Change-Id: If1d36f17c3ffd8605d14ab1aa30d4df0acafc3ad
Reviewed-on: https://chromium-review.googlesource.com/1219688
Reviewed-by: Egor Pasko <pasko@chromium.org>
Reviewed-by: Benoit L <lizeb@chromium.org>
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591322}
diff --git a/tools/cygprofile/orderfile_generator_backend.py b/tools/cygprofile/orderfile_generator_backend.py
index 9c3a157..c4af0b4 100755
--- a/tools/cygprofile/orderfile_generator_backend.py
+++ b/tools/cygprofile/orderfile_generator_backend.py
@@ -228,7 +228,7 @@
   """Handles compilation of clank."""
 
   def __init__(self, out_dir, step_recorder, arch, jobs, max_load, use_goma,
-               goma_dir, system_health_profiling):
+               goma_dir, system_health_profiling, monochrome):
     self._out_dir = out_dir
     self._step_recorder = step_recorder
     self._arch = arch
@@ -237,12 +237,20 @@
     self._use_goma = use_goma
     self._goma_dir = goma_dir
     self._system_health_profiling = system_health_profiling
+    if monochrome:
+      self._apk = 'Monochrome.apk'
+      self._libname = 'libmonochrome'
+      self._libchrome_target = 'monochrome'
+    else:
+      self._apk = 'Chrome.apk'
+      self._libname = 'libchrome'
+      self._libchrome_target = 'libchrome'
 
     self.obj_dir = os.path.join(self._out_dir, 'Release', 'obj')
     self.lib_chrome_so = os.path.join(
-        self._out_dir, 'Release', 'lib.unstripped', 'libchrome.so')
-    self.chrome_apk = os.path.join(
-        self._out_dir, 'Release', 'apks', 'Chrome.apk')
+        self._out_dir, 'Release', 'lib.unstripped',
+        '{}.so'.format(self._libname))
+    self.chrome_apk = os.path.join(self._out_dir, 'Release', 'apks', self._apk)
 
   def Build(self, instrumented, target):
     """Builds the provided ninja target with or without order_profiling on.
@@ -302,7 +310,7 @@
     """
     if force_relink:
       self._step_recorder.RunCommand(['rm', '-rf', self.lib_chrome_so])
-    self.Build(instrumented, 'libchrome')
+    self.Build(instrumented, self._libchrome_target)
 
 
 class OrderfileUpdater(object):
@@ -694,7 +702,8 @@
             self._instrumented_out_dir,
             self._step_recorder, self._options.arch, self._options.jobs,
             self._options.max_load, self._options.use_goma,
-            self._options.goma_dir, self._options.system_health_orderfile)
+            self._options.goma_dir, self._options.system_health_orderfile,
+            self._options.monochrome)
         self._compiler.CompileChromeApk(True)
         self._GenerateAndProcessProfile()
         self._MaybeArchiveOrderfile(self._GetUnpatchedOrderfileFilename())
@@ -727,7 +736,7 @@
             self._uninstrumented_out_dir, self._step_recorder,
             self._options.arch, self._options.jobs, self._options.max_load,
             self._options.use_goma, self._options.goma_dir,
-            self._options.system_health_orderfile)
+            self._options.system_health_orderfile, self._options.monochrome)
         self._compiler.CompileLibchrome(False)
         self._PatchOrderfile()
         # Because identical code folding is a bit different with and without
@@ -807,6 +816,9 @@
                       help=('Create an orderfile based on system health '
                             'benchmarks.'),
                       default=False)
+  parser.add_argument('--monochrome', action='store_true',
+                      help=('Compile and instrument monochrome (for post-N '
+                            'devices).'))
   parser.add_argument('--offsets-for-memory', action='store_true',
                       help=('Favor memory savings in the orderfile. Used '
                             'with --system-health-orderfile.'),