[go: nahoru, domu]

Orderfile: Ensure a fresh profile save directory, along with other tweaks.

- If saving a profile, require that the output directory not pre-exist
  (otherwise, two profiling runs can cross-polinate each other).

- Allow slight tolerance in total call count mismatches.

- Fix (what looks like) a bug in 'miss' summation.

- Miscellaneous other cleanup.

R=mattcary

Bug: None
Change-Id: Ib0e8509665c0257b9b787ca67ef79edb09da0739
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1689796
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Commit-Queue: Matthew Cary (CET) <mattcary@chromium.org>
Auto-Submit: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: Matthew Cary (CET) <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675021}
diff --git a/tools/cygprofile/orderfile_generator_backend.py b/tools/cygprofile/orderfile_generator_backend.py
index cb713e8..609bb7ac 100755
--- a/tools/cygprofile/orderfile_generator_backend.py
+++ b/tools/cygprofile/orderfile_generator_backend.py
@@ -589,7 +589,7 @@
     self._instrumented_out_dir = os.path.join(
         self._BUILD_ROOT, self._options.arch + '_instrumented_out')
     if self._options.use_call_graph:
-        self._instrumented_out_dir += '_call_graph'
+      self._instrumented_out_dir += '_call_graph'
 
     self._uninstrumented_out_dir = os.path.join(
         self._BUILD_ROOT, self._options.arch + '_uninstrumented_out')
@@ -669,6 +669,14 @@
     self._step_recorder.BeginStep('Generate Profile Data')
     files = []
     logging.getLogger().setLevel(logging.DEBUG)
+
+    if self._options.profile_save_dir:
+      # The directory must not preexist, to ensure purity of data. Check
+      # before profiling to save time.
+      if os.path.exists(self._options.profile_save_dir):
+        raise Exception('Profile save directory must not pre-exist')
+      os.makedirs(self._options.profile_save_dir)
+
     if self._options.system_health_orderfile:
       files = self._profiler.CollectSystemHealthProfile(
           self._compiler.chrome_apk)
@@ -1211,7 +1219,7 @@
 
 
 def CreateOrderfile(options, orderfile_updater_class=None):
-  """Creates an oderfile.
+  """Creates an orderfile.
 
   Args:
     options: As returned from optparse.OptionParser.parse_args()