Android 内存/电池使用情况

发布于 2024-11-27 04:15:44 字数 902 浏览 0 评论 0原文

由于我无法每天 0:00 运行服务,因此我决定每 50 秒运行一次(通过 AlarmManager)。我读到每 1 秒运行一次服务会耗尽电池电量。我用 1 秒刷新率和 50 秒刷新率尝试了我的程序。为此,我使用了各种应用程序来测量内存使用率和 CPU 使用率。以下是结果:

内存使用情况:

  • Android Booster

    1 秒:5.1 - 7.5 MB

    50 秒:5.5-7.2MB

  • 内存使用/内存管理器

    1 秒:24.5MB

    50 秒:23MB

  • 使用时间线

    1 秒:24MB

    50 秒:22.7 MB

  • 看门狗任务管理器

    1 秒:14.6MB

    50 秒:12-14MB

  • Android 助手:

    1 秒:4MB

    50 秒:7MB

CPU 使用率:

  • 使用时间线

    1 秒:2%

    50 秒:0%

  • 看门狗任务管理器

    1秒:1.3%-1.9%

    50 秒:0.1%

  • Android 助手:

    1秒:2%-3%

    50秒: 0.4%-2%

总而言之,我们可以说内存使用率没有改变,但是cpu改变了用法发生了巨大的变化。由于所有使用的应用程序显示不同的数据,我无法确定我的应用程序使用了多少内存/CPU,但这个小调查表明,每 1 秒运行一个服务对于 cpu 来说确实是一件痛苦的事情。或者不是吗?您对此有何看法?

Since I was unable to run a service every day at 0:00, I decided to run it every 50 sec (by AlarmManager). I read that running a service every 1 sec kills the battery. I tried out my program with 1 sec refresh rate as well as with 50 secs refresh rate. For this I used various applications to measure the memory usage and the cpu usage. Here are the results:

Memory usage:

  • Android Booster

    1 sec: 5.1 - 7.5 MB

    50 sec: 5.5-7.2MB

  • Memory Usage/Memory Manager

    1 sec: 24.5MB

    50 sec: 23MB

  • Usage Timelines

    1 sec: 24MB

    50 sec: 22.7 MB

  • Watchdog Task Manager

    1 sec: 14.6MB

    50 sec: 12-14MB

  • Android Assistant:

    1 sec: 4MB

    50 sec: 7MB

CPU usage:

  • Usage Timelines

    1 sec: 2%

    50 sec: 0%

  • Watchdog Task Manager

    1 sec: 1.3%-1.9%

    50 sec: 0.1%

  • Android Assistant:

    1 sec: 2%-3%

    50 sec: 0.4%-2%

All in all we can say that the memory usage has not changed but the cpu usage has changed spectacularly. As all used applications show different data, I cannot be sure how much memory/cpu my app uses but this little investigation showed me that running a service every 1 sec really is a pain in the ass for the cpu. Or isn't it? What is your opinion about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-12-04 04:15:44

基本规则是,您执行的操作越少,对电池的影响就越小。换句话说,您所做的一切都会减少电池电量。如果您每分钟更新一次,将其更改为每 2 分钟一次通常会将电池消耗减半。

但除此之外,没有一个数字可以给出“正确”的金额。你想要尽可能少地跑步,做尽可能少的工作。

看看你所做的数字是件好事,它可以让你了解你的影响是什么。然而,它们也不是故事的全部——例如,在一些常见的 CPU 上,简单地持有部分唤醒锁就会导致电池耗尽。

看待这个问题的一个好方法是,我们希望设备上的电池能够持续至少 N 天,其中 N 至少为 1,而且实际上我们希望它大于 1。如果设备没有被使用——它的屏幕关闭——它仍然在后台做一些事情,耗尽电池:电话收音机正在运行,可能有些东西正在将新电子邮件等同步到设备上,等等 如果设备不做这项工作,

它会持续很多天。您可以自己看到这一点:打开飞行模式,确保没有愚蠢的应用程序仍在后台执行操作,并查看电池可持续使用多长时间。很容易就需要一周。

因此,您在后台所做的每件小事本身都不是问题。在我们想要充电运行数天的世界中,这是这些工作的总和。基本设备充电后运行的时间越长,您的每一项小工作都会减少电池寿命,因为您有更多的时间运行和耗尽电池。

最终,安排一些工作每分钟或更长时间进行将会缩短用户的电池寿命。多少取决于很多因素:硬件的电源行为、用户通常可以在充电后运行多长时间、每次运行多长时间、您正在进行的工作类型。

我绝对推荐的一件事就是在您自己的设备上亲自测试这个应用程序。从基线开始:让您的设备闲置不使用,看看它能持续多久。确保上面没有其他可能影响其寿命的第三方应用程序(从 Android 3.1 开始,您可以强制停止所有这些应用程序以确保它们不会运行)。考虑关闭电子邮件同步等以消除图片中的噪音。

现在让您的应用程序以您认为应该的速度运行,看看它会减少多少电池寿命。会有一些,只是多少的问题。

此外,当您执行这些操作时,您需要关注在合理运行的系统上电池可以持续的最长时间以及您的应用程序如何影响它。用户的电池持续时间越长,您的应用对其影响就越大,因此这些人更有可能不满意并在市场上给出差评。

The basic rule is that the less you do the less you impact the battery. In other words, everything you do reduces the battery. If you are updating every minute, changing that to every 2 minutes will typically halve the drain on the battery.

But beyond that, there is no single number to give that is the "right" amount. You want to run as little as possible, doing as little work as possible.

Taking a look at the numbers you do is good, it gives you some idea of what your impact is. However they also aren't the whole story -- for example on some common CPUs simply holding a partial wake lock will cause battery drain.

A good way to look at this is that we want the battery on our devices to last at least N days, where N is at least one and really we'd like it to be more than one. If the device is not being used -- its screen is off -- it is still doing stuff in the background draining the battery: the phone radio is running, probably some things are syncing new e-mail and such on to the device, etc.

If the device wasn't doing that work, it would last for days and days and days. You can see this yourself: turn on airplane mode, make sure there aren't dumb apps doing stuff in the background still, and see how long your battery lasts. It can easily be a week.

So each little thing you do in the background isn't itself an issue. It is the aggregate of that work, in a world where we want to be running for days on a charge. And the longer the basic device can run on a charge, the more each of your little pieces of work reduces the battery life, because there is more time for you to run and drain it.

Ultimately, scheduling some work to happen every minute or more will reduce the user's battery life. How much that is depends on a lot of things: the power behavior of the hardware, how long the user can typically run on a charge, how long you run each of those times, the kinds of work you are doing.

One thing I would definitely recommend is just testing this app yourself, on your own device. Start with a baseline: leave your device sitting without use, and see how long it lasts. Be sure to not have other third party apps on it that could impact its life (starting with Android 3.1 you can just force stop all those apps to be sure they won't run). Consider turning off sync of e-mail and such to remove that noise from the picture.

Now put your app on it running at the amount you think it should, and see how much it reduces your battery life. It will be some, it is just a question of how much.

Also when you do these things, you want to focus on the longest time you can last on a battery on a reasonably running system and how your app impacts that. The longer a user's battery lasts, the more your app will impact it, and these thus are the ones who are more likely to be unhappy and give bad reviews on Market.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文