def _LogSystemStatistics(log_file_name): statistics_log = runner_logs.FileStreamFor(log_file_name) # Log the cpu load and process information. subprocess.call(['top', '-b', '-n', '1'], stdin=open(os.devnull), stdout=statistics_log, stderr=subprocess.STDOUT) subprocess.call(['ps', '-ax'], stdin=open(os.devnull), stdout=statistics_log, stderr=subprocess.STDOUT)
def _WaitUntilReady(self): logging.info('Connecting to Fuchsia using SSH.') host, port = self._GetEndpoint() end_time = time.time() + _ATTACH_RETRY_SECONDS ssh_diagnostic_log = runner_logs.FileStreamFor('ssh_diagnostic_log') while time.time() < end_time: runner = remote_cmd.CommandRunner(self._GetSshConfigPath(), host, port) ssh_proc = runner.RunCommandPiped(['true'], ssh_args=['-v'], stdout=ssh_diagnostic_log, stderr=subprocess.STDOUT) if ssh_proc.wait() == 0: logging.info('Connected!') self._started = True return True time.sleep(_ATTACH_RETRY_INTERVAL) logging.error('Timeout limit reached.') raise FuchsiaTargetException('Couldn\'t connect using SSH.')
def Start(self): emu_command = self._BuildCommand() # We pass a separate stdin stream. Sharing stdin across processes # leads to flakiness due to the OS prematurely killing the stream and the # Python script panicking and aborting. # The precise root cause is still nebulous, but this fix works. # See crbug.com/741194. logging.debug('Launching %s.' % (self._GetEmulatorName())) logging.debug(' '.join(emu_command)) # Zircon sends debug logs to serial port (see kernel.serial=legacy flag # above). Serial port is redirected to a file through emulator stdout. # If runner_logs are not enabled, we output the kernel serial log # to a temporary file, and print that out if we are unable to connect to # the emulator guest, to make it easier to diagnose connectivity issues. temporary_log_file = None if runner_logs.IsEnabled(): stdout = runner_logs.FileStreamFor('serial_log') else: temporary_log_file = tempfile.NamedTemporaryFile('w') stdout = temporary_log_file # TODO(crbug.com/1100402): Delete when no longer needed for debug info. # Log system statistics at the start of the emulator run. _LogSystemStatistics('system_start_statistics_log') self._emu_process = subprocess.Popen(emu_command, stdin=open(os.devnull), stdout=stdout, stderr=subprocess.STDOUT, env=self._SetEnv()) try: self._WaitUntilReady() except target.FuchsiaTargetException: if temporary_log_file: logging.info('Kernel logs:\n' + open(temporary_log_file.name, 'r').read()) raise
def _LogProcessStatistics(log_file_name): statistics_log = runner_logs.FileStreamFor(log_file_name) subprocess.call(['cat', '/proc/stat'], stdin=open(os.devnull), stdout=statistics_log, stderr=subprocess.STDOUT)