-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ctop: Add getpkg/pkglist command for UDS/TCP server mode
Signed-off-by: iipeace <[email protected]>
- Loading branch information
Showing
1 changed file
with
135 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
__credits__ = "Peace Lee" | ||
__license__ = "GPLv2" | ||
__version__ = "3.9.8" | ||
__revision__ = "241120" | ||
__revision__ = "241121" | ||
__maintainer__ = "Peace Lee" | ||
__email__ = "[email protected]" | ||
__repository__ = "https://github.com/iipeace/guider" | ||
|
@@ -28477,6 +28477,7 @@ class SysMgr(object): | |
- DRAW*|RemotePath{|Option} | ||
- DUMP/SYSDUMP{|Option} | ||
- GETPEAK | ||
- GETPKG/PKGLIST{|Option} | ||
- JOBS | ||
- KILL/TKILL|ID/COMM | ||
- LOGCAT/LOGMON{|Option} | ||
|
@@ -41529,7 +41530,7 @@ def _getDesc(s, t=0): | |
|
||
- {2:1} {3:1} and operate server using TCP/UDS protocols | ||
# {0:1} {1:1} -q UDSSERVER:/tmp/guider.socket, NRMAXJOB:10 | ||
# {0:1} {1:1} -q TCPSERVER:55555, NRMAXJOB:10 | ||
# {0:1} {1:1} -q TCPSERVER:55555, NRMAXJOB:10, NOLIMITPATH | ||
# {0:1} {1:1} -q TCPSERVER:"192.169.0.0.1:55555", NRMAXJOB:10 | ||
|
||
See the top COMMAND help for more examples. | ||
|
@@ -43029,6 +43030,10 @@ def _getDesc(s, t=0): | |
# {0:1} {1:1} -v -q FORCEWARN | ||
# {0:1} {1:1} -q PRINTPKGLIST | ||
|
||
- Print package list | ||
# {0:1} {1:1} -q GETPKGLIST | ||
# {0:1} {1:1} -q GETPKGLIST -J | ||
|
||
- {2:1} for specific processes | ||
# {0:1} {1:1} -g a.out, surfaceflinger | ||
# {0:1} {1:1} -g com.android.car -q TARGETCMD | ||
|
@@ -46968,7 +46973,7 @@ def _getDesc(s, t=0): | |
|
||
- {2:1} and monitor server using other protocols | ||
# {0:1} {1:1} -q UDSSERVER:/tmp/guider.socket, NRMAXJOB:10 | ||
# {0:1} {1:1} -q TCPSERVER:55555, NRMAXJOB:10 | ||
# {0:1} {1:1} -q TCPSERVER:55555, NRMAXJOB:10, NOLIMITPATH | ||
# {0:1} {1:1} -q TCPSERVER:"192.169.0.0.1:55555", NRMAXJOB:10 | ||
|
||
- {2:1} with specific local address | ||
|
@@ -50567,15 +50572,17 @@ def _handleCmd(connObj, cmd, cliProc): | |
# set default handling environment # | ||
SysMgr.setSignal(SysMgr.commSig, signal.SIG_IGN) | ||
SysMgr.clearExitFunc() | ||
origOutPath = SysMgr.outPath | ||
SysMgr.outPath = None | ||
SysMgr.encodeEnable = False | ||
SysMgr.colorEnable = False | ||
SysMgr.printEnable = True | ||
SysMgr.intervalEnable = 1 | ||
SysMgr.streamEnable = True | ||
SysMgr.eventCommandList = eventCommandList | ||
SysMgr.progressEnable = False | ||
origOutPath = SysMgr.outPath | ||
if origOutPath: | ||
origOutPath = SysMgr.convFullPath(origOutPath) | ||
SysMgr.outPath = None | ||
|
||
# define a socket monitor function # | ||
def _monitorConn(connObj): | ||
|
@@ -50633,13 +50640,15 @@ def _printExecutedCmd(): | |
"download", | ||
"dump", | ||
"getpeak", | ||
"getpkg", | ||
"jobs", | ||
"kill", | ||
"logcat", | ||
"logmon", | ||
"memmon", | ||
"memprof", | ||
"memtop", | ||
"pkglist", | ||
"remove", | ||
"resmon", | ||
"restop", | ||
|
@@ -50736,14 +50745,25 @@ def _getPacket(fd): | |
except: | ||
yield None | ||
|
||
# remove files # | ||
# handle files # | ||
for d in cmdOpt: | ||
# validate path # | ||
if not "NOLIMITPATH" in SysMgr.environList: | ||
if not origOutPath: | ||
_printErr("no output path in Guider") | ||
sys.exit(-1) | ||
elif not d.startswith(origOutPath): | ||
_printErr("'%s' is not in '%s'" % (d, origOutPath)) | ||
sys.exit(-1) | ||
|
||
# remove # | ||
if mainCmd == "remove": | ||
flist = UtilMgr.getFileList( | ||
[d], sort=True, exceptDir=False | ||
) | ||
SysMgr.removeFiles(flist) | ||
connObj.write("\n".join(flist)) | ||
# download # | ||
elif mainCmd == "download": | ||
try: | ||
fd = open(d, "rb") | ||
|
@@ -50786,6 +50806,16 @@ def _getPacket(fd): | |
for d in cmdOpt: | ||
SysMgr.printDirs(d) | ||
|
||
elif mainCmd in ("getpkg", "pkglist"): | ||
# start sending stats in JSON # | ||
SysMgr.jsonEnable = mainCmd == "pkglist" | ||
SysMgr.printFd = connObj | ||
SysMgr.showAll = True | ||
|
||
# get package list # | ||
SysMgr.addEnvironVar("GETPKGLIST") | ||
SysMgr.doHeapProfRec() | ||
|
||
elif mainCmd in ("memtop", "memmon"): | ||
if not cmdOpt: | ||
_printErr("no target info") | ||
|
@@ -50795,7 +50825,7 @@ def _getPacket(fd): | |
SysMgr.jsonEnable = mainCmd == "memmon" | ||
SysMgr.printFd = connObj | ||
|
||
# start monitoring binder calls # | ||
# start monitoring memory # | ||
SysMgr.addEnvironVar("MEMTOP") | ||
SysMgr.doHeapProfRec() | ||
|
||
|
@@ -59271,7 +59301,11 @@ def _printWarn(warn, always=False): | |
if SysMgr.jsonEnable: | ||
|
||
def _printRes(statusDict): | ||
print(UtilMgr.convDict2Str(statusDict, pretty=False)) | ||
if "GETPKGLIST" in SysMgr.environList: | ||
printFunc = SysMgr.printPipe | ||
else: | ||
printFunc = print | ||
printFunc(UtilMgr.convDict2Str(statusDict, pretty=False)) | ||
|
||
SysMgr.addExitFunc(_printRes, [statusDict]) | ||
|
||
|
@@ -59554,11 +59588,32 @@ def _waitThreshold(pids, cond, timing, target, sig=False): | |
targetstr, | ||
) | ||
|
||
# pkglist format # | ||
pkgConfig = """ | ||
buffers { | ||
size_kb: 63488 | ||
} | ||
|
||
duration_ms: 0 | ||
write_into_file: true | ||
flush_timeout_ms: 30000 | ||
flush_period_ms: 604800000 | ||
data_sources { | ||
config { | ||
name: "android.packages_list" | ||
} | ||
} | ||
""" | ||
|
||
# set config # | ||
term = False | ||
if "JAVADUMP" in SysMgr.environList: | ||
config = javaConfig | ||
elif "ATRACE" in SysMgr.environList: | ||
config = atraceConfig | ||
elif "GETPKGLIST" in SysMgr.environList: | ||
config = pkgConfig | ||
term = True | ||
else: | ||
config = heapConfig | ||
statusDict["javadump"] = javaTarget | ||
|
@@ -59718,6 +59773,9 @@ def _waitTask(pid): | |
_waitTask(recPid) | ||
elif stopRss: | ||
pass | ||
elif term: | ||
# wait for perfetto # | ||
time.sleep(0.5) | ||
else: | ||
signal.pause() | ||
except: | ||
|
@@ -59730,8 +59788,8 @@ def _waitTask(pid): | |
SysMgr.sendSignalProcs(signal.SIGINT, [recPid], verb=False) | ||
|
||
# check heapprofd processes # | ||
pids = SysMgr.getTids("heapprofd", False, True) | ||
if not pids: | ||
dlist = True if term else SysMgr.getTids("heapprofd", False, True) | ||
if not dlist: | ||
_printWarn( | ||
"no running heapprofd, check below commands", True | ||
) | ||
|
@@ -60353,6 +60411,44 @@ def _getLine(scripts): | |
yield idx, None | ||
idx += 1 | ||
|
||
def _convPkgList(p, pkglist): | ||
pname = p.get("name") | ||
uid = p.get("uid") | ||
debuggable = p.get("debuggable") | ||
profileable = p.get("profileable_from_shell") | ||
versioncode = p.get("version_code") | ||
pinfo = ( | ||
"%s(%s): debuggable(%s), " | ||
"profileable(%s), " | ||
"vercode(%s)" | ||
) % ( | ||
pname, | ||
uid, | ||
( | ||
convColor(debuggable, "GREEN", force=True) | ||
if debuggable == "true" | ||
else debuggable | ||
), | ||
( | ||
convColor(profileable, "GREEN", force=True) | ||
if profileable == "true" | ||
else profileable | ||
), | ||
versioncode, | ||
) | ||
pkglist.append(pinfo) | ||
|
||
# define system info save function # | ||
def _saveSysInfo(pstr): | ||
for s in pstr.split("\n"): | ||
s = s.split('": ', 1) | ||
if len(s) != 2: | ||
continue | ||
s = [a.strip(' ",') for a in s] | ||
if s[1] in ("[", "{"): | ||
continue | ||
SysMgr.addEnvironVar("SYSINFO", s[0] + " " + s[1]) | ||
|
||
# parse lines # | ||
for idx, l in _getLine(scripts): | ||
try: | ||
|
@@ -60438,16 +60534,28 @@ def _getLine(scripts): | |
if totalLength: | ||
UtilMgr.deleteProgress() | ||
|
||
# define system info save function # | ||
def _saveSysInfo(pstr): | ||
for s in pstr.split("\n"): | ||
s = s.split('": ', 1) | ||
if len(s) != 2: | ||
continue | ||
s = [a.strip(' ",') for a in s] | ||
if s[1] in ("[", "{"): | ||
continue | ||
SysMgr.addEnvironVar("SYSINFO", s[0] + " " + s[1]) | ||
# print package list # | ||
if "GETPKGLIST" in SysMgr.environList: | ||
pkgList = packets.get("packages_list", {}).get("packages", []) | ||
|
||
if SysMgr.jsonEnable: | ||
pkgDict = {} | ||
|
||
for p in pkgList: | ||
name = p.pop("name") | ||
pkgDict[name] = p | ||
|
||
statusDict["pkgList"] = pkgDict | ||
else: | ||
pkglist = [] | ||
|
||
# convert package list # | ||
for p in pkgList: | ||
_convPkgList(p, pkglist) | ||
|
||
SysMgr.printPipe("\n".join(pkglist)) | ||
|
||
return | ||
|
||
# process meta info # | ||
for x in ("trace_config", "packages_list", "system_info"): | ||
|
@@ -60487,37 +60595,14 @@ def _saveSysInfo(pstr): | |
packets[x].get("packages", []), | ||
key=lambda x: x.get("name", ""), | ||
): | ||
pname = p.get("name") | ||
uid = p.get("uid") | ||
debuggable = p.get("debuggable") | ||
profileable = p.get("profileable_from_shell") | ||
versioncode = p.get("version_code") | ||
pinfo = ( | ||
"%s(%s): debuggable(%s), " | ||
"profileable(%s), " | ||
"vercode(%s)" | ||
) % ( | ||
pname, | ||
uid, | ||
( | ||
convColor(debuggable, "GREEN", force=True) | ||
if debuggable == "true" | ||
else debuggable | ||
), | ||
( | ||
convColor(profileable, "GREEN", force=True) | ||
if profileable == "true" | ||
else profileable | ||
), | ||
versioncode, | ||
) | ||
pkglist.append(pinfo) | ||
# convert package list # | ||
_convPkgList(p, pkglist) | ||
|
||
# print package info # | ||
if ( | ||
not printPkgList | ||
and targetPkgs | ||
and UtilMgr.isValidStr(pname, targetPkgs) | ||
and UtilMgr.isValidStr(p.get("name"), targetPkgs) | ||
): | ||
SysMgr.printInfo(pkglist[-1], color=False) | ||
|
||
|
@@ -136289,8 +136374,12 @@ def printMemDumpInterval(): | |
|
||
# parse items and summarize them # | ||
for idx, d in enumerate(SysMgr.memDumpIntData): | ||
if not d: | ||
continue | ||
|
||
for n, v in d.items(): | ||
jsonObj = SysMgr.parseMemDump(v) | ||
print(jsonObj) | ||
|
||
@staticmethod | ||
def printRssInterval(): | ||
|