Пример #1
0
 def testProcessCPUPollerBasic(self):
     pid = os.getpid()
     name = "mytestprocess"
     pd = ProcessDetail(pid, name)
     poller = ProcessCPUPoller()
     v = poller.sample(pd)
     self.assertTrue(isinstance(v, types.FloatType))
Пример #2
0
 def testProcessCPUPollerBasic(self):
     pid = os.getpid()
     name = "mytestprocess"
     pd = ProcessDetail(pid, name)
     poller = ProcessCPUPoller()
     v = poller.sample(pd)
     self.assertTrue(isinstance(v, float))
Пример #3
0
 def testProcessCPUPollerBasic(self):
     p = utils.getProcess()
     self.testProcesses.append(p)        
     name = "mytestprocess"
     pd = ProcessDetail(p.pid, name)        
     poller = ProcessCPUPoller()
     v = poller.sample(pd)
     self.assertTrue(isinstance(v, types.FloatType))
     # psutil.error.AccessDenied will result into -1 returned
     self.assertTrue(v > 0)        
Пример #4
0
 def testProcessCPUPollerNoSuchProcess(self):
     """
     Poller should handle if the watched processed crashed or was
     terminated, so polling on NoSuchProcess.
     
     """
     pd = self._getKilledProcessDetail()        
     poller = ProcessCPUPoller()
     self.assertFalse(pd.proc.is_running())
     v = poller.sample(pd)
     self.assertTrue(isinstance(v, types.FloatType))
     # above situation shall result into handled psutil.error.NoSuchProcess
     self.assertEquals(v, -1)
Пример #5
0
    def sample(processDetail):
        """
        Return a single float representing CPU usage of the main process
        and its subprocesses.

        """
        return ProcessCPUPoller.sample(processDetail)
Пример #6
0
    def sample(processDetail):
        """
        Return a single float representing CPU usage of the main process
        and its subprocesses.

        """
        return ProcessCPUPoller.sample(processDetail)
Пример #7
0
    def testProcessCPUPollerNoSuchProcess(self):
        """
        Poller should handle if the watched processed crashed or was
        terminated, so polling on NoSuchProcess.

        """
        pd = self._getKilledProcessDetail()
        poller = ProcessCPUPoller()
        self.assertFalse(pd.proc.is_running())
        # sample() shall result into handled psutil.error.NoSuchProcess
        self.assertRaises(Exception, poller.sample, pd)