[go: nahoru, domu]

startop: Only do perfetto trace when needed.

Bug: 141324324
Test: python app_startup_runner.py  --package com.google.android.GoogleCamera  --readahead fadvise --inodes ../tmp.txt   -d
Test: python app_startup_runner.py  --package com.google.android.GoogleCamera  --readahead cold --inodes ../tmp.txt   -d
Change-Id: Icbf9e253cd3cf9517dca89c8d50efd21012105a9
diff --git a/startop/scripts/app_startup/app_startup_runner.py b/startop/scripts/app_startup/app_startup_runner.py
index fa1c4e6..25ee6f7 100755
--- a/startop/scripts/app_startup/app_startup_runner.py
+++ b/startop/scripts/app_startup/app_startup_runner.py
@@ -233,13 +233,17 @@
                                      simulate: bool,
                                      inodes_path: str,
                                      timeout: int,
-                                     compiler_type: CompilerType) -> DataFrame:
+                                     compiler_type: CompilerType,
+                                     requires_trace_collection: bool) -> DataFrame:
   """ Executes run based on perfetto trace. """
-  passed, perfetto_trace_file = run_perfetto_collector(collector_info,
-                                                       timeout,
-                                                       simulate)
-  if not passed:
-    raise RuntimeError('Cannot run perfetto collector!')
+  if requires_trace_collection:
+    passed, perfetto_trace_file = run_perfetto_collector(collector_info,
+                                                         timeout,
+                                                         simulate)
+    if not passed:
+      raise RuntimeError('Cannot run perfetto collector!')
+  else:
+    perfetto_trace_file = tempfile.NamedTemporaryFile()
 
   with perfetto_trace_file:
     for combos in run_combos:
@@ -271,7 +275,8 @@
     simulate: bool,
     inodes_path: str,
     timeout: int,
-    compiler_type: CompilerType):
+    compiler_type: CompilerType,
+    requires_trace_collection: bool):
   # nothing will work if the screen isn't unlocked first.
   cmd_utils.execute_arbitrary_command([_UNLOCK_SCREEN_SCRIPT],
                                       timeout,
@@ -284,7 +289,8 @@
                                                 simulate,
                                                 inodes_path,
                                                 timeout,
-                                                compiler_type)
+                                                compiler_type,
+                                                requires_trace_collection)
 
 def gather_results(commands: Iterable[Tuple[DataFrame]],
                    key_list: List[str], value_list: List[Tuple[str, ...]]):
@@ -369,11 +375,13 @@
                                                                       CollectorPackageInfo)
 
   print_utils.debug_print_gen("grouped run combinations: ", grouped_combos())
+  requires_trace_collection = any(i in _TRACING_READAHEADS for i in opts.readaheads)
   exec = execute_run_combos(grouped_combos(),
                             opts.simulate,
                             opts.inodes,
                             opts.timeout,
-                            opts.compiler_type)
+                            opts.compiler_type,
+                            requires_trace_collection)
 
   results = gather_results(exec, _COMBINATORIAL_OPTIONS, combos())