Example #1
0
    def func(self):
        "Show times."

        table = [["Current server uptime:",
                  "Total server running time:",
                  "Total in-game time (realtime x %g):" % (gametime.TIMEFACTOR),
                  "Server time stamp:"
                  ],
                 [utils.time_format(time.time() - SESSIONS.server.start_time, 3),
                  utils.time_format(gametime.runtime(format=False), 2),
                  utils.time_format(gametime.gametime(format=False), 2),
                  datetime.datetime.now()
                  ]]
        if utils.host_os_is('posix'):
            loadavg = os.getloadavg()
            table[0].append("Server load (per minute):")
            table[1].append("%g" % (loadavg[0]))
        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:])
        self.caller.msg(string)
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."
            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()) / 1000.0  # resident memory
        vmem = float(
            os.popen('ps -p %d -o %s | tail -1' %
                     (pid, "vsz")).read()) / 1000.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)

        if "mem" in self.switches:
            caller.msg(
                "Memory usage: RMEM: {w%g{n MB (%g%%), VMEM (res+swap+cache): {w%g{n MB."
                % (rmem, pmem, vmem))
            return

        if "flushmem" in self.switches:
            caller.msg(
                "Flushed object idmapper cache. Python garbage collector recovered memory from %i objects."
                % _idmapper.flush_cache())
            return

        # 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
            total_num, cachedict = _idmapper.cache_size()
            sorted_cache = sorted(
                [(key, num) for key, num in cachedict.items() if num > 0],
                key=lambda tup: tup[1],
                reverse=True)
            memtable = prettytable.PrettyTable(
                ["entity name", "number", "idmapper %%"])
            memtable.align = 'l'
            for tup in sorted_cache:
                memtable.add_row([
                    tup[0],
                    "%i" % tup[1],
                    "%.2f" % (float(tup[1]) / total_num * 100)
                ])

            # get sizes of other caches
            string += "\n{w Entity idmapper cache:{n %i items\n%s" % (
                total_num, memtable)

        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()) / 1000.0  # resident memory
        vmem = float(os.popen('ps -p %d -o %s | tail -1' % (pid, "vsz")).read()) / 1000.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)

        if "mem" in self.switches:
            caller.msg("Memory usage: RMEM: {w%g{n MB (%g%%), VMEM (res+swap+cache): {w%g{n MB." % (rmem, pmem, vmem))
            return

        if "flushmem" in self.switches:
            caller.msg("Flushed object idmapper cache. Python garbage collector recovered memory from %i objects." %  _idmapper.flush_cache())
            return

        # 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
            total_num, cachedict = _idmapper.cache_size()
            sorted_cache = sorted([(key, num) for key, num in cachedict.items() if num > 0],
                                    key=lambda tup: tup[1], reverse=True)
            memtable = prettytable.PrettyTable(["entity name",
                                                "number",
                                                "idmapper %%"])
            memtable.align = 'l'
            for tup in sorted_cache:
                memtable.add_row([tup[0],
                                 "%i" % tup[1],
                                 "%.2f" % (float(tup[1]) / total_num * 100)])

            # get sizes of other caches
            string += "\n{w Entity idmapper cache:{n %i items\n%s" % (total_num, memtable)

        caller.msg(string)
Example #4
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 #5
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)