def command()

in utils/bazel.py [0:0]


  def command(self, command, args=None):
    """Invokes a command with a bazel binary.

    Args:
      command: A string specifying the bazel command to invoke.
      args: An optional list of strings representing additional arguments to the
        bazel command.

    Returns:
      A dict containing collected metrics (wall, cpu, system times and
      optionally memory), the exit_status of the Bazel invocation, and the
      start datetime (in UTC).
      Returns None instead if the command equals 'shutdown'.
    """
    args = args or []
    logger.log('Executing Bazel command: bazel %s %s %s' %
               (' '.join(self._startup_options), command, ' '.join(args)))

    result = dict()
    result['started_at'] = datetime.datetime.utcnow()

    before_times = self._get_times()
    dev_null = open(os.devnull, 'w')
    exit_status = 0

    try:
      subprocess.check_call(
          [self._bazel_binary_path] + self._startup_options + [command] + args,
          stdout=dev_null,
          stderr=dev_null)
    except subprocess.CalledProcessError as e:
      exit_status = e.returncode
      logger.log_error('Bazel command failed with exit code %s' % e.returncode)

    if command == 'shutdown':
      return None
    after_times = self._get_times()

    for kind in ['wall', 'cpu', 'system']:
      result[kind] = after_times[kind] - before_times[kind]
    result['exit_status'] = exit_status

    # We do a number of runs here to reduce the noise in the data.
    result['memory'] = min([self._get_heap_size() for _ in range(5)])

    return result