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 ~ %

相关推荐
Wise玩转AI6 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
s***46986 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
runepic7 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
codists7 小时前
2025年11月文章一览
python
生而为虫7 小时前
31.Python语言进阶
python·scrapy·django·flask·fastapi·pygame·tornado
言之。7 小时前
Claude Code 实用开发手册
python
计算机毕设小月哥7 小时前
【Hadoop+Spark+python毕设】中国租房信息可视化分析系统、计算机毕业设计、包括数据爬取、Spark、数据分析、数据可视化、Hadoop
后端·python·mysql
2***c4357 小时前
Redis——使用 python 操作 redis 之从 hmse 迁移到 hset
数据库·redis·python
二川bro9 小时前
模型部署实战:Python结合ONNX与TensorRT
开发语言·python
秋邱9 小时前
AI + 社区服务:智慧老年康养助手(轻量化落地方案)
人工智能·python·重构·ar·推荐算法·agi