Ejemplo n.º 1
0
def adb_push_to_tmp_dir(content: str,
                        relative_dir: str = "",
                        verbose: bool = False) -> str:
    """Pushes content onto the Android device.

  Args:
    content: the full path to the source file.
    relative_dir: the directory to push to; relative to ANDROID_TMP_DIR.

  Returns:
    The full path to the content on the Android device.
  """
    filename = os.path.basename(content)
    android_path = os.path.join(ANDROID_TMP_DIR, relative_dir, filename)
    execute_cmd(["adb", "push", "-p",
                 os.path.abspath(content), android_path],
                verbose=verbose)
    return android_path
Ejemplo n.º 2
0
  def __run_capture(self, android_case_dir: str, tool_name: str,
                    capture_filename: str, taskset: str):
    capture_config = self.config.trace_capture_config
    host_tool_path = os.path.join(capture_config.traced_benchmark_tool_dir,
                                  tool_name)
    android_tool = self.__check_and_push_file(host_tool_path,
                                              TRACED_TOOL_REL_DIR)
    run_cmd = [
        "TRACY_NO_EXIT=1", f"IREE_PRESERVE_DYLIB_TEMP_FILES={ANDROID_TMP_DIR}",
        "taskset", taskset, android_tool, f"--flagfile={MODEL_FLAGFILE_NAME}"
    ]

    # Just launch the traced benchmark tool with TRACY_NO_EXIT=1 without
    # waiting for the adb command to complete as that won't happen.
    process = adb_start_cmd(run_cmd, android_case_dir, verbose=self.verbose)
    # But we do need to wait for its start; otherwise will see connection
    # failure when opening the catpure tool. Here we cannot just sleep a
    # certain amount of seconds---Pixel 4 seems to have an issue that will
    # make the trace collection step get stuck. Instead wait for the
    # benchmark result to be available.
    while True:
      line = process.stdout.readline()  # pytype: disable=attribute-error
      if line == "" and process.poll() is not None:  # Process completed
        raise ValueError("Cannot find benchmark result line in the log!")
      if self.verbose:
        print(line.strip())
      # Result available
      if re.match(r"^BM_.+/real_time", line) is not None:
        break

    # Now it's okay to collect the trace via the capture tool. This will
    # send the signal to let the previously waiting benchmark tool to
    # complete.
    capture_cmd = [
        capture_config.trace_capture_tool, "-f", "-o", capture_filename
    ]
    # If verbose, just let the subprocess print its output. The subprocess
    # may need to detect if the output is a TTY to decide whether to log
    # verbose progress info and use ANSI colors, so it's better to use
    # stdout redirection than to capture the output in a string.
    stdout_redirect = None if self.verbose else subprocess.DEVNULL
    execute_cmd(capture_cmd, verbose=self.verbose, stdout=stdout_redirect)
Ejemplo n.º 3
0
def adb_push_to_tmp_dir(content: str,
                        relative_dir: str = "",
                        verbose: bool = False) -> str:
  """Pushes content onto the Android device.

  Args:
    content: the full path to the source file.
    relative_dir: the directory to push to; relative to ANDROID_TMP_DIR.

  Returns:
    The full path to the content on the Android device.
  """
  filename = os.path.basename(content)
  android_path = os.path.join(ANDROID_TMP_DIR, relative_dir, filename)
  # When the output is a TTY, keep the default progress info output.
  # In other cases, redirect progress info to null to avoid bloating log files.
  stdout_redirect = None if sys.stdout.isatty() else subprocess.DEVNULL
  execute_cmd(
      ["adb", "push", os.path.abspath(content), android_path],
      verbose=verbose,
      stdout=stdout_redirect)
  return android_path
Ejemplo n.º 4
0
def adb_execute(cmd_args: Sequence[str],
                relative_dir: str = "",
                verbose: bool = False) -> subprocess.CompletedProcess:
    """Executes command with adb shell.

  Switches to `relative_dir` relative to the android tmp directory before
  executing. Waits for completion. Output is streamed to the terminal.

  Args:
    cmd_args: a list containing the command to execute and its parameters
    relative_dir: the directory to execute the command in; relative to
      ANDROID_TMP_DIR.

  Returns:
    The completed process.
  """
    cmd = ["adb", "shell"]
    cmd.extend(["cd", os.path.join(ANDROID_TMP_DIR, relative_dir)])
    cmd.append("&&")
    cmd.extend(cmd_args)

    return execute_cmd(cmd, verbose=verbose)