ifuse挂载后,在python代码中访问iOS沙盒目录获取app日志

上一次使用pymobiledevice3,在python代码中访问app的沙盒目录并分析业务日志,在使用过程中发现,在获取app日志的时候速度很慢,执行时间很长,需要30-61秒,所以这次尝试使用libimobiledevic和ifuse,现在已经将iOS沙盒目录挂载到了本地,在python代码中访问并分析日志:

python 复制代码
def get_dev_play_state_through_libimobiledevice(iphone_model, sn, state, log_date):
    """
    :param iphone_model: iPhone型号,例如,iPhoneX,本地根据手机型号创建挂载目录
    :param sn: 设备sn
    :param state: 不同开流状态,例如,wakeS1234、awake success、p4pS1234、p4pE12、previewS1234、previewS123456
    :param log_date: 日志日期,例如,20241028
    :return:
    """
    filter_condition = f"'{state} success.*deviceId = {sn}'"
    mount_path = f"/Users/testmanzhang/ios_sandbox/{iphone_model}/Documents/Logs/1234567_app_ios_{log_date}.log"
    command = f"grep {filter_condition} {mount_path}"

    result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    print(result.stdout)

响应速度相对于pymobiledevice3快很多。时间大概在1-6秒左右。在ifuse同步周期内,首次访问文件内容会稍微慢些,大概6秒左右;周期内第2次开始会快些,大概1秒左右。

有个问题需要注意的是,mac锁屏再解锁后之前的挂载关系报错,There was an error accessing the mount point: Input/output error,

需要重新挂载:

testmanzhang@TestMandeMBP ~ % ifuse ~/ios_sandbox/iPhoneX --container com.glazero.ios --udid f89d929e8c45a81c0fe2d22f80c1a36e227e90ef

There was an error accessing the mount point: Input/output error

testmanzhang@TestMandeMBP ~ % umount ~/ios_sandbox/iPhoneX

testmanzhang@TestMandeMBP ~ % mount | grep ios_sandbox

testmanzhang@TestMandeMBP ~ % ifuse ~/ios_sandbox/iPhoneX --container com.glazero.ios --udid f89d929e8c45a81c0fe2d22f80c1a36e227e90ef

testmanzhang@TestMandeMBP ~ %

相关推荐
外收内放9 小时前
Python基础语法练习题(40-42)
开发语言·python
m0_547486669 小时前
《数据挖掘:理论、方法与实践基于Python语言》全套PPT课件2026(中国地质大学)
人工智能·python·数据挖掘
meiying88389 小时前
电商图片批量处理实战:Python+Pillow 一键完成裁剪、压缩、水印与格式转换
python·pillow
高洁019 小时前
AI视频生成技术:从静态图文到动态视觉的内容智能革命
python·深度学习·django·transformer·tornado
沐欣工作室_lvyiyi10 小时前
基于Flask的旅游大数据分析与可视化系统(论文+源码)
python·flask·旅游
施棠海10 小时前
多 Agent 团队编排系统的设计与实测:agent-workflow
python·ai·架构
asdzx6710 小时前
Python 实现从 URL 在线下载 PDF 文档教程
python·pdf
Bruce_Liuxiaowei10 小时前
元组与具名元组:把「第 3 个字段」变成「price」
数据结构·python·语法·元组
___波子 Pro Max.10 小时前
pip 管库,pipx 管工具:Python 依赖隔离的正确姿势
python