cjh19831115 发表于 2022-12-21 11:55

不睡眠原因排查


其实,不睡眠的根本原因有两个方面可能,一个是某个程序禁止系统进行睡眠,它是通过对系统所支持的断言(assertions)机制来实现的,下面会详细说;另一种情况是Mac虽然睡眠了后来接收到了唤醒消息,因为用户可能无意或者忘记或者没有意识到这些设置产生的影响,造成系统对特殊信号进行系统唤醒响应。所以,下面从两个方面来说明,如何下手检查。



在进一步分析之前,最好确认,系统是否设置了睡眠(是否禁止),可以到节能系统配置中查看,或者使用OSX提供的能源管理的命令pmset。对pmset的理解和使用,能帮助我们对苹果电脑的电源配置情况进行详尽了解并提高自由控制度,后面我们也是主要依靠这个命令来展开工作。



最基本的,用下面命令来查看当前的能源配置情况:

pmset -g
或者是
pmset -g custom

前者只显示当前电源的配置情况,后者可以分别对电池和外接电源的不同配置显示。
利用上面的命令,看看sleep的配置值,如果是0,那么就是禁止睡眠,非零就是系统空闲的多少分钟后进入睡眠。


断言接口:

断言是系统底层IO对能源管理机制的对应用程序的一个接口,是在IOPMLib中定义的,官方文档写道:" access to common power management facilities, like initiating system sleep, getting current idle timer values, registering for sleep/wake notifications, and preventing system sleep."

为了能够更详细地排查到底是那个程序设置了断言阻止系统睡眠,可以通过查看当前系统断言的情况:

/usr/bin/pmset -g assertions


现在通过一个实例来分析,下面是一个典型的场景的断言情况:

Assertion status system-wide:
   PreventUserIdleDisplaySleep    1
   CPUBoundAssertion            0
   PreventSystemSleep             1
   PreventUserIdleSystemSleep   1
   InternalPreventDisplaySleep    1
   ExternalMedia                  0
   UserIsActive                   1
   ApplePushServiceTask         0
   BackgroundTask               1

Listed by owning process:
pid 2922(screensharingd): 00:04:37 NoDisplaySleepAssertion named: "Nameless (via IOPMAssertionCreate)"
pid 44(mds): 00:20:38 BackgroundTask named: "com.apple.metadata.mds"
pid 2924(ScreensharingAg): 00:00:15 NoDisplaySleepAssertion named: "screen sharing wake display"
pid 2924(ScreensharingAg): 00:00:05 UserIsActive named: "screen sharing wake display"
pid 2520: PreventUserIdleSystemSleep named: "com.apple.audio.'AppleHDAEngineOutput:1B,0,1,2:0'.noidlesleep"
pid 2423(caffeinate): 00:09:13 PreventSystemSleep named: "caffeinate command-line tool"



https://blog.cs删dn.net/cnedu除cation/article/det链接ails/21217963
页: [1]
查看完整版本: 不睡眠原因排查