sannidhyaroy / Soduto

Soduto is a KDE Connect compatible client for macOS. It allows better integration between your phones, desktops and tablets.
https://soduto.thenoton.com
GNU General Public License v3.0
141 stars 11 forks source link

soduto causes Mac to wake up every minute , draining a lot of battery overnight #13

Open avichou opened 1 year ago

avichou commented 1 year ago

MBA M1, monterey and ventura

After i noticed i was losing over 8% of battery overnight, while if booting in safe mode wouldn't drop more than 1%, I started debugging all the processes and wake-ups

Using "log show --style syslog | fgrep "Wake reason" command, it appeared there were 2 main processes running roughly every minute ;

1)kernel: (corecapture) 098020.154583 wlan0.A[25258] [ik] systemWokenByWiFi@42641:WoW Wake reason = wifi, kern.wakereason: 'SMC.OutboxNotEmpty smc.70070000 wifibt bluetooth-pcie' .

wifi/bt/lan wakeup basically

2)Default 0x0 0 0 kernel: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01)

both of which would occur every 45s approximately

Tried disabling background processes one by one, and SODUTO appeared to be the issue, -although tbf it's present with kde connect as well i'm afraid-

with soduto OFF, those two processes would still wake up the mac , but only every 20-30mns.

TLDR: soduto and kde connect keep waking up the mac (and possibly the phone as well) by trying to maintain a connection

screnshots : with soduto and without it

image

image
sannidhyaroy commented 1 year ago

If KDE Connect also has the same issue, I wonder if this is because they both are trying to actively check for devices and not lose a connection. Since, I don’t know much details about the connection side of KDE Connect and it's clients, I'd say you might get a pretty knowledgeable answer from @giedrius-stanevicius, considering that he's the original developer of Soduto. Also I'll take a look on this and try to replicate it and see if I can include a dropdown setting to reduce the number of times it checks for connections when the Mac is in Low Power Mode or when not charging or in low battery.

I can’t confirm if this will be resolved as expected, but I'll certainly do what I can.

avichou commented 1 year ago

If KDE Connect also has the same issue, I wonder if this is because they both are trying to actively check for devices and not lose a connection. Since, I don’t know much details about the connection side of KDE Connect and it's clients, I'd say you might get a pretty knowledgeable answer from @giedrius-stanevicius, considering that he's the original developer of Soduto. Also I'll take a look on this and try to replicate it and see if I can include a dropdown setting to reduce the number of times it checks for connections when the Mac is in Low Power Mode or when not charging or in low battery.

I can’t confirm if this will be resolved as expected, but I'll certainly do what I can.

I'll try to debug it further to confirm kde connect.app also presents this issue , but iirc it's the case

Is giedrius still active ? He abandoned soduto didn't he ? Also should I contact him myself , or did you just tag him ?(i don't know how GitHub works sorry 😐)

Tyvm for your job ! Speaking of which have u not noticed that issue on your own Mac? Do you not see the battery depleting during sleep ?

giedrius-stanevicius commented 1 year ago

Hi there. From looking at the code, I could not see the possible problem - a deeper investigation should be needed. However, I don't know when I'll have time to look into this. If someone would like to debug it, looking at broadcastAnnouncement function and the whole ConnectionProvider class could be a good start.

avichou commented 1 year ago

Hi there. From looking at the code, I could not see the possible problem - a deeper investigation should be needed. However, I don't know when I'll have time to look into this. If someone would like to debug it, looking at broadcastAnnouncement function and the whole ConnectionProvider class could be a good start.

thank you , unforunately i lack the knowledge for debugging...

but dont you notice that behavior on your machine ? mac waking up every minute, and losing 8% of battery at night during sleep. that's something you can easily spot . Or am I the only one in that situation ?

sannidhyaroy commented 1 year ago

Tyvm for your job ! Speaking of which have u not noticed that issue on your own Mac? Do you not see the battery depleting during sleep ?

I observed the energy usage for a couple of days and Soduto uses very little energy on my mac. The 12 hr. Power in Activity Monitor usually is between 0.15. Raycast, 1Password and Activity Monitor itself uses way more energy than Soduto. Will update the comment if I notice anything absurd!

avichou commented 1 year ago

Tyvm for your job ! Speaking of which have u not noticed that issue on your own Mac? Do you not see the battery depleting during sleep ?

I observed the energy usage for a couple of days and Soduto uses very little energy on my mac. The 12 hr. Power in Activity Monitor usually is between 0.15. Raycast, 1Password and Activity Monitor itself uses way more energy than Soduto. Will update the comment if I notice anything absurd!

hey! sorry I may not have been clear

The issue is that soduto wakes up the mac , but the process may not be recognized as soduto

Do I make sense ? soduto itself doesnt drain much energy according to activity monitor , but it is the cause of those very frequent wakeups

Did you try running log show --style syslog | fgrep "Wake reason and see how often your mac gets woken up during the night ? cuz as I said, with soduto open it wakes up every minute, without soduto it happens roughly every 20mns

(wifi-bt pce and host 0 processes )

sannidhyaroy commented 1 year ago

Did you try running log show --style syslog | fgrep "Wake reason and see how often your mac gets woken up during the night ? cuz as I said, with soduto open it wakes up every minute, without soduto it happens roughly every 20mns

I did try running the command but it just keeps on loading and then terminates the process after 2 or 3 minutes. However I'll paste the power events on my mac, as listed according to System Information > Power:

Power Events:

Next Scheduled Events:

  appPID:   464
  Type: Wake
  Scheduled By: com.apple.alarm.user-visible-com.apple.CalendarNotification.EKTravelEngine.periodicRefreshTimer
  Time: 22/04/23, 8:27 AM
  UserVisible:  0

  appPID:   119
  Type: Wake
  Scheduled By: com.apple.alarm.user-visible-com.apple.acmd.alarm
  Time: 23/04/23, 6:21 AM
  UserVisible:  0
avichou commented 1 year ago

Did you try running log show --style syslog | fgrep "Wake reason and see how often your mac gets woken up during the night ? cuz as I said, with soduto open it wakes up every minute, without soduto it happens roughly every 20mns

I did try running the command but it just keeps on loading and then terminates the process after 2 or 3 minutes. However I'll paste the power events on my mac, as listed according to System Information > Power:

Power Events:

Next Scheduled Events:

  appPID: 464
  Type:   Wake
  Scheduled By:   com.apple.alarm.user-visible-com.apple.CalendarNotification.EKTravelEngine.periodicRefreshTimer
  Time:   22/04/23, 8:27 AM
  UserVisible:    0

  appPID: 119
  Type:   Wake
  Scheduled By:   com.apple.alarm.user-visible-com.apple.acmd.alarm
  Time:   23/04/23, 6:21 AM
  UserVisible:    0

hmm that's probably because you haven't rebooted your mac in a long time (if I had to guess)

unfortunately power events and scheduled don't provide much infos apart from apple's own events. It's not listed for me either

how about battery drain during the night, with soduto on and off ?

sannidhyaroy commented 1 year ago

how about battery drain during the night, with soduto on and off ?

I did a battery drain during the night with Soduto on. The test was approximately of 5 hours. The initial charge was $\frac{3208}{4529}\times{100}$% $\= 70.8324$% (approx.). After 5 hours, the battery was at $\frac{3153}{4529}\times{100}$% $\= 69.6180$% (approx.).

I did the test after closing all foreground as well as background apps as well, so only the default system processes and Soduto was running. There was no third-party app, except Soduto running in the background while I was doing the test and the mac was kept at sleep with just the lid closed. Now, there was no control involved in this experiment as of now but I plan on doing the same experiment later this night with no apps running except default system processes to act as a control.

But even without a control in this setup, I'm pretty satisfied how the mac pulled off as it only lost about $(3208 - 3153) = 55 mAh$ or $(70.8324 - 69.6180)$% $\= 1.2144$% of battery juice on my mac after sleeping 5 hours.

EDIT: Today I left my mac for about 6 hours and 20 minutes without any 3rd party processes in the background and only system processes. Initially the battery was holding $\frac{3258}{4526} \times 100$% $\= 71.9841$% (approx.) of juice. After 6 hours and 20 minutes, it's at $\frac{3175}{4526} \times 100$% $\= 70.1502$% (approx.). That gives us a difference of $(3258 - 3175) = 83 mAh$ or $(71.9841 - 70.1502)$% $\= 1.8339$%.

So, here's the final test results: With Soduto: 1.2144% of battery drop after 5 hours Without Soduto: 1.8339% of battery drop after 6 hours and 20 minutes

Assuming rate of battery drop to be uniform, for per hour, we have a $\frac{1.2144}{5} = 0.24288$% drop with Soduto and a $\frac{1.8339}{6.3333} = 0.28956$% drop without Soduto. It's weird that it drew more battery juice without Soduto but this is not supposed to be an extremely accurate test. It has some discrepancies and it's very possible that macOS itself drew more power in the second test for some other reasons.

Overall Soduto takes negligible resources on your mac, even when at sleep.

avichou commented 1 year ago

thank you . That's intersting, it must be an issue on my end, perhaps phone related, are u using kde connect on your phone, or something else ?

so i've left my mac with several background processes but WITHOUT soduto running, from 3AM to 7PM (basically right now) , and lost 1% , from 76 to 75 . which is amazing

Now , I'll test it tonight with soduto ON, and will report the results tomorrow . exact same configuration, except i'll leave soduto ON . if it drains 8% again, i suppose it is obvious that soduto is the issue, at least on my device

I'm really puzzled as to how the same process could drain so much more battery on 2 different macs

avichou commented 1 year ago

forgot to tag you @sannidhyaroy

sannidhyaroy commented 1 year ago

Now , I'll test it tonight with soduto ON, and will report the results tomorrow . exact same configuration, except i'll leave soduto ON . if it drains 8% again, i suppose it is obvious that soduto is the issue, at least on my device

I'm really puzzled as to how the same process could drain so much more battery on 2 different macs

This might sound silly but are you by chance reporting the battery percentage drop shown in the menu bar? Apple's battery indicator might not be the best way to measure battery drop as they're known to manipulate the actual percentage.

Like if you notice, Apple devices will stay at 100% for a very long time before dropping to 99%.

avichou commented 1 year ago

Now , I'll test it tonight with soduto ON, and will report the results tomorrow . exact same configuration, except i'll leave soduto ON . if it drains 8% again, i suppose it is obvious that soduto is the issue, at least on my device

I'm really puzzled as to how the same process could drain so much more battery on 2 different macs

This might sound silly but are you by chance reporting the battery percentage drop shown in the menu bar? Apple's battery indicator might not be the best way to measure battery drop as they're known to manipulate the actual percentage.

Like if you notice, Apple devices will stay at 100% for a very long time before dropping to 99%.

Yes you're right ,if anything I'm silly for using that

But idk how else to check battery, what command do you use ? I'll retest it with your command and report both results , with and without soduto !

Still don't u think that it's reliable enough for a difference that big ? I mean 1% vs 8%...even if not fully reliable .sounds too big of a difference doesn't it

sannidhyaroy commented 1 year ago

But idk how else to check battery, what command do you use ? I'll retest it with your command and report both results , with and without soduto !

Still don't u think that it's reliable enough for a difference that big ? I mean 1% vs 8%...even if not fully reliable .sounds too big of a difference doesn't it

You're right that even if it's not nearly accurate, the difference is still big enough.

As for how you can check the battery charge, there are several apps out there but I personally just use an extension called "Battery Health" within Raycast. It's not exactly accurate but it does the job. You can then convert the charge into percentage.

avichou commented 1 year ago

But idk how else to check battery, what command do you use ? I'll retest it with your command and report both results , with and without soduto !

Still don't u think that it's reliable enough for a difference that big ? I mean 1% vs 8%...even if not fully reliable .sounds too big of a difference doesn't it

You're right that even if it's not nearly accurate, the difference is still big enough.

As for how you can check the battery charge, there are several apps out there but I personally just use an extension called "Battery Health" within Raycast. It's not exactly accurate but it does the job. You can then convert the charge into percentage.

I'll try to find and report the results

Besides the wake ups are way less present without soduto so there's that

Tonight I'll have soduto on and see how much battery is drained

Good night :)

avichou commented 1 year ago

@sannidhyaroy hello !

so a quick sum up :

-without soduto, battery drained is 1% (from 76 to 75) , for a total of 16 hours of sleep

-with soduto, battery drained is 5% (75 to 70) , for a total of 17 hours of sleep

not as bad as before i'd say, since it often would drop 8%+ , but still concerning. I am yet to try with battery charge utilities to get more precise results, but still, the difference is too big to be considered within margin of error .

since we both have the same mac, I assume it must be caused by the combination of soduto+ something else. basically soduto acts as a catalyzer/enhancer. So soduto is only part of the problem, which must be combined with something else, that makes it wake the mac so often

may I ask, does it happen that even with your lid closed, your phone still shows "sannidhyaroy's-mac-connected" , from time to time ?

Do you have find my ON ?I personally have it on, but find my network off .

Do you keep your phone ON at night ?

PS: I'll try to test with my phone off tonight ,and see if it changes anything

PPS:thank you so much for bearing with me, I know I can be annoying sometimes , but this battery drain is really concerning..

sannidhyaroy commented 1 year ago

may I ask, does it happen that even with your lid closed, your phone still shows "sannidhyaroy's-mac-connected" , from time to time ?

My phone would be connected for a while after my MacBook's lid is closed and after sometime, it'd disconnect. When the lid is opened and the mac wakes up from sleep, Soduto will immediately check for nearby devices and connect to available paired devices, if possible.

Do you have find my ON ?I personally have it on, but find my network off .

Do you keep your phone ON at night ?

Yes, I have Find My turned on and I keep my phone on at night.

NOTE: Only the forked version of Soduto in this repository checks for nearby devices immediately when your mac wakes up from sleep. The official version doesn't. I had to click on the Soduto menu bar icon in the official version after the mac woke up and then Soduto would check for devices to re-connect. I felt this was not seamless but I'm not sure it was intended or it was because Soduto wasn't in development for a long time, so the functionality was broken.

avichou commented 1 year ago

may I ask, does it happen that even with your lid closed, your phone still shows "sannidhyaroy's-mac-connected" , from time to time ?

My phone would be connected for a while after my MacBook's lid is closed and after sometime, it'd disconnect. When the lid is opened and the mac wakes up from sleep, Soduto will immediately check for nearby devices and connect to available paired devices, if possible.

Do you have find my ON ?I personally have it on, but find my network off . Do you keep your phone ON at night ?

Yes, I have Find My turned on and I keep my phone on at night.

NOTE: Only the forked version of Soduto in this repository checks for nearby devices immediately when your mac wakes up from sleep. The official version doesn't. I had to click on the Soduto menu bar icon in the official version after the mac woke up and then Soduto would check for devices to re-connect. I felt this was not seamless but I'm not sure it was intended or it was because Soduto wasn't in development for a long time, so the functionality was broken.

Thanks ! yeah i noticed that difference in behavior between the official version and the forked, and I much prefer your implementation :)

I'll also try to run soduto in safe boot next night and see if it makes any changes

Do you have any other ideas as to what else may be causing such a weird difference between your setup and mine

sannidhyaroy commented 1 year ago

Do you have any other ideas as to what else may be causing such a weird difference between your setup and mine

I'm not sure about this one but at this point, I've seen people with very different issues that I've not been able to replicate, even though we might be using the same version of Soduto.

As you said in your previous comment that other apps might affect the functionality of Soduto and this can be true as well, as I have found apps who behave differently because a user had another particular app installed vs another user didn't. As an example, I found CleanMyMac X messes up the functionalities of some apps like TG Pro or some app that I don't quite remember.

Another possible reason could be because I'm running my own build of Soduto with my own developer certificate. But for other users, their mac is running a build of Soduto which isn't notarized and is signed with the certificate of an unknown developer (since I don't pay Apple $99/year). So, there can be a minor difference in functionalities due to that. These are just possibilities and there can be more but since I'm new to macOS development, I can't say with certainty what's the real reason.

And I think it's not new that there have been instances when developers have not been able to reproduce a bug or issue that a user was facing. We all don't know exactly what's behind haha.

avichou commented 1 year ago

Do you have any other ideas as to what else may be causing such a weird difference between your setup and mine

I'm not sure about this one but at this point, I've seen people with very different issues that I've not been able to replicate, even though we might be using the same version of Soduto.

As you said in your previous comment that other apps might affect the functionality of Soduto and this can be true as well, as I have found apps who behave differently because a user had another particular app installed vs another user didn't. As an example, I found CleanMyMac X messes up the functionalities of some apps like TG Pro or some app that I don't quite remember.

Another possible reason could be because I'm running my own build of Soduto with my own developer certificate. But for other users, their mac is running a build of Soduto which isn't notarized and is signed with the certificate of an unknown developer (since I don't pay Apple $99/year). So, there can be a minor difference in functionalities due to that. These are just possibilities and there can be more but since I'm new to macOS development, I can't say with certainty what's the real reason.

And I think it's not new that there have been instances when developers have not been able to reproduce a bug or issue that a user was facing. We all don't know exactly what's behind haha.

fair enough ! guess I'll just live with it. if you ever manage to get the results for log show --style syslog | fgrep "Wake reason" pls let me know :)

btw i've just tested in safe boot, with soduto running, and lost about 118mah, or roughly 3% of battery, for a total of 16h

it seems the mac doesn't wake up as often in safe boot, even with soduto running (every 15/20 minutes)

Shall I close the issue ?

2023-04-27 09:30:06.000623+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 09:48:48.869560+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 10:22:13.866278+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 10:26:19.261367+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 10:26:19.481513+0200 localhost kernel[0]: (corecapture) 021383.868080 wlan0.A[24016] [ik] systemWokenByWiFi@42641:WoW Wake reason = wlan, kern.wakereason: 'SMC.OutboxNotEmpty smc.70070000 wifibt wlan' 2023-04-27 10:43:25.757147+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 10:58:29.757975+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 11:13:29.807604+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 11:13:30.139787+0200 localhost kernel[0]: (corecapture) 024214.632023 wlan0.A[24391] [ik] systemWokenByWiFi@42641:WoW Wake reason = wlan, kern.wakereason: 'SMC.OutboxNotEmpty smc.70070000 wifibt wlan' 2023-04-27 11:17:17.036822+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 11:17:17.288412+0200 localhost kernel[0]: (corecapture) 024441.780648 wlan0.A[24522] [ik] systemWokenByWiFi@42641:WoW Wake reason = wlan, kern.wakereason: 'SMC.OutboxNotEmpty smc.70070000 wifibt wlan' 2023-04-27 11:25:11.781720+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 11:25:12.089636+0200 localhost kernel[0]: (corecapture) 024916.581872 wlan0.A[24649] [ik] systemWokenByWiFi@42641:WoW Wake reason = wlan, kern.wakereason: 'SMC.OutboxNotEmpty smc.70070000 wifibt wlan' 2023-04-27 11:33:22.658353+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 11:50:51.657529+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 12:08:17.655797+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01) 2023-04-27 12:24:47.659072+0200 localhost kernel[0]: (AppleTopCaseHIDEventDriver) [HID] [ATC] AppleDeviceManagementHIDEventService::processWakeReason Wake reason: Host (0x01)

giedrius-stanevicius commented 1 year ago

Hi again. I've looked into the code (in my own repository) a little bit more. And I think there might be several cases worth investigating:

avichou commented 1 year ago

Hi again. I've looked into the code (in my own repository) a little bit more. And I think there might be several cases worth investigating:

  • clipboard sharing plugin seems to use a regular timer to check for clipboard changes. While Soduto does not have means to disable the functionality, I guess it is possible to disable through the KDE Connect app. So, you may try disabling the clipboard service on KDE Connect app and check the OS awakings if they are the same.
  • notifications service also may use regular timers when there are active notifications present - to check for notifications dismissal. Same as with the clipboard service, you may try disabling it on KDE Connect app side to check if this causes the problem.
  • Aside from the cases above, I did not notice any other possible causes for regular awakenings. However, Soduto still keeps network connections open and also listens for multicast network anouncements. Theese could also cause awakenings if external devices are actively sending KDE Connect related data over network.

Thank you ! Unfortunately I'm having issues with fiber , but when wifi gets fixed I'll make sure to test all of that

-Could you tell me more about "kde connect related data" ? What could possibly send anything related to kde connect ? May this be a router/DNS issue ?

-could you possibly report how often your Mac gets woken up (whether it's # every 15mns, or every 30s) , using log show --style syslog | fgrep "Wake reason" , please ?

giedrius-stanevicius commented 1 year ago

-Could you tell me more about "kde connect related data" ? What could possibly send anything related to kde connect ?

May this be a router/DNS issue ? I meant that other KDE Connect clients could broadcast announcements about their presence (for this, they don't need to be paired and connected) and connected clients could send information about their clipboard content/notifications/etc.

-could you possibly report how often your Mac gets woken up (whether it's # every 15mns, or every 30s) , using log show --style syslog | fgrep "Wake reason" , please ?

I don't use Soduto myself anymore as I don't have an Android phone anymore. So the only way I could test is with Soduto client alone and with no other devices on the network. That might have different outcome, but I could try when I find the time.