From 2a3b02ac1376ba84a689ea5a105f14a11a2f92b1 Mon Sep 17 00:00:00 2001 From: iipeace Date: Thu, 28 Sep 2023 23:05:11 +0900 Subject: [PATCH] ttop: Improve performance for sorting by PSS Signed-off-by: iipeace --- guider/guider.py | 259 +++++++---------------------------------------- 1 file changed, 34 insertions(+), 225 deletions(-) diff --git a/guider/guider.py b/guider/guider.py index 0779b75b..c22141ac 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "230926" +__revision__ = "230928" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -1064,26 +1064,14 @@ class ConfigMgr(object): "long", (("clockid_t", "which_clock"), ("struct timex *", "tx")), ), - "clock_adjtime32": ( - "long", - (("clockid_t", "which_clock"), ("struct old_timex32 *", "tx")), - ), "clock_getres": ( "long", (("clockid_t", "which_clock"), ("struct timespec *", "tp")), ), - "clock_getres_time32": ( - "long", - (("clockid_t", "which_clock"), ("struct old_timespec32 *", "tp")), - ), "clock_gettime": ( "long", (("clockid_t", "which_clock"), ("struct timespec *", "tp")), ), - "clock_gettime32": ( - "long", - (("clockid_t", "which_clock"), ("struct old_timespec32 *", "tp")), - ), "clock_nanosleep": ( "long", ( @@ -1093,23 +1081,10 @@ class ConfigMgr(object): ("struct timespec *", "rmtp"), ), ), - "clock_nanosleep_time32": ( - "long", - ( - ("clockid_t", "which_clock"), - ("int", "flags"), - ("struct old_timespec32 *", "rqtp"), - ("struct old_timespec32 *", "rmtp"), - ), - ), "clock_settime": ( "long", (("clockid_t", "which_clock"), ("const struct timespec *", "tp")), ), - "clock_settime32": ( - "long", - (("clockid_t", "which_clock"), ("struct old_timespec32 *", "tp")), - ), "clone": ( "long", ( @@ -1439,17 +1414,6 @@ class ConfigMgr(object): ("u32", "val3"), ), ), - "futex_time32": ( - "long", - ( - ("u32 *", "uaddr"), - ("int", "op"), - ("u32", "val"), - ("struct old_timespec32 *", "utime"), - ("u32 *", "uaddr2"), - ("u32", "val3"), - ), - ), "futimesat": ( "long", ( @@ -1458,14 +1422,6 @@ class ConfigMgr(object): ("struct old_timeval *", "utimes"), ), ), - "futimesat_time32": ( - "long", - ( - ("unsigned int", "dfd"), - ("const char *", "filename"), - ("struct old_timeval32 *", "t"), - ), - ), "get_kernel_syms": ("long", (("struct kernel_sym *", "table"))), "get_mempolicy": ( "long", @@ -1613,7 +1569,6 @@ class ConfigMgr(object): ), "getuid": ("long", ()), "getuid16": ("long", ()), - "getuid32": ("long", ()), "getxattr": ( "long", ( @@ -1657,16 +1612,6 @@ class ConfigMgr(object): ("struct timespec *", "timeout"), ), ), - "io_getevents_time32": ( - "long", - ( - ("__u32", "ctx_id"), - ("__s32", "min_nr"), - ("__s32", "nr"), - ("struct io_event *", "events"), - ("struct old_timespec32 *", "timeout"), - ), - ), "io_pgetevents": ( "long", ( @@ -1678,17 +1623,6 @@ class ConfigMgr(object): ("const struct __aio_sigset *", "sig"), ), ), - "io_pgetevents_time32": ( - "long", - ( - ("aio_context_t", "ctx_id"), - ("long", "min_nr"), - ("long", "nr"), - ("struct io_event *", "events"), - ("struct old_timespec32 *", "timeout"), - ("const struct __aio_sigset *", "sig"), - ), - ), "io_setup": ( "long", (("unsigned", "nr_reqs"), ("aio_context_t *", "ctx")), @@ -2081,16 +2015,6 @@ class ConfigMgr(object): ("const struct timespec *", "abs_timeout"), ), ), - "mq_timedreceive_time32": ( - "long", - ( - ("mqd_t", "mqdes"), - ("char *", "u_msg_ptr"), - ("unsigned int", "msg_len"), - ("unsigned int *", "u_msg_prio"), - ("const struct old_timespec32 *", "u_abs_timeout"), - ), - ), "mq_timedsend": ( "long", ( @@ -2101,16 +2025,6 @@ class ConfigMgr(object): ("const struct timespec *", "abs_timeout"), ), ), - "mq_timedsend_time32": ( - "long", - ( - ("mqd_t", "mqdes"), - ("const char *", "u_msg_ptr"), - ("unsigned int", "msg_len"), - ("unsigned int", "msg_prio"), - ("const struct old_timespec32 *", "u_abs_timeout"), - ), - ), "mq_unlink": ("long", (("const char *", "name"),)), "mremap": ( "long", @@ -2167,13 +2081,6 @@ class ConfigMgr(object): "long", (("struct timespec *", "rqtp"), ("struct timespec *", "rmtp")), ), - "nanosleep_time32": ( - "long", - ( - ("struct old_timespec32 *", "rqtp"), - ("struct old_timespec32 *", "rmtp"), - ), - ), "newfstat": ( "long", (("unsigned int", "fd"), ("struct stat *", "statbuf")), @@ -2360,15 +2267,6 @@ class ConfigMgr(object): ("const sigset_t *", "sigmask"), ), ), - "ppoll_time32": ( - "long", - ( - ("struct pollfd *", "fds"), - ("unsigned int", "nfds"), - ("struct old_timespec *", "tmo_p"), - ("const sigset_t *", "sigmask"), - ), - ), "prctl": ( "long", ( @@ -2451,17 +2349,6 @@ class ConfigMgr(object): ("void *", "sigmask"), ), ), - "pselect6_time32": ( - "long", - ( - ("int", "nfds"), - ("fd_set *", "readfds"), - ("fd_set *", "writefds"), - ("fd_set *", "exceptfds"), - ("struct old_timespec32 *", ""), - ("void *", "sigmask"), - ), - ), "ptrace": ( "long", ( @@ -2588,16 +2475,6 @@ class ConfigMgr(object): ("struct timespec *", "timeout"), ), ), - "recvmmsg_time32": ( - "long", - ( - ("int", "fd"), - ("struct mmsghdr *", "msg"), - ("unsigned int", "vlen"), - ("unsigned", "flags"), - ("struct old_timespec32 *", "timeout"), - ), - ), "recvmsg": ( "long", ( @@ -2703,15 +2580,6 @@ class ConfigMgr(object): ("size_t", "sigsetsize"), ), ), - "rt_sigtimedwait_time32": ( - "long", - ( - ("const sigset_t *", "uthese"), - ("siginfo_t *", "uinfo"), - ("const struct old_timespec32 *", "uts"), - ("size_t", "sigsetsize"), - ), - ), "rt_tgsigqueueinfo": ( "long", ( @@ -2749,10 +2617,6 @@ class ConfigMgr(object): "long", (("pid_t", "pid"), ("struct timespec *", "interval")), ), - "sched_rr_get_interval_time32": ( - "long", - (("pid_t", "pid"), ("struct old_timespec32 *", "interval")), - ), "sched_setaffinity": ( "long", ( @@ -2840,15 +2704,6 @@ class ConfigMgr(object): ("const struct timespec *", "timeout"), ), ), - "semtimedop_time32": ( - "long", - ( - ("int", "semid"), - ("struct sembuf *", "sops"), - ("unsigned", "nsops"), - ("const struct old_timespec32 *", "timeout"), - ), - ), "send": ( "long", ( @@ -3140,7 +2995,6 @@ class ConfigMgr(object): ), ), "stime": ("long", (("old_time_t *", "tptr"),)), - "stime32": ("long", (("old_time32_t *", "tptr"),)), "swapoff": ("long", (("const char *", "specialfile"),)), "swapon": ( "long", @@ -3203,7 +3057,6 @@ class ConfigMgr(object): ), "tgkill": ("long", (("int", "tgid"), ("int", "pid"), ("int", "sig"))), "time": ("long", (("old_time_t *", "tloc"),)), - "time32": ("long", (("old_time32_t *", "tloc"),)), "timer_create": ( "long", ( @@ -3218,13 +3071,6 @@ class ConfigMgr(object): "long", (("timer_t", "timer_id"), ("struct itimerspec *", "setting")), ), - "timer_gettime32": ( - "long", - ( - ("timer_t", "timer_id"), - ("struct old_itimerspec32 *", "setting"), - ), - ), "timer_settime": ( "long", ( @@ -3234,24 +3080,11 @@ class ConfigMgr(object): ("struct itimerspec *", "old_setting"), ), ), - "timer_settime32": ( - "long", - ( - ("timer_t", "timer_id"), - ("int", "flags"), - ("struct old_itimerspec32 *", "new"), - ("struct old_itimerspec32 *", "old"), - ), - ), "timerfd_create": ("long", (("int", "clockid"), ("int", "flags"))), "timerfd_gettime": ( "long", (("int", "ufd"), ("struct itimerspec *", "otmr")), ), - "timerfd_gettime32": ( - "long", - (("int", "ufd"), ("struct old_itimerspec32 *", "otmr")), - ), "timerfd_settime": ( "long", ( @@ -3261,15 +3094,6 @@ class ConfigMgr(object): ("struct itimerspec *", "otmr"), ), ), - "timerfd_settime32": ( - "long", - ( - ("int", "ufd"), - ("int", "flags"), - ("const struct old_itimerspec32 *", "utmr"), - ("struct old_itimerspec32 *", "otmr"), - ), - ), "times": ("long", (("struct tms *", "tbuf"),)), "tkill": ("long", (("int", "pid"), ("int", "sig"))), "truncate": ("long", (("const char *", "path"), ("long", "length"))), @@ -3294,10 +3118,6 @@ class ConfigMgr(object): "long", (("const char *", "filename"), ("struct utimbuf *", "times")), ), - "utime32": ( - "long", - (("const char *", "filename"), ("struct old_utimbuf32 *", "t")), - ), "utimensat": ( "long", ( @@ -3307,23 +3127,10 @@ class ConfigMgr(object): ("int", "flags"), ), ), - "utimensat_time32": ( - "long", - ( - ("unsigned int", "dfd"), - ("const char *", "filename"), - ("struct old_timespec32 *", "t"), - ("int", "flags"), - ), - ), "utimes": ( "long", (("const char *", "filename"), ("struct old_timeval *", "utimes")), ), - "utimes_time32": ( - "long", - (("const char *", "filename"), ("struct old_timeval32 *", "t")), - ), "vfork": ("long", ()), "vhangup": ("long", ()), "vmsplice": ( @@ -33794,8 +33601,6 @@ def getCmdList(): @staticmethod def printHelp(force=False, isExit=True): - printPipe = SysMgr.printPipe - # help # if force or len(sys.argv) <= 1 or SysMgr.isHelpMode(): # get environment variable from launcher # @@ -33862,7 +33667,7 @@ def printHelp(force=False, isExit=True): -z set CPU affinity -Y set sched [ POLICY:PRIO|TIME{:TID|COMM:CONT} - CLASS:{{WHICH:}}PRIO:TID|COMM ] + CLASS:{WHICH:}PRIO:TID|COMM ] -v verbose """ @@ -37978,7 +37783,7 @@ def _getDesc(s, t=0): -o set output path -J print in JSON format -m set terminal size - -q set environment variables + -q set environment variables -v verbose """ @@ -38154,7 +37959,7 @@ def _getDesc(s, t=0): [ p:pipe | d:demangle | D:DWARF | e:encode ] -I set input path -g set function filter - -q set environment variables + -q set environment variables -v verbose """ ) @@ -39800,11 +39605,9 @@ def _getDesc(s, t=0): + """ Options: -o set output path - -q set environment variables + -q set environment variables -v verbose - """.format( - cmd, mode - ) + """ ) helpStr += """ @@ -39825,11 +39628,9 @@ def _getDesc(s, t=0): + """ Options: -o set output path - -q set environment variables + -q set environment variables -v verbose - """.format( - cmd, mode - ) + """ ) helpStr += """ @@ -39860,11 +39661,9 @@ def _getDesc(s, t=0): Options: -o set output path -g set target file - -q set environment variables + -q set environment variables -v verbose - """.format( - cmd, mode - ) + """ ) helpStr += """ @@ -41110,7 +40909,7 @@ def _getDesc(s, t=0): SysMgr.printLogo() # print help # - printPipe(helpStr) + SysMgr.printPipe(helpStr) else: helpStr = ( @@ -41139,7 +40938,7 @@ def _getDesc(s, t=0): SysMgr.setStream() # print help # - printPipe(helpStr) + SysMgr.printPipe(helpStr) if isExit: sys.exit(0) @@ -50573,6 +50372,7 @@ def checkCmdMode(): # HELPTEST MODE # elif SysMgr.checkMode("helptest"): + SysMgr.loggingEnable = False SysMgr.streamEnable = True for i in SysMgr.getCmdSet(): SysMgr.origArgs = sys.argv = [ @@ -56088,11 +55888,11 @@ def _printCpuInfo(cpulist, core): SysMgr.printPipe( ( "[ CPU(%s) ]\n" - "- frequency: [ %s ]\n" + "- cur_frequency: [ %s ]\n" "- min_frequency: [ %s ]\n" "- max_frequency: [ %s ]\n" "- governor: [ %s ]\n" - "- oneline: [ %s ]\n\n" + "- online: [ %s ]\n\n" ) % ( core, @@ -97532,7 +97332,7 @@ def mergeSymTable(self, force=False, onlyFunc=True, removeOrig=False): continue # skip symbols except for function # - if onlyFunc and item["type"] != "FUNC": + if onlyFunc and not item["type"] in ("FUNC", "SECTION"): continue # update symbol length # @@ -103221,14 +103021,18 @@ def _addEntryOldState(cmd, args, isExtended=False): ) ) - if nrItems == 0 and isTarget: - printer(" None") + if nrItems == 0 and isTarget: + printer(" None") + nrPrint = 0 for i in xrange(nrItems): fd.seek(sh_offset + i * sh_entsize) + dyndata = fd.read(sh_entsize) + if not dyndata: + break d_tag, d_un = struct.unpack( - "II" if self.is32Bit else "QQ", fd.read(sh_entsize) + "II" if self.is32Bit else "QQ", dyndata ) # NULL termination # @@ -103269,7 +103073,12 @@ def _addEntryOldState(cmd, args, isExtended=False): else: printer("%016x %20s %1s" % (d_tag, d_tag, hex(d_un))) + nrPrint += 1 + if printable: + if nrPrint == 0 and isTarget: + printer(" None") + printer("%s\n\n\n" % oneLineLoc) @@ -121314,13 +121123,11 @@ def _printEventWarning(func): next_stop = self.threadData[next_id]["stop"] # update the CPU scheduling priority for thread to highest one # - if self.threadData[prev_id]["pri"] == "?" or long( - self.threadData[prev_id]["pri"] - ) > long(d["prev_prio"]): + prevPri = self.threadData[prev_id]["pri"] + if prevPri == "?" or long(prevPri) > long(d["prev_prio"]): self.threadData[prev_id]["pri"] = d["prev_prio"] - if self.threadData[next_id]["pri"] == "?" or long( - self.threadData[next_id]["pri"] - ) > long(d["next_prio"]): + nextPri = self.threadData[next_id]["pri"] + if nextPri == "?" or long(nextPri) > long(d["next_prio"]): self.threadData[next_id]["pri"] = d["next_prio"] # update CPU time by futex # @@ -132121,6 +131928,8 @@ def _memFactorPG(stat): and "user" in self.prevProcData[idx] ): value["user"] = self.prevProcData[idx]["user"] + elif self.isKernelThread(idx): + raise Exception("kernel thread") else: SysMgr.sysInstance.saveUserInfo() userData = SysMgr.sysInstance.userData