예제 #1
0
    def test_ProcTable_mirror_by_pid(self):
        bname = 'unittest-ptmbp2'
        bunch, myproc, psutilproc = tests.BunchProto.start(bname)
        pt = ProcTable()
        self.assertIsInstance(pt.mirror_by_pid(psutilproc.pid), ProcessMirror)

        bunch.stop()
예제 #2
0
 def test_ProcTable_get_bundle_names(self):
     logging.debug("======= %s ======" % inspect.stack()[0][3])
     try:
         table = ProcTable()
         logging.debug("Bundle names: {}".format(table.get_bundle_names()))
     except psutil._exceptions.AccessDenied as e:
         logging.error(e)
         logging.error("Some tests require root priveleges")
예제 #3
0
    def test_ProcTable_children(self):
        bname = 'unittest-pm'
        nchildren = 5
        bunch, myproc, psutilproc = tests.BunchProto.start(bname, nchildren=5)
        pt = ProcTable()
        m = pt.mirror_by_pid(psutilproc.pid)
        self.assertTrue(len(m.children()) == nchildren)
        self.assertIsInstance(m.children()[0], ProcessMirror)

        bunch.stop()
예제 #4
0
    def test_ProcTable_get_top_5s(self):
        bname = 'unittest-ptgt5s'
        nchildren = 10
        bunch, myproc, psutilproc = tests.BunchProto.start(bname, nchildren=5)
        pt = ProcTable()

        top5 = pt.get_top_5s()
        self.assertTrue(len(top5) > 5)

        bunch.stop()
예제 #5
0
    def test_ProcTable_mirrors_by_pgid(self):
        bname = 'unittest-ptmbp'
        bunch, myproc, psutilproc = tests.BunchProto.start(bname)
        pt = ProcTable()
        pgid = os.getpgid(psutilproc.pid)
        self.assertTrue(
            len(
                list(
                    filter(None,
                           [p._pgid != pgid
                            for p in pt.mirrors_by_pgid(pgid)]))) == 0)

        bunch.stop()
예제 #6
0
    def test_ProcBundle_stats(self):
        logging.debug("======= %s ======" % inspect.stack()[0][3])
        bname = 'unittest-pbs'
        bunch, myproc, psutilproc = tests.BunchProto.start(bname)

        pt = ProcTable()
        bundle = pt.get_bundle_by_name(pt.get_bundle_names()[0])
        self.assertIsInstance(bundle.get_n_ctx_switches_vol(), int)
        self.assertIsInstance(bundle.get_n_ctx_switches_invol(), int)
        self.assertIsInstance(bundle.get_memory_info_rss(), int)
        self.assertIsInstance(bundle.get_memory_info_vms(), int)
        self.assertIsInstance(bundle.get_cpu_percent(), float)

        bunch.stop()
예제 #7
0
    def test_name_from_proctitles(self):
        logging.debug("======= %s ======" % inspect.stack()[0][3])

        bname = "unittest-nfpt"
        procname = "sh:./test.sh"
        bunch, myproc, psutilproc = tests.BunchProto.start(bname,
                                                           nchildren=2,
                                                           func=cycle)
        p = ProcTable()
        time.sleep(0.1)
        bundle = p.get_bundle_by_name(bname)
        #print(bundle._name_from_self_proclist())
        bunch.stop()
        """
예제 #8
0
    def test_ProcTable_test(self):
        bname = 'unittest-t'
        nchildren = 5
        bunch, myproc, psutilproc = tests.BunchProto.start(bname, nchildren=5)
        pt = ProcTable()

        #print(pt.bundles[0].bundle_name)

        bunch.stop()
예제 #9
0
    def test_ProcessBundle_name(self):
        bname = 'unittest-pb'
        bunch, myproc, psutilproc = tests.BunchProto.start(bname)

        procs = psutilproc.children()
        procs.append(psutilproc)
        pt = ProcTable()
        procs = [ProcessMirror(p, pt) for p in procs]
        bundle = ProcBundle(procs, pt=pt)
        self.assertTrue(bundle.bundle_name == bname)

        bunch.stop()
예제 #10
0
    def test_get_pcpu_busy(self):
        logging.debug("======= %s ======" % inspect.stack()[0][3])

        bname = "unittest-gpcpb"
        procname = "sh:./test.sh"
        bunch, myproc, psutilproc = tests.BunchProto.start(bname,
                                                           nchildren=2,
                                                           func=cycle)
        p = ProcTable()
        time.sleep(0.1)
        #print(p.get_bundle_names())
        """
        for b in p.bundles:
            print("{}:\t{}".format(b.bundle_name, b.proclist))
        """
        bundle = p.get_bundle_by_name(procname)
        pcpu = bundle.pcpu
        #print(bundle.__class__)
        pcpu_threshold = 75
        if pcpu <= pcpu_threshold:
            print("pcpu value: {}".format(pcpu))
        self.assertTrue(pcpu > pcpu_threshold)

        bunch.stop()
예제 #11
0
    def test_get_idle(self):
        logging.debug("======= %s ======" % inspect.stack()[0][3])
        p = ProcTable()
        self.assertIsInstance(p.get_idle(), float)

        bname = "unittest-gi"
        bunch, myproc, psutilproc = tests.BunchProto.start(bname,
                                                           nchildren=2,
                                                           func=cycle)
        p = ProcTable()

        self.assertTrue(p.get_idle() < 10.0)

        bunch.stop()
예제 #12
0
#!/usr/bin/env python3
import zaggregator
import zaggregator.utils as utils
import zaggregator.tests as tests
import zaggregator.procbundle as pb
from zaggregator.procbundle import ProcBundle
from zaggregator.proctable import ProcTable
from zaggregator.procmirror import ProcessMirror
from zaggregator.tests import cycle

if __name__ == '__main__':
    pt = ProcTable()
    for p in pt._procs:
        print(p)
예제 #13
0
 def test_ProcTable_mirror_by_pid(self):
     pt = ProcTable()
     proc = psutil.Process(pid=os.getpid())
     self.assertTrue(pt.mirror_by_pid(os.getpid()).pid == os.getpid())