wujunchuan / wujunchuan.github.io

John Trump's personal blog in issues
115 stars 13 forks source link

MacBook Pro Retina 睡眠耗电现象修复 #9

Open wujunchuan opened 7 years ago

wujunchuan commented 7 years ago

MacBook Pro Retina 睡眠耗电现象修复

经过测试,MacBook Pro (Retina, Mid 2015)在盒盖睡眠的时候会频繁的被唤醒,导致夜间掉电比较严重(有的网友一个晚上掉电10%以上),根据"syslog | grep -i "Wake reason"显示,也是有被频繁唤醒的记录,虽然掉电没有他们的那么严重,研究了一下各路的解决方案,找到了最终的一个解决方案

如果你在终端中输入 "syslog | grep -i "Wake reason"有像下面的情况的,那么就请注意了,因为这个问题似乎已经存在一段时间了,并且问题集中在2015年后的机型上,网上有挺多讨论的,并且在最新的系统(macOS Sierra 10.12.1 (16B2657)),苹果并没有修复这个问题,只能靠我们自己来手动解决了

syslog

产生问题的原因

论坛上大部分的回答都是集中在app唤醒,Power Nap,网络唤醒,重置SMC等解决方案,如果你尝试了上面的各种办法还是没有解决的话,可以继续往下读

我们通过分析系统日志(上图)就可以看到,我们的机器被TCP超时频繁的唤醒,所以,最简单的解决办法就是每次在盒盖前,把WiFi手动断开就可以,如果是不爱折腾的同学可以考虑考虑.也就动动手关掉WiFi嘛

解决问题

既然我们知道,导致休眠失败的原因是网络频繁被唤醒,那么要嘛手动关闭网络,要嘛自动关闭网络,如果有个工具,可以检测系统休眠状态,并且对其进行WiFi的切断与唤醒就好了.

正好我发现了这篇文章 A Macbook Pro's insomnia solution

这位外国友人的解决方案,正是我上面说的,通过sleepwatcher来监听系统休眠情况,并且对其WiFi进行操作

手动挡司机

首先,得先安装sleepwatcher,这里推荐使用brew形式来安装,如果还没有用上brew的同学,请点击获取Homebrew 在终端中输入/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

随后安装sleepwatcher执行下面语句brew install sleepwatcher

SleepWatcher默认执行wake事件配置文件是在~/.wakeup,执行sleep事件配置文件是在~/. sleep所以我们将下面两个脚本复制到用户目录下

.sleep

#!/bin/bash

status=$(networksetup getairportpower en0 | grep -Ei "On$")

if [ -f /tmp/wifi.on ]; then
    rm /tmp/wifi.on
fi

if [ "" !=  "$status" ]; then
    echo "`date` -- WiFi is On ... storing statement" >> /tmp/sleep.log

    touch /tmp/wifi.on
    networksetup setairportpower en0 off
fi

.wakeup

if [ -f /tmp/wifi.on ]; then
    echo "`date` -- Enablig WiFi" >> /tmp/sleep.log
    sleep 3
    networksetup setairportpower en0 on
fi

最后执行,令上面两个脚本生效,省得重启

cp /usr/local/Cellar/sleepwatcher/2.2/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist

关于脚本的解释,可以看原文

自动挡用户

作者本人也是写了一个shell脚本来帮助大家,只需要根据README写的步骤来执行shell,就可以完成安装. 下载解压后进入该目录,在终端输入

bash PleaseSleep install等待安装完成

如果日后需要删除的话,在终端输入 bash PleaseSleep uninstall

下载地址:PleaseSleep.7z

相关阅读

可以参考下面几篇文章,对这个问题有个整体的认识

MacBook Pro Retina 睡眠耗电现象深究

关于休眠耗电问题求助

A Macbook Pro's insomnia solution

rMBP 2015 Wake Reason: ARPT (Network)

JKChang2015 commented 7 years ago

get! Thanks

keien411 commented 7 years ago

找半天了

JimmyLv commented 7 years ago

多谢!

Planck1043 commented 7 years ago

苹果公司这个bug这么久都还没有解决,也是醉了

wujunchuan commented 7 years ago

@fenzhizi123 是的,而且这个Bug已经跨版本存在了,原本以为升级到新系统会好点

FrancoWay commented 7 years ago

这个问题我找了快1年。。。还是得用google搜才能搜到东西呀~

buptxdt commented 7 years ago

macOS 10.12.5下合盖子sleepwatcher 不会调用.sleep和.wakeup 最后用brew services start sleepwatcher 解决的

hermitcrabcai commented 6 years ago

image hi 我用 mac 10.14 的版本 提示需要安装最新版本的xcode 还不知能否安装成功

hermitcrabcai commented 6 years ago

image 安装了 xcode 10.0 时 提示这个下载超时 实际上我在浏览器端时可以下载的

hermitcrabcai commented 6 years ago

请群主解答一下啊哦 谢谢了

wujunchuan commented 6 years ago

@Hermitcrabcai He 我想你是被墙了,终端命令行不能直接走翻墙流量(eg: shadowsocks) 看下这个文章 配置下科学上网就可以了

hermitcrabcai commented 6 years ago

我是可以访问google的 全局流量模式 都试过 一直无法命令行安装 我之前是安装成功过了 但是我手贱卸载了 只是现在系统是10.14 xcode是10.0 请您解答一下

wujunchuan commented 6 years ago

全局流量模式下,命令行也是不会走翻墙流量的,你试试 curl www.google.com 就知道了。 我觉得是被墙了,按上面的方法折腾下先

寄居蟹 notifications@github.com 于2018年6月25日周一 上午9:32写道:

我是可以访问google的 全局流量模式 都试过 一直无法命令行安装 我之前是安装成功过了 但是我手贱卸载了 只是现在系统是10.14 xcode是10.0 请您解答一下

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wujunchuan/wujunchuan.github.io/issues/9#issuecomment-399806689, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKeTwqNcosH-nZjox_58wJiKNSYTBl8ks5uAD3KgaJpZM4Kosxg .

-- Thanks, John Trump

hermitcrabcai commented 6 years ago

image 尝试google确实如此 但是文章的流程似乎不会操作 只是很好奇 之前为什么可以下载成功

wujunchuan commented 6 years ago

也可以用Homebrew的镜像源,(Homebrew有比较快的源(mirror)吗?)[ https://www.zhihu.com/question/31360766] 不过我觉得还是把proxychains4配置好比较好,毕竟很多东西需要用到科学上网

寄居蟹 notifications@github.com 于2018年6月25日周一 上午10:04写道:

[image: image] https://user-images.githubusercontent.com/26593656/41826848-fdcb23ca-785e-11e8-8916-a8ff61d7bb21.png 尝试google确实如此 但是文章的流程似乎不会操作 只是很好奇 之前为什么可以下载成功

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wujunchuan/wujunchuan.github.io/issues/9#issuecomment-399810322, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKeT6-FzIRbhc1OQrb3ntnPln-Ghj92ks5uAEUQgaJpZM4Kosxg .

-- Thanks, John Trump

hermitcrabcai commented 6 years ago

image 已用surge配置上网 但是目前又提示这个错误

wujunchuan commented 6 years ago

Surge打开Enhanced Mode了吗

image

寄居蟹 notifications@github.com 于2018年6月25日周一 上午10:17写道:

[image: image] https://user-images.githubusercontent.com/26593656/41827228-e7c28710-7860-11e8-8fda-6d96c876b593.png 已用surge配置上网 但是目前又提示这个错误

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wujunchuan/wujunchuan.github.io/issues/9#issuecomment-399811891, or mute the thread https://github.com/notifications/unsubscribe-auth/AHKeT5BOVPQjQ55V_sJcpVq8mGbMBM8Yks5uAEgvgaJpZM4Kosxg .

-- Thanks, John Trump

hermitcrabcai commented 6 years ago

image 安装成功了 感谢群主一直以来的耐心解答 谢谢 顺便问问您 您用surge吗 我正在用试用版本 想一直使用surge 想组团购买

JKChang2015 commented 6 years ago

Someupdates:

10.13版本加强了权限的限制,尤其是对/usr/local目录,默认开通 SIP (System Intergrity Protection),它禁止了软件以root身份在Mac上运行,不管你是在终端中如何运行

chmod u+x Pleasesleep Pleasesleep install 返回给你的就是 chown: Operation not permitted

只有关闭System Intergrity Protection: 1.重启Mac,按住Command + R键直到Apple Logo出现,进入Recovery Mode模式(我感觉我是按了好半天)

2.点击工具里的Terminal(终端)

3.输入csrutil disable,之后回车

4.重启Mac

5.重启完成后,终端中输入 Pleasesleep install, 成功执行,没有报操作不允许了

(如果想重新开启安全设置,则重复1、2步骤,输入csrutil enable就可以了)

hermitcrabcai commented 6 years ago

@JKChang2015 是的 已经按照您说的方式解决 谢谢

hermitcai commented 4 years ago

目前sleepwatch版本已经到了2.2.1 生效语句需要修改下 cp /usr/local/Cellar/sleepwatcher/2.2.1/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist 最近我的机器是最新的版本 但是睡眠一直睡不死 中午过来看早上起来发现机器都有点发烫 试试这个睡眠脚本能不能解决我的问题 之前是通过这个脚本解决了我掉电的问题

hermitcai commented 4 years ago

亲测中午还是机器烧 并没有睡着

JKChang2015 commented 4 years ago

亲测中午还是机器烧 并没有睡着

试着运行:

pmset -g assertions 

看看哪些进程在唤醒你的电脑

hermitcai commented 4 years ago

亲测中午还是机器烧 并没有睡着

试着运行:

pmset -g assertions 

看看哪些进程在唤醒你的电脑

image 这个是我刚刚执行的 但是刚刚执行之前 我更新过一次系统

hermitcai commented 4 years ago

亲测中午还是机器烧 并没有睡着

试着运行:

pmset -g assertions 

看看哪些进程在唤醒你的电脑

全是wifi惹的祸 我现在手动关闭wifi 一切安好 autosleep现在好像不能用了没啥效果了

JKChang2015 commented 4 years ago

亲测中午还是机器烧 并没有睡着

试着运行:

pmset -g assertions 

看看哪些进程在唤醒你的电脑

全是wifi惹的祸 我现在手动关闭wifi 一切安好 autosleep现在好像不能用了没啥效果了

image

系统设置里去掉勾就行,不用手动关闭wifi

hermitcai commented 4 years ago

h好的 我试试

On Thu, Apr 9, 2020 at 3:44 PM JKChang notifications@github.com wrote:

亲测中午还是机器烧 并没有睡着

试着运行:

pmset -g assertions

看看哪些进程在唤醒你的电脑

全是wifi惹的祸 我现在手动关闭wifi 一切安好 autosleep现在好像不能用了没啥效果了

[image: image] https://user-images.githubusercontent.com/16242098/78870551-37be4980-7a3e-11ea-8898-a2130ad53671.png

系统设置里去掉勾就行,不用手动关闭wifi

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wujunchuan/wujunchuan.github.io/issues/9#issuecomment-611382952, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKX7PKKDNRE3DVPFVYW3IOLRLV4GRANCNFSM4CVCZRQA .