Skip to content

Commit

Permalink
fetop: Change item colors
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Jun 14, 2024
1 parent 9c3bda9 commit 45baaa6
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "240613"
__revision__ = "240614"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -34317,7 +34317,7 @@ def clearCommCache():
SysMgr.commCache = {}

@staticmethod
def getComm(pid, cache=False, save=False, commCache=True):
def getComm(pid, cache=False, save=False, commCache=True, default=None):
if commCache and pid in SysMgr.commCache:
return SysMgr.commCache[pid]

Expand Down Expand Up @@ -34348,7 +34348,7 @@ def getComm(pid, cache=False, save=False, commCache=True):
except:
return None

comm = None
comm = default
commPath = "%s/%s/comm" % (SysMgr.procPath, pid)

try:
Expand Down Expand Up @@ -44512,7 +44512,7 @@ def _checker():
item.encode("latin-1"),
)
if ret < 0:
SysMgr.printErr(
SysMgr.printWarn(
"failed to call fanotify_mark for '%s' because %s"
% (item, SysMgr.getErrReason())
)
Expand Down Expand Up @@ -62113,9 +62113,6 @@ def _printSummary(fileSummary={}, procSummary={}, final=False):
SysMgr.getAvailMemInfo(),
)

if not SysMgr.outPath and not SysMgr.streamEnable:
SysMgr.clearScreen()

if final:
timename = "Runtime"
runtime = SysMgr.getRuntime()
Expand Down Expand Up @@ -62166,18 +62163,25 @@ def _printSummary(fileSummary={}, procSummary={}, final=False):
outStr += "{0:<32} {1:<32} {2:<32}\n{3:1}\n".format(
"File", "Proc", "Attr", twoLine
)

watchList = SysMgr.fileWatchTotalList

for path, vals in sorted(
fileSummary.items(), key=lambda e: e[1]["TOTAL"], reverse=True
):
if not path:
continue

full = path.rsplit("/", 1)
if len(full) == 2:
path = full[0] + "/" + convColor(full[1], "GREEN")

outStr += path + "\n"
for proc, subvals in vals.items():
if proc == "TOTAL":
continue

outStr += "{0:32} {1:32}".format(" ", proc)
outStr += "{0:32} {1:32} ".format(" ", proc)

# merge events #
evtList = []
Expand All @@ -62186,31 +62190,29 @@ def _printSummary(fileSummary={}, procSummary={}, final=False):
):
evtList.append(
"%s(%s)"
% (attr, convColor(convNum(cnt), "YELLOW"))
% (attr, convColor(convNum(cnt), "WARNING"))
)

# check skip condition for event merge #
if final or not isTopMode or not SysMgr.outPath:
continue

try:
SysMgr.fileWatchTotalList[path]["TOTAL"] += cnt
watchList[path]["TOTAL"] += cnt
except SystemExit:
sys.exit(0)
except:
SysMgr.fileWatchTotalList.setdefault(path, {})
SysMgr.fileWatchTotalList[path]["TOTAL"] = cnt
watchList.setdefault(path, {})
watchList[path]["TOTAL"] = cnt

try:
SysMgr.fileWatchTotalList[path][proc][attr] += cnt
watchList[path][proc][attr] += cnt
except SystemExit:
sys.exit(0)
except:
SysMgr.fileWatchTotalList.setdefault(path, {})
SysMgr.fileWatchTotalList[path].setdefault(
proc, {}
)
SysMgr.fileWatchTotalList[path][proc][attr] = cnt
watchList.setdefault(path, {})
watchList[path].setdefault(proc, {})
watchList[path][proc][attr] = cnt

evtStr = "|".join(evtList)
outStr += "%s\n" % evtStr
Expand All @@ -62227,6 +62229,13 @@ def _printSummary(fileSummary={}, procSummary={}, final=False):
else:
SysMgr.addProcBuffer(outStr + "\n")
else:
# check user input #
SysMgr.waitUserInput(0.000001, msg="DEFAULT")

# clear screen #
if not SysMgr.streamEnable:
SysMgr.clearScreen()

for line in outStr.split("\n"):
if not SysMgr.addPrint(line + "\n"):
break
Expand All @@ -62243,6 +62252,7 @@ def _printSummary(fileSummary={}, procSummary={}, final=False):
fileSummary.clear()
procSummary.clear()
SysMgr.clearPrint()

return

outStr = ""
Expand Down Expand Up @@ -62562,11 +62572,14 @@ def _alarmHandler(signum, frame):
# fanotify #
elif len(item) in (4, 6):
epath, events, epid, ecomm = item[:4]
if not ecomm:
ecomm = "?"

if len(item) == 6:
ppid, pcomm = item[4:6]
else:
ppid = pcomm = None
ppid = SysMgr.getPpid(epid)
pcomm = SysMgr.getComm(ppid)

# check file condition #
if targetInfo:
Expand Down Expand Up @@ -62600,7 +62613,11 @@ def _alarmHandler(signum, frame):
else:
procInfo = "%s(%s)" % (ecomm, epid)
if ppid:
procInfo += " in %s(%s)" % (pcomm, ppid)
procInfo = "%s(%s)->%s" % (
pcomm,
ppid,
procInfo,
)

if top or SysMgr.outPath:
# get event list #
Expand Down

0 comments on commit 45baaa6

Please sign in to comment.