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

相关推荐
山海青风2 分钟前
图像识别零基础实战入门 1 计算机如何“看”一张图片
图像处理·python
彼岸花开了吗30 分钟前
构建AI智能体:八十、SVD知识整理与降维:从数据混沌到语义秩序的智能转换
人工智能·python·llm
山土成旧客44 分钟前
【Python学习打卡-Day40】从“能跑就行”到“工程标准”:PyTorch训练与测试的规范化写法
pytorch·python·学习
闲人编程1 小时前
消息通知系统实现:构建高可用、可扩展的企业级通知服务
java·服务器·网络·python·消息队列·异步处理·分发器
大神君Bob1 小时前
【AI办公自动化】如何使用Pytho让Excel表格处理自动化
python
Heorine1 小时前
数学建模 绘图 图表 可视化(6)
python·数学建模·数据可视化
栈与堆1 小时前
LeetCode-1-两数之和
java·数据结构·后端·python·算法·leetcode·rust
冰淇淋真好吃1 小时前
iOS实现 WKWebView 长截图的优雅方案
ios
智航GIS2 小时前
10.7 pyspider 库入门
开发语言·前端·python
副露のmagic2 小时前
更弱智的算法学习 day25
python·学习·算法