FORUMS
Remove All Ads from XDA

[App] Tasker | The Deep-Sleep-Detective | V13 | Root ||

2,679 posts
Thanks Meter: 5,237
 
By brandall, Senior Member on 25th June 2011, 02:32 AM
Post Reply Email Thread
Profile Aim

Tasker will use a number of triggers to detect, log, monitor and report when your device has been in a deep-sleep state, and more importantly; when it hasn’t. The profiles identify both potential and actual deep-sleep-behaviour, providing statistics and real-time alerts should your device fail to enter deep-sleep in the absence of any common preventing factors. The alerts will enable you to identify the troublesome processes and applications that love to kill your battery.

Pushing Tasker to its Limits?

Composing this after just uploading V13, I can confidently say that I'm pretty sure I've now pushed Tasker to its limits when it comes to using its functionality and to build as close as I believe you can get to a fully fledged application:

* Installation tasks to inject binary and set permissions
* Tasks dynamically compose and execute shell scripts
* Automated and ad hoc error logging
* 'Self-checking' error loops
* Tasker/shell generated reporting
* Media and interactive notifications
* 28 intertwining tasks totalling 500+ actions triggered by 11 contexts

Theory

Finding out when your device has entered deep-sleep, is rather like asking someone to drop you a quick text as soon as they’ve died. As impossible as that sounds, you can of course always get them to let you know they aren’t dead; establish they are doing something else so currently can’t be dead; or discover they are indeed still alive and therefore conclude they weren’t dead in the first place…

I’ll stop talking in riddles and start where I started, which is when your device has the potential to enter deep-sleep:

* When the display is off

Yes, I know that was a pretty obvious one to start with, but if we just record potential deep-sleep-time as ‘screen off time’ we will be left with major inaccuracies such as:

* Media Playing
* During Call

And more importantly:

* Device charging

Those example factors already start to narrow down the times of when your device enters the zone of deep-sleep-potential (DSP).

Practice

We can retrospectively establish the amount of time the device has spent in deep-sleep, by looking at the file:
Code:
sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
Next to each available scaling frequency is the amount of time in milliseconds the device has spent at that frequency since last boot. This is my example file:
Code:
245760   319834
384000   4651
576000   3736
768000   2271
998400   6983
1113600  24953
The up-time of the device, less the sum of the individual frequency times, provides us with the amount of time that the CPU was not active = Total-Deep-Sleep-Time. We can compare this proportionally to the up-time and simply report deep-sleep as a percentage of the current usage (since last boot).

That is all well and good, but if the percentage is very low, it immediately suggests poor device performance and that may not be a true reflection. To make this figure more accurate (and perhaps less alarming) we first need to establish the DSP your device had and base our statistics on that.

Overview

Dealing with the obvious first, we know that DSP occurs only when the screen is off and ends when it turns back on. At the point the display goes off, we can take a log of the current up-time and compare it to the total time in frequency state. Subtracting one from the other gives us a constant we can refer to.

If the device does not enter deep-sleep prior to the screen turning back on, then performing the same calculations at the display on trigger should provide the same constant.

Any difference between the display off/on constants will notify us not only that the device has been in deep-sleep, but also for how long. This information can be immediately relayed and/or totalled up to be used against DSP times to build a more accurate, real-time and ongoing reflection of your device’s deep-sleep-behaviour (DSB).

Already starting to narrow down DSP times, and we can further exclude the events that were listed above (such as charging) from our DSP calculations.

Profiles and Tasks

I think I may have permanently damaged my brain making these profiles work, report and intertwine correctly… I have many further plans which I’ll list below – albeit theoretically….

Unlike my other Tasker posts, I’m not going to make this a tutorial (*group sigh?*), as in brief terms (which does not reflect the extent of my hair-loss), it keeps checking the time-in-state files against constants whilst making sure no DSP excluding factors or events are active. It performs a sh*t load of comparable percentages, converting a lot of milliseconds to hours and minutes to make it user-friendly for you. Yes, that was my hint to you to hit the thanks meter

Honestly, the thought of writing this one out in detail makes me feel bored, so I doubt it would make very exciting reading… The logic in the profiles is there to follow of course and I’ll be happy to answer any of your questions, but for once this really is just a ‘plug and go’ – there’s nothing for you to edit, other than perhaps choosing to align triggers with your existing set-up.

Future Development

It's my understanding that power management and wakelock debugging can only be implemented when Android is compiled and therefore we have no specific "I'm about to fall asleep, quick take a log" trigger to work with (I'd love you to tell me otherwise) for analysis, so as the profiles develop, more deep-sleep preventative 'events', such as receiving an SMS will be included in order to build a greater picture of what is happening before and after deep-sleep.

The ultimate goal would be to gather comparison logs to flag up the likely suspects for the device not entering deep-sleep in the first place or waking up from it too often. You can almost see the UI notification now:
Quote:

YouPorn Mobile and has been killing your battery - uninstall it by clicking here

That may be a few versions away, but we've all got to have a dream... and preferably one that involves every noob with battery issues downloading my application for a dollar from the market

What? You didn't think I was doing this all for the love of the community did you?!
The Following 63 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
25th June 2011, 02:32 AM |#2  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,237
 
Donate to Me
More
Simple Preparation

Before importing the profiles and tasks:

* Make sure you are running the latest version of Tasker 1.2u2
* Install the Glossy Silver HD icons apk (Open any existing task, click on the icon selection button - Download More Icons)
* Backup your profile data and tasks and a recent nandroid never does any harm.
* Ensure Tasker has 'Accessibility' and 'Administrator' permission on your device.

Installing instructions are in post #3
------------------------------

Ad-hoc

I've added in an ad-hoc task from V3, so you can check the statistics at any time. Easiest way to launch it is via an icon from your homescreen using a Tasker 'run task' widget, available in the widget options on your launcher. DSDAdhoc should be triggered first, which in turn will trigger further tasks and information will appear on your display.

Trigger Information

The profiles currently use the following triggers:

* Display On
* Display Off
* In Call
* Call End
* USB Plugged Power
* Device Boot
* Device Shut-down
* Media

Depending on your current set up, you may already have most of these contexts, so assuming you wish to keep the profiles installed, you may wish to use Perform Task actions as opposed to doubling them up. You must make sure these profiles run with a higher priority than your others to avoid the loops catching one another...

Files and Logs

The Deep Sleep Detective writes files to your SDCard:

DeepSleepDetective.txt is triggered when your device has not been in DS for more than 80% of DSP. It provides a list of your running applications, historic wakelocks, statistics and active wakelocks at the point the display was turned off - The information provided will become more specific and user friendly as the version go on.

DSD-BootLog.txt is triggered when the device boots up. It writes DSD statistics taken prior to the last shut-down.

A DSD directory is set-up that contains relevant files. There is also a back-up folder where previous Detective Reports will be stored so they are not overwritten.

-----------------------------------------
I'll add more to the above when I get time
-----------------------------------------

Credits
waydownsouth - HUGELY MASSIVE Terminal & Script help
nobnut - HUGELY MASSIVE amount of testing
Pulser_g2 - Solving my toolbox woes
The Following 16 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
25th June 2011, 02:33 AM |#3  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,237
 
Donate to Me
More
Change Log

Code:
V13

* Direct execute shell commands via Tasker (no longer use locale plugin)
* Changed logic for end call to prevent 'display off data stolen' errors
* Removed incorrect %DSCOFF variable clear in TIS tasks
* Corrected the DSDAdhocTIS upload
* Cleared errorlog.txt to avoid file failures
* Included toolbox generic tests in error log
* Populated XDA Username in error log and ReadMe
* Included busybox version in error log
* Let DisplayOff handle %NOCOUNT clearing
* Calculated time_in_state using shell (too many frequencies on recent devices)
* Included IF/ELSE logic in certain tasks
* Added failsafe for missing time_in_state files
* Set permissions using busybox to avoid permission to set permissions error!!
* Corrected binary PS request
* Increased data collected in error logging (nothing personal of course).
* Tried my best to make notification click work correctly...
* Collected DSP data when incoming call wakes from sleep and display goes off.
* Included Tasker version number in error log - credit fubaya
* Replaced all Test File actions
* Improved logic in almost every task
* Lots of other things I can't remember...

V12

* Uploaded DSDAhocTIS  in the V11 .zip file instead of DSDAhTIS :mad:
Credit - 1337GamingNinja

Please got to this post for the additional DSDAhTIS download to the V11 .zip below

V11

* Inserted IF to deal with %CPUDSD being set to 'EOF' in DSDADhoc & DSDDO
* Inserted 'variable add' in DSDNotify to deal with %DSCOFF being set to zero on first display off'
* Included uptime output in error log
* Included %DSDDO & %CPUDSD in error log
* Added %UTEOF, %TISW & %UTW variables and loops to diagnose read/timing errors
* Added uptime fail-safe with routed task to time_in_state
* Added notification short-cut 'on-click' actions
* Included DSD version number in error log
* Added standard 2 second reduction to %DISPOFFINT due to lag
* Stopped scrolling notifications when in call
* Changed permissions levels
* Added flag-pass variable to prevent overlap
* Added 5 second wait to display off/on profiles to handle screen on/off 'flicks'
* Increased intelligence of loop checks
* Added sound to certain events
* Included ROM version in error reporting
* Removed %DSCL loop in favour of odd/even flag-pass
* Fixed %NOCOUNT prevention
* Included a second shutdown profile in case toolbox method is failing
* Moved binary folder inside DSD folder for ease
* Included Adhoc error reporting to save user requests
* Prevented cancelling all Tasker notifications on display off


To Do

* Make the information in the Detective Report more user friendly and understandable
* Receivers for wakeups during deep-sleep
* Solve Tasker media 'bug'
* Include Tasker version number in error log - Dev including in next beta


V10

* Called time in state data via script to avoid permission errors
* Reverted DSDDO, DSDShutdown, DSDAdhoc to the above
* Added wait times and loops to allow for delays
* Removed DSDXDAUN as it was too buggy
* Reordered tasks to allow for multiple calls of single script
* Removed directory/file making tasks to minimise possible set-up errors
* Removed unnecessary permissions from script
* Added further dynamic script controls to increase speed of shutdown task
* A few more bits and bobs...

V9n

* Added missing files! Thanks nobnut

V9

* More notifications of what is going on to update the user and identify error sources
* Error logging and request to email the details included
* Updated reporting tools and information
* Increased intelligence of tasks
* Included 'self-checking' of necessary actions
* Standard binary injection
* Standard file permissions on boot
* Fixed screen off/on/power/on/off entanglement
* Updated aesthetics

V8a

[!] Sorry to those that have already downloaded V8, but I needed to make changes for the reports to function correctly - Damn those SU requests!

* Changed set-up tasks to try and ensure SU requests are approved.

V8

* Added preventative for %DSCOFF failing to populate in DSDDO
* Added notification to DSDDisplayOn if DSP was unavailable during screen off time
* Added wakelock capture to DSDDisplayOff
* Added IF != 0 to %DSCON in set to % action of DSDNotify
* Added wakelock hunter to DSDDisplayOff
* Changed multiple locale commands to shell script dynamically composed by Tasker
* Added script to match wakelocks to owner applications/processes - BIG thanks to waydownsouth
* Cut report building time down to under 10 5 seconds
* Added IF and GoTo actions to avoid the bad maths eval errors on constants
* Added DSDSetUp task with ReadMe.txt
* DSDSetUp to create directories and files
* Added 'spoiler' preventing to DSDNotify
* Added display off media context
* Added Further test file actions to avoid empty reports
* Changed collision handling and task priorities
* Added additional variable clear actions to avoid possible data corruption
* Too many more to list...

V7 

* Removed due to a patent infringement claim by Apple 

V6

* Removed additional % in DSD-BootReport - credit nobnut
* Reverted to linux/locale 'toolbox' commands for report information - credit Pulser_g2
* Reverted to Tasker handling all calculations - Speed Test proved Locale Plugin to be much slower
* Removed pop-up tasks as they are fugly
* Added 'wait until' actions before %CPUTIS to ensure data from file is written

V5

* Changed PSD to DSP in Flash action #33 in DSDAhMaths - TYPO! Thanks nobnut
* Removed unneeded variable clear action in DSDNotify
* Ticked missing 'do maths' in action #13 of DSDAdhoc
* Added minimal uptime threshold until tasks are expected to perform maths to avoid data corruption
* Corrected %CPUDSDD error in action #8 of DSShutdown
* Corrected adding X% in DSD-Shutdown write file action as '%' is looked for for errors... Oops.
* Removed append from above write action to minimise possible errors.
* Added functionality to sum scaling frequencies using locale
* Added above command to DSDSuperuser, DSDAdhoc & DSDDO
* Added additional variable clear caution in DSDDO to avoid %CPUDSDD1 & %CPUTISD1 being used.

V4

* Append box should be unticked in action #1 of DSDShutdown
* Corrected variable clear data in %DSDDO
* Added variable clear %DSDDOS to end DSDDispOn
* Added file existence check to DSDDeviceBoot
* Added safety value to %DISPOFFT to prevent knock-on failures if not set
* Reverted to V1 DSDDO due to toolbox differences in devices
* Reverted to V2 DSDAdhoc due to toolbox differences in devices
* Removed unneeded actions from DSDSuperUser due to revert
* Added '+' '-' & 'Zzzz' popups to confirm task flow
* Added DSDAdhoc into .zip
* Reverted to V2 DSDShutdown due to toolbox differences in devices

V3
* Removed 'append' from action #1 of DSDShutdown to avoid looping data corruption
* Corrected error in IF statement in the task DSDIntMaths
* Added 400ms wait task after locale fetch in #2 of DSDDO
* Ad-hoc tasks added so information can be viewed at any time
* Restructured A LOT of the tasks 
* Included more information in report files
* Lots more I've forgotten

V2
* Changed 'between boot report maths' to boot instead of trying to rush them in before shutdown
* Used locale/linux to perform some of the maths as I assume it's quicker?
* Cut down task sizes due to above
* Altered structure of output files for easy reading
* MASSIVE boot task that hurt my brain
Bugs

* Transition power on/off / display on/off + incall - Solved in V9
* Binary package differences from device to device - Solved in V6 - Credit Pulser_g2
* DSDAdhoc providing erroneous results on first run after charge - Solved V6
* SGSII needs different files - post if you need them - Solved in V4
* DS Data Failure Notification on boot - Solved in V2
* I'm getting a prompt to click on a file at boot, but it fails? - Solved in V2
* I'm getting Not Numeric errors when I open Tasker - Solved in V3
* I'm getting an error %CPUDSDD is not numeric? - Solved in V3
* DSDDeviceBoot is not running correctly? - Solved in V3
* The boot file isn't being written? - Solved in V3

* Media profile is deactivating when the music application is no longer in the foreground - Dirty solution for now is to switch the screen off only when you are in the application... - I'm on it

Installation Instructions

* Delete all profiles and DSD* tasks from Tasker
* Delete all DSD* profiles and DSD* tasks from the folders Tasker/Profiles & Tasker/Tasks
* Unzip the latest version download
* Place the task files in /sdcard/Tasker/Tasks
* Place the profile files in /sdcard/Tasker/Profiles
* Place the folder DSD on the root of your storage card (after deleting/renaming any current folder from a previous version)

In Tasker, from the menu options/profile data 'Import One (15) Task':

DSDDON
DSDDONTIS
DSDDOFF
DSDDOFFTIS
DSDIntMaths
DSDNotify
DSDAdhoc
DSDAdhTIS
DSDAhMathsDST
DSDAhMathsUPS
DSDFileSetUp
DSDSUPOP
DSDSuperUser
DSDWakelock
DSDErrorLog


In menu options/profile data 'Import One (11) Profile':

DSD-DisplayOn
DSD-DisplayOff
DSD-Incall
DSD-EndCall
DSD-Power
DSD-Boot
DSD-ShutDSH
DSD-ShutDTIS
DSD-Notify
DSD-Reboot
DSD-Media


The above profiles also contain the following 13 tasks, which will be automatically imported:

DSDDispOn
DSDDispOff
DSDDeviceBoot
DSDDuringCall
DSDEndCall
DSDCharging
DSDChargeEnd
DSDMedia
DSDMediaEnd
DSDNClick
DSDShutDSH
DSDShutDTIS
DSDReboot


First Run

* Ensure all of the task and profiles imported correctly
* Save out of Tasker to preserve the changes made
* Load Tasker and select the task DSDSuperUser

Thanks to nobnut and his testing, I've been able to establish that the SuperUser requests can take up to 30 seconds to appear. There is only one command that needs permission. DSDSuperUser has a 30 second wait time to give the SuperUser application a chance to prompt. If it hasn't appeared by the end of the wait time, there is a pop up asking if you want to run the task again - I hope you'll only need to run it once though!

* Press 'test' in DSDSuperUser and follow the instructions from there! PLEASE do read the readme file as it contains other important instructions!

Let's get detecting...

The thanks meter lets me know I'm appreciated!
Attached Files
File Type: zip DSD-V13.zip - [Click for QR Code] (119.5 KB, 3202 views)
The Following 61 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
25th June 2011, 03:00 AM |#4  
Member
Derby
Thanks Meter: 18
 
More
Oooh, me likey.

It's a shame you decided against the tutorial part as normally I just read that bit, nick the ideas, and write my own profiles.

Still, this could come in extremely handy. Keep up the good work.
25th June 2011, 04:09 AM |#5  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,237
 
Donate to Me
More
Quote:
Originally Posted by neilix

Oooh, me likey.

It's a shame you decided against the tutorial part as normally I just read that bit, nick the ideas, and write my own profiles.

Still, this could come in extremely handy. Keep up the good work.

Thief!

Maybe I'll explain a little... Perhaps a YouTube video is the way forward...
The Following User Says Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
26th June 2011, 08:28 PM |#6  
nobnut's Avatar
Senior Member
Thanks Meter: 2,705
 
More
What should have been provided within Android by default. Excellent idea.
The Following 2 Users Say Thank You to nobnut For This Useful Post: [ View ] Gift nobnut Ad-Free
27th June 2011, 12:21 AM |#7  
Senior Member
Thanks Meter: 811
 
More
@ Brandall

you should look into the output of these terminal commands:
Code:
uptime
Code:
cat /proc/wakelocks
HTH
The Following 4 Users Say Thank You to waydownsouth For This Useful Post: [ View ] Gift waydownsouth Ad-Free
27th June 2011, 12:44 AM |#8  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,237
 
Donate to Me
More
Quote:
Originally Posted by waydownsouth

@ Brandall

you should look into the output of these terminal commands:

Code:
uptime
Code:
cat /proc/wakelocks
HTH

Thanks waydownsouth, you were already getting a big credit in this thread as it was! Knowing I could output sleep-time would have saved me a few lines of maths!

Understanding how the cat /proc/wakelocks output could identify a deep-sleep preventer is probably going to take a few more nights on Google! You best sign out of G-talk
The Following 2 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
27th June 2011, 11:12 AM |#9  
lotherius's Avatar
Inactive Recognized Developer
Flag Houston, TX
Thanks Meter: 610
 
Donate to Me
More
Watching with Interest as I've noticed (since I've got Gingerbread battery logging that actually shows such info) that *something* has been keep my device on partial-wake at night, but not EVERY night, just some nights. Haven't been able to identify WHAT yet, as it isn't making itself known through any abnormal CPU usage, just by the fact my device doesn't go to deep sleep and thus drains battery more than it should.
27th June 2011, 11:39 AM |#10  
nobnut's Avatar
Senior Member
Thanks Meter: 2,705
 
More
Hi, I'm getting the notification on reboot that shutdown didn't go correctly.
The Following 2 Users Say Thank You to nobnut For This Useful Post: [ View ] Gift nobnut Ad-Free
27th June 2011, 12:26 PM |#11  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,237
 
Donate to Me
More
Quote:
Originally Posted by nobnut

Hi, I'm getting the notification on reboot that shutdown didn't go correctly.

Thanks for letting me know - At least I know the boot notification is working!

Attached is the V2 version I'm working on. In case you need instructions (I never know anyone's level): After you've imported it, click on DSDReport in the profile screen, click add, select DSDReportV2 - then delete DSDReport.

I hope this one runs quicker... You'll need to give it SuperUser permissions as normal, so please 'test' it a couple of times before trying out a reboot...

Please let me know it works!
Attached Files
File Type: zip DSDReport-V2.zip - [Click for QR Code] (1.1 KB, 52 views)
The Following 2 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
Post Reply Subscribe to Thread

Tags
cpu, deep-sleep, lovesauce battery babies, profile, tasker

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes