TOTAL PSS: 24492 TOTAL RSS: 87324 TOTAL SWAP PSS: 4063 中我只想要TOTAL PSS
时间: 2024-02-10 12:12:19 浏览: 19
你可以在 `excecmd` 函数中修改命令字符串,只保留 `TOTAL PSS` 部分的输出,可以这样修改:
```python
if 'Windows' in platform.system():
cmd = "adb shell dumpsys meminfo %s |findstr \"TOTAL PSS:\""
else:
cmd = "adb shell dumpsys meminfo %s |grep \"TOTAL PSS:\""
```
这样,`excecmd` 函数只会返回 `TOTAL PSS:` 部分的输出,而不包括 `TOTAL RSS:` 和 `TOTAL SWAP PSS:`。然后在 `get_mem` 函数中,将提取出来的 `pss1` 转换为整数即可:
```python
for proc in procs:
pss1 = int(excecmd(cmd % proc)[1].split()[2])
pss.append(pss1)
pss = max_avg(pss)[2]
result["pss"] = pss
```
这样就可以只返回 `TOTAL PSS` 的值了。
相关问题
TOTAL PSS: 24492 TOTAL RSS: 87324 TOTAL SWAP PSS: 4063 转换成字典
可以将这些数据转换为一个Python字典,格式如下:
```
{
"TOTAL PSS": 24492,
"TOTAL RSS": 87324,
"TOTAL SWAP PSS": 4063
}
```
您可以使用以下代码将其转换:
```python
data = "TOTAL PSS: 24492 TOTAL RSS: 87324 TOTAL SWAP PSS: 4063"
stats = {}
for stat in data.split():
key, value = stat.split(":")
stats[key] = int(value)
print(stats)
```
meminfo 中 TOTAL PSS TOTAL RSS TOTAL SWAP PSS
这些是用于描述 Android 系统内存使用情况的指标,其中 TOTAL PSS 表示进程的私有和共享内存加上系统的共享库占用的内存,TOTAL RSS 表示进程的私有内存加上共享内存,TOTAL SWAP PSS 表示被交换到磁盘上的内存大小。