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

Search This thread

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
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 :eek:

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:
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? :eek: You didn't think I was doing this all for the love of the community did you?! ;)
 
Last edited:

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
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
 
Last edited:

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
Change Log

Code:
[B][U]V13[/U][/B]

* 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 [URL="http://xdaforums.com/member.php?u=2440628"]fubaya[/URL]
* Replaced all Test File actions
* Improved logic in almost every task
* Lots of other things I can't remember...

[B][U]V12[/U][/B]

* Uploaded [B]DSDAhocTIS [/B] in the V11 .zip file instead of [B]DSDAhTIS[/B] :mad:
Credit - [URL="http://xdaforums.com/member.php?u=2824949"]1337GamingNinja[/URL]

Please got to [URL="http://xdaforums.com/showpost.php?p=16089263&postcount=760"]this post[/URL] for the additional [B]DSDAhTIS[/B] download to the V11 .zip below

[B][U]V11[/U][/B]

* 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


[B][U]To Do[/U][/B]

* 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


[B][U]V10[/U][/B]

* 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...

[B][U]V9n[/U][/B]

* Added missing files! Thanks [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]

[B][U]V9[/U][/B]

* 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

[B][U]V8a[/U][/B]

[!] 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.

[B][U]V8[/U][/B]

* 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
* [strike]Added IF != 0 to %DSCON in set to % action of DSDNotify[/strike]
* 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 [URL="http://xdaforums.com/member.php?u=3390610"]waydownsouth[/URL]
* Cut report building time down to under [strike]10[/strike] 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...

[B][U]V7[/U][/B] 

* Removed due to a patent infringement claim by Apple 

[B][U]V6[/U][/B]

* Removed additional % in DSD-BootReport - credit [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]
* Reverted to linux/locale 'toolbox' commands for report information - credit [URL="http://xdaforums.com/member.php?u=2178960"]Pulser_g2[/URL]
* 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

[B][U]V5[/U][/B]

* Changed PSD to DSP in Flash action #33 in DSDAhMaths - TYPO! Thanks [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]
* 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.

[B][U]V4[/U][/B]

* 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

[B][U]V3[/U][/B]
* 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

[B][U]V2[/U][/B]
* 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... :eek:

The thanks meter lets me know I'm appreciated! :eek:
 

Attachments

  • DSD-V13.zip
    119.5 KB · Views: 3,294
Last edited:

neilix

Senior Member
Sep 6, 2010
66
18
Derby
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.
 

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
@ 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 ;)
 

lotherius

Inactive Recognized Developer
Jan 12, 2009
2,178
612
Houston, TX
Google Pixel 6
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.
 

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
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!
 

Attachments

  • DSDReport-V2.zip
    1.1 KB · Views: 57

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
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.

Well I hope in a few versions time this will be able to tell you... Messing with sleep preventing wakelocks right now...
 

nobnut

Senior Member
Feb 27, 2010
6,922
2,693
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!

I just realised something! There was no DSDReport in the original v1.0 zip.
 

nobnut

Senior Member
Feb 27, 2010
6,922
2,693
Yes, sorry about that.

Just tried it again (having granted SU before rebooting) similar thing happened.

I received a 'DS Data failure - Incorrect shutdown - Resetting Data' notification.

EDIT: I'm also getting a 'DS Data Failure' on subsequent reboots.

Report attached for information.
 

Attachments

  • DS-BootReport.txt
    1.9 KB · Views: 35
Last edited:

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
Yes, sorry about that.

Just tried it again (having granted SU before rebooting) similar thing happened.

I received a 'DS Data failure - Incorrect shutdown - Resetting Data' notification.

Damn it... That notification is happening because it is detecting %DSBOOT didn't set to 1 before shutdown, suggesting it didn't gather the necessary data to provide a full 'daily report'.

If you get time, could you let me know which data it did manage to gather by adjusting the task DSDDeviceBoot? Could you remove these actions:

IF %DSBOOT Not set
Notify vibrate DS Data Failure
GoTo action
End IF

That way it will continue to write the information it did gather to the file DS-BootReport.txt. A screen prompt should ask you if you want to view this file shortly after rebooting.

Please keep a copy of the original DSDDeviceBoot task so you can re-import it afterwards! Your thanks meter will be increasing.... :)
 

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
Just to confirm,

Line 1... Mine currently reads 'IF %DSBOOT Set'

What would you like me to do? Delete it or edit it and try again?

Is there not a '!' between %DSBOOT and Set ?

Thanks for the upload of the file - I'm very confused now though, as that file shouldn't be written if the DS failure notification triggered... :confused: What number is your GoTo action set to? Does it take you to the variable clear action right after the write file DS-BootReport ?

Thanks for this
 

nobnut

Senior Member
Feb 27, 2010
6,922
2,693
Set to 7.

Yes there is a '!', I was just checking.

Shall I go ahead and delete those lines?

EDIT: Yes, I am directed to the view/clear.

EDIT2: Deleted lines and now get a "DS Boot Report: 0%" notification.

When clicked, I am not redirected (no clear /view option).

EDIT3: Could the report be written when clicking 'Test' to get SU granted?
 
Last edited:

brandall

Senior Member
May 16, 2008
2,679
5,222
Birmingham
Set to 7.

Yes there is a '!', I was just checking.

Shall I go ahead and delete those lines?

EDIT: Yes, I am directed to the view/clear.

Thanks.

I don't understand how it can be applying both for you...? IF the failure notification action happens then it should go to action 7 which is after the write file action??

I can see from the text file you attached that your data is populating correctly (somehow!?) - No need to delete the actions for now as you're still getting the desire output - delete it if you find it annoying though!

I'm baffled as to how it is doing both actions regardless... hmmm - I'll have a ponder and come back - off to a meeting now. Thanks again for looking into this for me - appreciated.

EDIT2: Deleted lines and now get a "DS Boot Report: 0%" notification.

When clicked, I am not redirected (no clear /view option).

EDIT3: Could the report be written when clicking 'Test' to get SU granted?

When you make the changes, are you saving out of Tasker and going back in?? If it's providing a notification when the action is deleted, something is seriously wrong!!

Yes on the SuperUser idea... I didn't consider looking at the date/time as don't know what date/time zone you are from! Could you delete the text file please... Have to dash!!!

EDIT: I'll upload a changed version on my return if it's still functioning strangely
 
Last edited:
  • Like
Reactions: nobnut

Top Liked Posts

  • There are no posts matching your filters.
  • 62
    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 :eek:

    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:
    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? :eek: You didn't think I was doing this all for the love of the community did you?! ;)
    60
    Change Log

    Code:
    [B][U]V13[/U][/B]
    
    * 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 [URL="http://xdaforums.com/member.php?u=2440628"]fubaya[/URL]
    * Replaced all Test File actions
    * Improved logic in almost every task
    * Lots of other things I can't remember...
    
    [B][U]V12[/U][/B]
    
    * Uploaded [B]DSDAhocTIS [/B] in the V11 .zip file instead of [B]DSDAhTIS[/B] :mad:
    Credit - [URL="http://xdaforums.com/member.php?u=2824949"]1337GamingNinja[/URL]
    
    Please got to [URL="http://xdaforums.com/showpost.php?p=16089263&postcount=760"]this post[/URL] for the additional [B]DSDAhTIS[/B] download to the V11 .zip below
    
    [B][U]V11[/U][/B]
    
    * 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
    
    
    [B][U]To Do[/U][/B]
    
    * 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
    
    
    [B][U]V10[/U][/B]
    
    * 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...
    
    [B][U]V9n[/U][/B]
    
    * Added missing files! Thanks [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]
    
    [B][U]V9[/U][/B]
    
    * 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
    
    [B][U]V8a[/U][/B]
    
    [!] 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.
    
    [B][U]V8[/U][/B]
    
    * 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
    * [strike]Added IF != 0 to %DSCON in set to % action of DSDNotify[/strike]
    * 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 [URL="http://xdaforums.com/member.php?u=3390610"]waydownsouth[/URL]
    * Cut report building time down to under [strike]10[/strike] 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...
    
    [B][U]V7[/U][/B] 
    
    * Removed due to a patent infringement claim by Apple 
    
    [B][U]V6[/U][/B]
    
    * Removed additional % in DSD-BootReport - credit [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]
    * Reverted to linux/locale 'toolbox' commands for report information - credit [URL="http://xdaforums.com/member.php?u=2178960"]Pulser_g2[/URL]
    * 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
    
    [B][U]V5[/U][/B]
    
    * Changed PSD to DSP in Flash action #33 in DSDAhMaths - TYPO! Thanks [URL="http://xdaforums.com/member.php?u=2393301"]nobnut[/URL]
    * 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.
    
    [B][U]V4[/U][/B]
    
    * 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
    
    [B][U]V3[/U][/B]
    * 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
    
    [B][U]V2[/U][/B]
    * 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... :eek:

    The thanks meter lets me know I'm appreciated! :eek:
    15
    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
    4
    V13 Up!

    Overview

    S'up folks, long time...

    So, V13 has had a pretty major overhall and I really hope will be flawless on the logic side. Let me know!

    There will be a V14 as I've discovered some hidden gems within Android regarding active wakelocks during sleep (whoop!), but extracting this data and presenting it correctly is beyond my shell capabilities at present.. I need to spend a few hours alone with Google to get my head around it.

    Also, I've put in a request with the Tasker dev to convert com.blar.blar to the application name under the 'Test' action, so that I will indeed be able to honour my OP prediction of telling you the name of a specific troublesome application that has been holding wakelock.

    Finally, in V14 the reports will be in HTML format so the wakelocks can be hyperlinked to a Google search for more information, or killed immediately by using the Task/Process Killer script I wrote for Tasker many moons ago. I need the html viewer .apk to be installed via shell during set-up and this involves a little more reading for me too..

    Anyway, please read the set-up instructions below!

    Let me know your feedback folks!

    Change Log

    Code:
    [B][U]V13[/U][/B]
    
    * 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 [URL="http://xdaforums.com/member.php?u=2440628"]fubaya[/URL]
    * Replaced all Test File actions
    * Improved logic in almost every task
    * Lots of other things I can't remember...
    
    [B][U]To Do[/U][/B]
    
    * Solve Tasker media 'bug'

    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


    SuperUser

    After plenty of headaches, my findings are that the settings used in the SuperUser application can slow down the execution of processes/commands requiring root. I strongly suggest that under the preferences, you set Access timeout to '0' and the Automatic response to 'prompt'.

    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 (although mine appears in under a second!). 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... :eek:
    4
    @ Brandall

    you should look into the output of these terminal commands:
    Code:
    uptime
    Code:
    cat /proc/wakelocks

    HTH :)