不仅如此,要求仅使用一次adb命令,使用python解析这次返回的结果
时间: 2024-03-05 22:53:53 浏览: 11
好的,可以使用下面的 Python 代码来实现:
```python
import subprocess
import re
# 执行 adb 命令并获取输出
output = subprocess.check_output(['adb', 'shell', 'dumpsys', 'gfxinfo', 'com.ss.android.article.news', 'framestats'])
# 正则表达式匹配 Profile data 和 Janky frames
profile_data_pattern = re.compile(r'.*Profile data in ms:\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+).*')
janky_frames_pattern = re.compile(r'.*Janky frames:\s+(\d+)\s+\((\d+\.\d+)%\).*')
# 解析输出并提取指标
profile_data_match = profile_data_pattern.match(output.decode())
if profile_data_match:
profile_data = [float(x) for x in profile_data_match.groups()]
print('Profile data in ms:', profile_data)
else:
print('Failed to match profile data')
janky_frames_match = janky_frames_pattern.match(output.decode())
if janky_frames_match:
janky_frames = int(janky_frames_match.group(1))
print('Janky frames:', janky_frames)
else:
print('Failed to match janky frames')
```
这个 Python 代码只执行了一次 adb 命令,并使用正则表达式匹配输出中的 Profile data 和 Janky frames 两个指标。最后输出解析结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)