<commit_before>import logging
import subprocess
import telnetlib
import time
from .adapter import Adapter


QEMU_START_DELAY = 1


class QEMUConnException(Exception):
    """
    Exception in telnet connection
    """
    pass


class EOF(Exception):
    """
    Exception in telnet connection
    """
    pass


class QEMUConn(Adapter):
    """
    a connection with QEMU.
    """
    def __init__(self, hda, telnet_port, hostfwd_port, qemu_no_graphic):
        """
        initiate a QEMU connection
        :return:
        """
        logging.basicConfig(level=logging.INFO)
        self.logger = logging.getLogger('QEMU')

        self.hda = hda
        self.domain = "localhost"
        self.telnet_port = telnet_port
        self.hostfwd_port = hostfwd_port
        self.qemu_no_graphic = qemu_no_graphic
        self.connected = False

    def set_up(self):
        # start qemu instance
        qemu_cmd = ["qemu-system-i386",
                    "-hda", self.hda,
                    "-smp", "cpus=2",
                    "-m", "2048",
                    "-machine", "q35",
                    "-monitor", "telnet:%s:%d,server,nowait" % \
                    (self.domain, self.telnet_port),
                    "-net", "nic,model=e1000",
                    "-net", "user,hostfwd=tcp::%d-:5555" % \
                    self.hostfwd_port,
                    "-enable-kvm"]
        if self.qemu_no_graphic:
            qemu_cmd.append("-nographic")
        self.logger.info(qemu_cmd)
        self.qemu_p = subprocess.Popen(qemu_cmd)
        self.pid = self.qemu_p.pid
        time.sleep(QEMU_START_DELAY)

    def utf8bytes(self, string):
        return bytes(string, encoding="utf-8")

    def connect(self, from_snapshot=False):
        # 1. Connect to QMP
        self.qemu_tel = telnetlib.Telnet(host=self.domain, port=self.telnet_port)
        self.logger.info(self.qemu_tel.read_until(self.utf8bytes("\r\n")))
        # 2. Recover adbd if from_snapshot
        if from_snapshot:<commit_msg>use 4 cpus<commit_after>import logging
import subprocess
import telnetlib
import time
from .adapter import Adapter


QEMU_START_DELAY = 1


class QEMUConnException(Exception):
    """
    Exception in telnet connection
    """
    pass


class EOF(Exception):
    """
    Exception in telnet connection
    """
    pass


class QEMUConn(Adapter):
    """
    a connection with QEMU.
    """
    def __init__(self, hda, telnet_port, hostfwd_port, qemu_no_graphic):
        """
        initiate a QEMU connection
        :return:
        """
        logging.basicConfig(level=logging.INFO)
        self.logger = logging.getLogger('QEMU')

        self.hda = hda
        self.domain = "localhost"
        self.telnet_port = telnet_port
        self.hostfwd_port = hostfwd_port
        self.qemu_no_graphic = qemu_no_graphic
        self.connected = False

    def set_up(self):
        # start qemu instance
        qemu_cmd = ["qemu-system-i386",
                    "-hda", self.hda,
                    "-smp", "cpus=4",
                    "-m", "2048",
                    "-machine", "q35",
                    "-monitor", "telnet:%s:%d,server,nowait" % \
                    (self.domain, self.telnet_port),
                    "-net", "nic,model=e1000",
                    "-net", "user,hostfwd=tcp::%d-:5555" % \
                    self.hostfwd_port,
                    "-enable-kvm"]
        if self.qemu_no_graphic:
            qemu_cmd.append("-nographic")
        self.logger.info(qemu_cmd)
        self.qemu_p = subprocess.Popen(qemu_cmd)
        self.pid = self.qemu_p.pid
        time.sleep(QEMU_START_DELAY)

    def utf8bytes(self, string):
        return bytes(string, encoding="utf-8")

    def connect(self, from_snapshot=False):
        # 1. Connect to QMP
        self.qemu_tel = telnetlib.Telnet(host=self.domain, port=self.telnet_port)
        self.logger.info(self.qemu_tel.read_until(self.utf8bytes("\r\n")))
        # 2. Recover adbd if from_snapshot
        if from_snapshot:
{'fraction_non_alphanumeric': 0.11667913238593867, 'fraction_numerical': 0.012216404886561954, 'mean_word_length': 1.9306062819576333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3066510', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1293, 'n_words': 237}