Example #1
0
 def at_repeat(self):
     "called every 2 hours. Sets a max attr-cache limit to 100 MB." # enough for normal usage?
     if is_pypy:
         # pypy don't support get_size, so we have to skip out here.
         return
     attr_cache_size, _, _ = caches.get_cache_sizes()
     if attr_cache_size > _ATTRIBUTE_CACHE_MAXSIZE:
         caches.flush_attr_cache()
Example #2
0
    def func(self):
        "Show list."

        caller = self.caller

        # display active processes

        if not utils.host_os_is('posix'):
            string = "Process listings are only available under Linux/Unix."
        else:
            global _resource, _idmapper
            if not _resource:
                import resource as _resource
            if not _idmapper:
                from src.utils.idmapper import base as _idmapper

            import resource
            loadavg = os.getloadavg()
            psize = _resource.getpagesize()
            pid = os.getpid()
            rmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "rss")).read()) / 1024.0
            vmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "vsz")).read()) / 1024.0

            rusage = resource.getrusage(resource.RUSAGE_SELF)
            table = [["Server load (1 min):",
                      "Process ID:",
                      "Bytes per page:",
                      "CPU time used:",
                      "Resident memory:",
                      "Virtual memory:",
                      "Page faults:",
                      "Disk I/O:",
                      "Network I/O:",
                      "Context switching:"
                      ],
                     ["%g" % loadavg[0],
                      "%10d" % pid,
                      "%10d " % psize,
                      "%s (%gs)" % (utils.time_format(rusage.ru_utime), rusage.ru_utime),
                      #"%10d shared" % rusage.ru_ixrss,
                      #"%10d pages" % rusage.ru_maxrss,
                      "%10.2f MB" % rmem,
                      "%10.2f MB" % vmem,
                      "%10d hard" % rusage.ru_majflt,
                      "%10d reads" % rusage.ru_inblock,
                      "%10d in" % rusage.ru_msgrcv,
                      "%10d vol" % rusage.ru_nvcsw
                    ],
                     ["", "", "",
                      "(user: %gs)" % rusage.ru_stime,
                      "", #"%10d private" % rusage.ru_idrss,
                      "", #"%10d bytes" % (rusage.ru_maxrss * psize),
                      "%10d soft" % rusage.ru_minflt,
                      "%10d writes" % rusage.ru_oublock,
                      "%10d out" % rusage.ru_msgsnd,
                      "%10d forced" % rusage.ru_nivcsw
                      ],
                     ["", "", "", "",
                      "", #"%10d stack" % rusage.ru_isrss,
                      "",
                      "%10d swapouts" % rusage.ru_nswap,
                      "", "",
                      "%10d sigs" % rusage.ru_nsignals
                    ]
                     ]
            stable = []
            for col in table:
                stable.append([str(val).strip() for val in col])
            ftable = utils.format_table(stable, 5)
            string = ""
            for row in ftable:
                string += "\n " + "{w%s{n" % row[0] + "".join(row[1:])

            # object cache size
            cachedict = _idmapper.cache_size()
            totcache = cachedict["_total"]
            string += "\n{w Database entity (idmapper) cache usage:{n %5.2f MB (%i items)" % (totcache[1], totcache[0])
            sorted_cache = sorted([(key, tup[0], tup[1]) for key, tup in cachedict.items() if key !="_total" and tup[0] > 0],
                                    key=lambda tup: tup[2], reverse=True)
            table = [[tup[0] for tup in sorted_cache],
                     ["%5.2f MB" % tup[2] for tup in sorted_cache],
                     ["%i item(s)" % tup[1] for tup in sorted_cache]]
            ftable = utils.format_table(table, 5)
            for row in ftable:
                string += "\n  " + row[0] + row[1] + row[2]
            # get sizes of other caches
            attr_cache_info, field_cache_info, prop_cache_info = get_cache_sizes()
            #size = sum([sum([getsizeof(obj) for obj in dic.values()]) for dic in _attribute_cache.values()])/1024.0
            #count = sum([len(dic) for dic in _attribute_cache.values()])
            string += "\n{w On-entity Attribute cache usage:{n %5.2f MB (%i attrs)" % (attr_cache_info[1], attr_cache_info[0])
            string += "\n{w On-entity Field cache usage:{n %5.2f MB (%i fields)" % (field_cache_info[1], field_cache_info[0])
            string += "\n{w On-entity Property cache usage:{n %5.2f MB (%i props)" % (prop_cache_info[1], prop_cache_info[0])
        caller.msg(string)
Example #3
0
    def func(self):
        "Show list."

        caller = self.caller

        # display active processes

        if not utils.host_os_is('posix'):
            string = "Process listings are only available under Linux/Unix."
            caller.msg(string)
            return

        global _resource, _idmapper
        if not _resource:
            import resource as _resource
        if not _idmapper:
            from src.utils.idmapper import base as _idmapper

        import resource
        loadavg = os.getloadavg()
        psize = _resource.getpagesize()
        pid = os.getpid()
        rmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "rss")).read()) / 1024.0  # resident memory
        vmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "vsz")).read()) / 1024.0  # virtual memory
        pmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "%mem")).read())  # percent of resident memory to total
        rusage = resource.getrusage(resource.RUSAGE_SELF)

        # load table
        loadtable = prettytable.PrettyTable(["property", "statistic"])
        loadtable.align = 'l'
        loadtable.add_row(["Server load (1 min)", "%g" % loadavg[0]])
        loadtable.add_row(["Process ID", "%g" % pid]),
        loadtable.add_row(["Bytes per page", "%g " % psize])
        loadtable.add_row(["CPU time used (total)", "%s (%gs)" % (utils.time_format(rusage.ru_utime), rusage.ru_utime)])
        loadtable.add_row(["CPU time used (user)", "%s (%gs)" % (utils.time_format(rusage.ru_stime), rusage.ru_stime)])
        loadtable.add_row(["Memory usage","%g MB (%g%%)" % (rmem, pmem)])
        loadtable.add_row(["Virtual address space\n {x(resident+swap+caching){n", "%g MB" % vmem])
        loadtable.add_row(["Page faults", "%g hard,  %g soft, %g swapouts" % (rusage.ru_majflt, rusage.ru_minflt, rusage.ru_nswap)])
        loadtable.add_row(["Disk I/O", "%g reads, %g writes" % (rusage.ru_inblock, rusage.ru_oublock)])
        loadtable.add_row(["Network I/O", "%g in, %g out" % (rusage.ru_msgrcv, rusage.ru_msgsnd)])
        loadtable.add_row(["Context switching", "%g vol, %g forced, %g signals" % (rusage.ru_nvcsw, rusage.ru_nivcsw, rusage.ru_nsignals)])

        string = "{wServer CPU and Memory load:{n\n%s" % loadtable

        if not is_pypy:
            # Cache size measurements are not available on PyPy
            # because it lacks sys.getsizeof

            # object cache size
            cachedict = _idmapper.cache_size()
            totcache = cachedict["_total"]
            sorted_cache = sorted([(key, tup[0], tup[1]) for key, tup in cachedict.items() if key !="_total" and tup[0] > 0],
                                    key=lambda tup: tup[2], reverse=True)
            memtable = prettytable.PrettyTable(["entity name",
                                                "number",
                                                "cache (MB)",
                                                "idmapper %%"])
            memtable.align = 'l'
            for tup in sorted_cache:
                memtable.add_row([tup[0],
                                 "%i" % tup[1],
                                 "%5.2f" % tup[2],
                                 "%.2f" % (float(tup[2] / totcache[1]) * 100)])

            # get sizes of other caches
            attr_cache_info, prop_cache_info = get_cache_sizes()
            string += "\n{w Entity idmapper cache usage:{n %5.2f MB (%i items)\n%s" % (totcache[1], totcache[0], memtable)
            string += "\n{w On-entity Attribute cache usage:{n %5.2f MB (%i attrs)" % (attr_cache_info[1], attr_cache_info[0])
            string += "\n{w On-entity Property cache usage:{n %5.2f MB (%i props)" % (prop_cache_info[1], prop_cache_info[0])
            base_mem = vmem - totcache[1] - attr_cache_info[1] - prop_cache_info[1]
            string += "\n{w Base Server usage (virtmem-idmapper-attrcache-propcache):{n %5.2f MB" % base_mem

        caller.msg(string)