Good point :-), here's the plan: I'm writing an app to find out what apps are using the most CPU time (which I hope will correlate with battery drain). It's possible to get a snapshot picture of this by looking at /proc: http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/annotate/head%3A/src/net/launchpad/drainometer/proc/ProcSnapshot.java
A single snapshot picture will however miss apps that start, run for some time and then exit. So what I want to do is to take *regular* snapshots. I take the difference between the last two snapshots and add the difference to a process name -> number of ticks Map. Snapshotting rules are: * Snapshots should be taken at regular intervals. * The first two snapshots should be taken in quick succession to be able to quickly present the first measurement to the user. * It must be possible for an UI app to look at the result of the snapshotting. To get the whole thing going, I'm letting the UI part of the application start the sampler in the background. When the sampling is first started it needs to take two snapshots quickly (see above). The rest of the samples should be taken at longer intervals. I first tried to do this using alarms, but I didn't manage to get the "two quick samples first and the rest further apart" behavior with alarms: http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/files/39 I now have a working implementation with a background service: http://bazaar.launchpad.net/~walles/drain-o-meter/trunk/files/57 Suggestions on how I should *really* be doing welcome :-). Cheers //Johan On 9 Sep, 16:47, Mark Murphy <mmur...@commonsware.com> wrote: > Walleswrote: > > I'll use a Service instead of an Alarm and keep it running in the > > background. That way I can keep track of it myself. > > Please don't. For starters, it won't work, since the service may get > killed off by the user or the system. Also, while the service is in > memory, you are taking up one process' worth of RAM. > > If you could explain to us what the effect is you are trying to achieve > (versus low-level technical statements, like "not to overwrite an > existing alarm with a new one"), we might be able to suggest alternative > patterns. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > _Android Programming Tutorials_ Version 1.0 In Print! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---