You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Mac应用调试时的CDPurgeableResultCache日志?

解决Mac应用调试时CDPurgeableResultCache日志泛滥问题

调试Mac应用时,控制台反复输出以下日志,严重干扰正常调试工作:

2023-03-08 23:06:15.692878+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/VM, setting to zero
2023-03-08 23:06:15.693537+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/Update, setting to zero
2023-03-08 23:06:15.694138+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/Preboot, setting to zero
2023-03-08 23:06:15.694736+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/iSCPreboot, setting to zero
2023-03-08 23:06:15.695335+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/Hardware, setting to zero
2023-03-08 23:06:15.709811+0100 UtilityTools[43807:2280795] [client] 114 CDPurgeableResultCache _recentPurgeableTotals no result for /System/Volumes/xarts, setting to zero

该日志由调用volumeAvailableCapacityForImportantUsageKey的代码触发,原代码如下:

func getFreeSpace() -> Double {
    let fileURL = URL(fileURLWithPath: NSHomeDirectory())
    do {
        let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey]) // THIS LINE
        if let capacity: Int64 = values.volumeAvailableCapacityForImportantUsage {
            return Double(capacity)
        }
    } catch {

    }
    return 1
}

解决方案

方法一:控制台精准过滤日志

无需修改代码,直接在Xcode调试控制台的搜索框中输入-CDPurgeableResultCache,即可自动排除包含该关键词的日志,不影响其他调试信息查看。

方法二:禁用系统级日志(谨慎使用)

如果需要彻底屏蔽所有系统日志:

  1. 点击Xcode顶部菜单栏Product → Scheme → Edit Scheme
  2. 在弹出窗口选择Run → Arguments标签
  3. 在Environment Variables区域添加变量OS_ACTIVITY_MODE,值设为disable

注意:此方法会禁用所有系统日志,可能丢失其他有用的调试信息,仅建议临时使用。

方法三:替换API避免触发日志

改用POSIX标准的statfs函数获取磁盘可用空间,跳过触发日志的系统框架逻辑:

import Foundation

func getFreeSpace() -> Double {
    let path = NSHomeDirectory()
    var statInfo = statfs()
    guard statfs(path, &statInfo) == 0 else {
        return 1
    }
    // 计算可用空间:块大小 × 可用块数
    let freeBytes = Double(statInfo.f_bsize) * Double(statInfo.f_bavail)
    return freeBytes
}

此方法能准确获取磁盘可用空间,同时不会产生目标日志。


内容的提问来源于stack exchange,提问作者Petr Hora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 14:47:44