コード例 #1
0
ファイル: watch.py プロジェクト: tuwid/darkc0de-old-stuff
    def __init__(self, process,
    exitcode_score=0.50, signal_score=1.0, default_score=0.0,
    timeout_score=1.0):
        self.process = weakref_ref(process)
        project = process.project()
        ProjectAgent.__init__(self, project, "watch:%s" % process.name)
        if RUNNING_LINUX:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.warning("CpuProbe is not available")
            self.cpu = None

        # Score if process exited normally
        self.default_score = default_score

        # Score if process exit code is not nul
        self.exitcode_score = exitcode_score

        # Score if process has been killed by signal
        self.signal_score = signal_score

        # Score if process timeout has been reached
        self.timeout_score = timeout_score
コード例 #2
0
ファイル: watch.py プロジェクト: cherry-wb/segvault
    def __init__(self, process,
    exitcode_score=DEFAULT_EXITCODE_SCORE,
    signal_score=DEFAULT_SIGNAL_SCORE,
    default_score=0.0,
    timeout_score=DEFAULT_TIMEOUT_SCORE):
        self.process = weakref_ref(process)
        project = process.project()
        ProjectAgent.__init__(self, project, "watch:%s" % process.name)
        if RUNNING_LINUX and project.config.use_cpu_probe:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.cpu = None

        # Score if process exited normally
        self.default_score = default_score

        # Score if process exit code is not nul
        self.exitcode_score = exitcode_score

        # Score if process has been killed by signal
        self.signal_score = signal_score

        # Score if process timeout has been reached
        self.timeout_score = timeout_score
コード例 #3
0
ファイル: watch.py プロジェクト: cherry-wb/segvault
class WatchProcess(ProjectAgent):
    def __init__(self, process,
    exitcode_score=DEFAULT_EXITCODE_SCORE,
    signal_score=DEFAULT_SIGNAL_SCORE,
    default_score=0.0,
    timeout_score=DEFAULT_TIMEOUT_SCORE):
        self.process = weakref_ref(process)
        project = process.project()
        ProjectAgent.__init__(self, project, "watch:%s" % process.name)
        if RUNNING_LINUX and project.config.use_cpu_probe:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.cpu = None

        # Score if process exited normally
        self.default_score = default_score

        # Score if process exit code is not nul
        self.exitcode_score = exitcode_score

        # Score if process has been killed by signal
        self.signal_score = signal_score

        # Score if process timeout has been reached
        self.timeout_score = timeout_score

    def init(self):
        self.score = None
        self.pid = None

    def on_process_create(self, agent):
        if agent != self.process():
            return
        self.pid = agent.process.pid
        self.prepareProcess()

    def on_session_start(self):
        if self.pid is not None:
            self.prepareProcess()

    def prepareProcess(self):
        if self.cpu:
            self.cpu.setPid(self.pid)

    def live(self):
        if not self.pid:
            return

        # Check if process is done or not
        status = self.process().poll()
        if status is not None:
            self.processDone(status)
            return

    def processDone(self, status):
        self.score = self.computeScore(status)
        self.send('session_stop')
        self.pid = None

    def getScore(self):
        return self.score

    def computeScore(self, status):
        # Timeout reached
        if self.process().timeout_reached:
            return self.timeout_score

        # No status: no way to compute score
        if status is None:
            return None

        # Process exit code is not nul?
        if 0 < status and status != 127:
            return self.exitcode_score

        # Process killed by a signal
        if status < 0:
            return self.signal_score

        # Process exited normally: default score
        return self.default_score

    def deinit(self):
        self.pid = None
コード例 #4
0
ファイル: watch.py プロジェクト: zhuyue1314/segvault
class WatchProcess(ProjectAgent):
    def __init__(self,
                 process,
                 exitcode_score=DEFAULT_EXITCODE_SCORE,
                 signal_score=DEFAULT_SIGNAL_SCORE,
                 default_score=0.0,
                 timeout_score=DEFAULT_TIMEOUT_SCORE):
        self.process = weakref_ref(process)
        project = process.project()
        ProjectAgent.__init__(self, project, "watch:%s" % process.name)
        if RUNNING_LINUX and project.config.use_cpu_probe:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.cpu = None

        # Score if process exited normally
        self.default_score = default_score

        # Score if process exit code is not nul
        self.exitcode_score = exitcode_score

        # Score if process has been killed by signal
        self.signal_score = signal_score

        # Score if process timeout has been reached
        self.timeout_score = timeout_score

    def init(self):
        self.score = None
        self.pid = None

    def on_process_create(self, agent):
        if agent != self.process():
            return
        self.pid = agent.process.pid
        self.prepareProcess()

    def on_session_start(self):
        if self.pid is not None:
            self.prepareProcess()

    def prepareProcess(self):
        if self.cpu:
            self.cpu.setPid(self.pid)

    def live(self):
        if not self.pid:
            return

        # Check if process is done or not
        status = self.process().poll()
        if status is not None:
            self.processDone(status)
            return

    def processDone(self, status):
        self.score = self.computeScore(status)
        self.send('session_stop')
        self.pid = None

    def getScore(self):
        return self.score

    def computeScore(self, status):
        # Timeout reached
        if self.process().timeout_reached:
            return self.timeout_score

        # No status: no way to compute score
        if status is None:
            return None

        # Process exit code is not nul?
        if 0 < status and status != 127:
            return self.exitcode_score

        # Process killed by a signal
        if status < 0:
            return self.signal_score

        # Process exited normally: default score
        return self.default_score

    def deinit(self):
        self.pid = None
コード例 #5
0
ファイル: attach.py プロジェクト: zhuyue1314/segvault
class AttachProcessPID(ProjectAgent):
    def __init__(self, project, pid, name=None):
        if not name:
            name = "pid:%s" % pid
        ProjectAgent.__init__(self, project, name)
        if RUNNING_WINDOWS:
            raise NotImplementedError(
                "AttachProcessPID is not supported on Windows")
        self.death_score = 1.0
        self.show_exit = True   # needed by the debugger
        self.max_memory = 100*1024*1024
        self.memory_score = 1.0
        self.debugger = project.debugger
        self.dbg_process = None
        if HAS_PROC and project.config.use_cpu_probe:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.warning("CpuProbe is not available on your OS")
            self.cpu = None
        if pid:
            self.setPid(pid)
        else:
            self.pid = None

    def init(self):
        self.score = 0.0

    def on_project_stop(self):
        if self.dbg_process:
            self.dbg_process.detach()
            self.dbg_process = None

    def setPid(self, pid):
        self.pid = pid
        dumpProcessInfo(self.info, self.pid)
        if self.cpu:
            self.cpu.setPid(pid)
        if not self.dbg_process:
            self.dbg_process = self.debugger.tracePID(self, pid)

    def live(self):
        if self.pid is None:
            return
        if not self.checkAlive():
            return
        if self.max_memory:
            if not self.checkMemory():
                return

    def checkAlive(self):
        if RUNNING_WINDOWS:
            raise NotImplementedError()

        if self.dbg_process:
            status = self.debugger.pollPID(self.pid)
            if status is None:
                return True
        elif HAS_PROC:
            try:
                stat('/proc/%s' % self.pid)
                return True
            except OSError, err:
                if err.errno != ENOENT:
                    raise
        else:
コード例 #6
0
ファイル: watch.py プロジェクト: tuwid/darkc0de-old-stuff
class WatchProcess(ProjectAgent):
    def __init__(self, process,
    exitcode_score=0.50, signal_score=1.0, default_score=0.0,
    timeout_score=1.0):
        self.process = weakref_ref(process)
        project = process.project()
        ProjectAgent.__init__(self, project, "watch:%s" % process.name)
        if RUNNING_LINUX:
            self.cpu = CpuProbe(project, "%s:cpu" % self.name)
        else:
            self.warning("CpuProbe is not available")
            self.cpu = None

        # Score if process exited normally
        self.default_score = default_score

        # Score if process exit code is not nul
        self.exitcode_score = exitcode_score

        # Score if process has been killed by signal
        self.signal_score = signal_score

        # Score if process timeout has been reached
        self.timeout_score = timeout_score

    def init(self):
        self.score = None
        self.pid = None

    def on_process_create(self, agent):
        if agent != self.process():
            return
        self.pid = agent.process.pid
        self.prepareProcess()

    def on_session_start(self):
        if self.pid is not None:
            self.prepareProcess()

    def prepareProcess(self):
        dumpProcessInfo(self.info, self.pid)
        if self.cpu:
            self.cpu.setPid(self.pid)

    def live(self):
        if not self.pid:
            return

        # Check if process is done or not
        status = self.process().poll()
        if status is not None:
            self.processDone(status)
            return

    def processDone(self, status):
        self.score = self.computeScore(status)
        if not self.process().timeout_reached:
            log = self.scoreLogFunc()
            displayProcessStatus(log, status)
        self.send("process_done", self.process(), status)
        self.send('session_stop')
        self.pid = None

    def getScore(self):
        return self.score

    def computeScore(self, status):
        # Timeout reached
        if self.process().timeout_reached:
            return self.timeout_score

        # No status: no way to compute score
        if status is None:
            return None

        # Process exit code is not nul?
        if 0 < status:
            return self.exitcode_score

        # Process killed by a signal
        if status < 0:
            return self.signal_score

        # Process exited normally: default score
        return self.default_score

    def deinit(self):
        self.pid = None