@@ -1095,6 +1095,16 @@ private final String formatBytesLocked(long bytes) {
10951095 }
10961096 }
10971097
1098+ private static long computeWakeLock (Timer timer , long batteryRealtime , int which ) {
1099+ if (timer != null ) {
1100+ // Convert from microseconds to milliseconds with rounding
1101+ long totalTimeMicros = timer .getTotalTimeLocked (batteryRealtime , which );
1102+ long totalTimeMillis = (totalTimeMicros + 500 ) / 1000 ;
1103+ return totalTimeMillis ;
1104+ }
1105+ return 0 ;
1106+ }
1107+
10981108 /**
10991109 *
11001110 * @param sb a StringBuilder object.
@@ -1109,9 +1119,7 @@ private static final String printWakeLock(StringBuilder sb, Timer timer,
11091119 long batteryRealtime , String name , int which , String linePrefix ) {
11101120
11111121 if (timer != null ) {
1112- // Convert from microseconds to milliseconds with rounding
1113- long totalTimeMicros = timer .getTotalTimeLocked (batteryRealtime , which );
1114- long totalTimeMillis = (totalTimeMicros + 500 ) / 1000 ;
1122+ long totalTimeMillis = computeWakeLock (timer , batteryRealtime , which );
11151123
11161124 int count = timer .getCountLocked (which );
11171125 if (totalTimeMillis != 0 ) {
@@ -1735,6 +1743,8 @@ public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUi
17351743
17361744 Map <String , ? extends BatteryStats .Uid .Wakelock > wakelocks = u .getWakelockStats ();
17371745 if (wakelocks .size () > 0 ) {
1746+ long totalFull = 0 , totalPartial = 0 , totalWindow = 0 ;
1747+ int count = 0 ;
17381748 for (Map .Entry <String , ? extends BatteryStats .Uid .Wakelock > ent
17391749 : wakelocks .entrySet ()) {
17401750 Uid .Wakelock wl = ent .getValue ();
@@ -1754,6 +1764,44 @@ public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUi
17541764 // Only print out wake locks that were held
17551765 pw .println (sb .toString ());
17561766 uidActivity = true ;
1767+ count ++;
1768+ }
1769+ totalFull += computeWakeLock (wl .getWakeTime (WAKE_TYPE_FULL ),
1770+ batteryRealtime , which );
1771+ totalPartial += computeWakeLock (wl .getWakeTime (WAKE_TYPE_PARTIAL ),
1772+ batteryRealtime , which );
1773+ totalWindow += computeWakeLock (wl .getWakeTime (WAKE_TYPE_WINDOW ),
1774+ batteryRealtime , which );
1775+ }
1776+ if (count > 1 ) {
1777+ if (totalFull != 0 || totalPartial != 0 || totalWindow != 0 ) {
1778+ sb .setLength (0 );
1779+ sb .append (prefix );
1780+ sb .append (" TOTAL wake: " );
1781+ boolean needComma = false ;
1782+ if (totalFull != 0 ) {
1783+ needComma = true ;
1784+ formatTimeMs (sb , totalFull );
1785+ sb .append ("full" );
1786+ }
1787+ if (totalPartial != 0 ) {
1788+ if (needComma ) {
1789+ sb .append (", " );
1790+ }
1791+ needComma = true ;
1792+ formatTimeMs (sb , totalPartial );
1793+ sb .append ("partial" );
1794+ }
1795+ if (totalWindow != 0 ) {
1796+ if (needComma ) {
1797+ sb .append (", " );
1798+ }
1799+ needComma = true ;
1800+ formatTimeMs (sb , totalWindow );
1801+ sb .append ("window" );
1802+ }
1803+ sb .append (" realtime" );
1804+ pw .println (sb .toString ());
17571805 }
17581806 }
17591807 }
0 commit comments