Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wujunchuan opened this Issue Nov 3, 2016 · 20 comments

Comments

Projects
None yet
8 participants
@wujunchuan
Copy link
Owner

wujunchuan commented Nov 3, 2016

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

This comment has been minimized.

Copy link

JKChang2015 commented Jan 27, 2017

get! Thanks

@keien411

This comment has been minimized.

Copy link

keien411 commented Feb 15, 2017

找半天了

@wujunchuan wujunchuan added Tools and removed get! labels Mar 1, 2017

@JimmyLv

This comment has been minimized.

Copy link

JimmyLv commented Mar 2, 2017

多谢!

@Planck1043

This comment has been minimized.

Copy link

Planck1043 commented Mar 21, 2017

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

@wujunchuan

This comment has been minimized.

Copy link
Owner Author

wujunchuan commented Mar 21, 2017

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

@FrancoWay

This comment has been minimized.

Copy link

FrancoWay commented Jun 16, 2017

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

@Vicent-xd

This comment has been minimized.

Copy link

Vicent-xd commented Jun 22, 2017

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

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 24, 2018

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

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 24, 2018

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

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 24, 2018

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

@wujunchuan

This comment has been minimized.

Copy link
Owner Author

wujunchuan commented Jun 24, 2018

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

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 25, 2018

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

@wujunchuan

This comment has been minimized.

Copy link
Owner Author

wujunchuan commented Jun 25, 2018

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 25, 2018

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

@wujunchuan

This comment has been minimized.

Copy link
Owner Author

wujunchuan commented Jun 25, 2018

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 25, 2018

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

@wujunchuan

This comment has been minimized.

Copy link
Owner Author

wujunchuan commented Jun 25, 2018

@hermitcrabcai

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 25, 2018

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

@JKChang2015

This comment has been minimized.

Copy link

JKChang2015 commented Jun 25, 2018

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

This comment has been minimized.

Copy link

hermitcrabcai commented Jun 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.