def _LogMapFailureDiagnostics(device):
  _DumpHostLog()

  # The device forwarder daemon logs to the logcat, so print the end of that.
  try:
    logger.info('Last 50 lines of logcat:')
    for logcat_line in device.adb.Logcat(dump=True)[-50:]:
      logger.info('    %s', logcat_line)
  except (device_errors.CommandFailedError,
          device_errors.DeviceUnreachableError):
    # Grabbing the device forwarder log is also best-effort. Ignore all errors.
    logger.warning('Failed to get the contents of the logcat.')

  # Log alive device forwarders.
  try:
    ps_out = device.RunShellCommand(['ps'], check_return=True)
    logger.info('Currently running device_forwarders:')
    for line in ps_out:
      if 'device_forwarder' in line:
        logger.info('    %s', line)
  except (device_errors.CommandFailedError,
          device_errors.DeviceUnreachableError):
    logger.warning('Failed to list currently running device_forwarder '
                   'instances.')