From dcaeff31759fc2c7fecb44616c971ab1597fe45c Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 25 Aug 2011 17:48:52 -0700 Subject: [PATCH] Always splice historical data stats, debug info. When reading network counters, always splice in xt_qtaguid values to avoid counting backwards. Test to verify. Remove verbose logging around global alerts, and add dumpsys debug info for NMS and MDST. Also fix subtle bug around stats persisting and dumping. Bug: 5212893, 5211028 Change-Id: I783e5286637a67ee2dd2b09878198711a926d0cb --- core/java/android/net/NetworkStats.java | 8 +++++++- core/java/android/net/NetworkStatsHistory.java | 12 ++++++------ .../com/android/server/net/NetworkStatsService.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java index 5b883a0741..e5f32735b0 100644 --- a/core/java/android/net/NetworkStats.java +++ b/core/java/android/net/NetworkStats.java @@ -19,6 +19,7 @@ package android.net; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; +import android.util.Log; import android.util.SparseBooleanArray; import com.android.internal.util.Objects; @@ -38,6 +39,8 @@ import java.util.HashSet; * @hide */ public class NetworkStats implements Parcelable { + private static final String TAG = "NetworkStats"; + /** {@link #iface} value when interface details unavailable. */ public static final String IFACE_ALL = null; /** {@link #uid} value when UID details unavailable. */ @@ -397,7 +400,10 @@ public class NetworkStats implements Parcelable { if (enforceMonotonic && (entry.rxBytes < 0 || entry.rxPackets < 0 || entry.txBytes < 0 || entry.txPackets < 0 || entry.operations < 0)) { - throw new IllegalArgumentException("found non-monotonic values"); + Log.v(TAG, "lhs=" + this); + Log.v(TAG, "rhs=" + value); + throw new IllegalArgumentException( + "found non-monotonic values at lhs[" + i + "] - rhs[" + j + "]"); } if (clampNegative) { entry.rxBytes = Math.max(0, entry.rxBytes); diff --git a/core/java/android/net/NetworkStatsHistory.java b/core/java/android/net/NetworkStatsHistory.java index b19949e39d..d07d8990d7 100644 --- a/core/java/android/net/NetworkStatsHistory.java +++ b/core/java/android/net/NetworkStatsHistory.java @@ -482,12 +482,12 @@ public class NetworkStatsHistory implements Parcelable { for (int i = start; i < bucketCount; i++) { pw.print(prefix); pw.print(" bucketStart="); pw.print(bucketStart[i]); - if (activeTime != null) pw.print(" activeTime="); pw.print(activeTime[i]); - if (rxBytes != null) pw.print(" rxBytes="); pw.print(rxBytes[i]); - if (rxPackets != null) pw.print(" rxPackets="); pw.print(rxPackets[i]); - if (txBytes != null) pw.print(" txBytes="); pw.print(txBytes[i]); - if (txPackets != null) pw.print(" txPackets="); pw.print(txPackets[i]); - if (operations != null) pw.print(" operations="); pw.print(operations[i]); + if (activeTime != null) { pw.print(" activeTime="); pw.print(activeTime[i]); } + if (rxBytes != null) { pw.print(" rxBytes="); pw.print(rxBytes[i]); } + if (rxPackets != null) { pw.print(" rxPackets="); pw.print(rxPackets[i]); } + if (txBytes != null) { pw.print(" txBytes="); pw.print(txBytes[i]); } + if (txPackets != null) { pw.print(" txPackets="); pw.print(txPackets[i]); } + if (operations != null) { pw.print(" operations="); pw.print(operations[i]); } pw.println(); } } diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 80ae9bc6cb..bb0a0d132b 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -707,7 +707,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mLastPersistUidSnapshot, uidSnapshot, true); if (forcePersist || persistUidDelta.getTotalBytes() > persistThreshold) { writeUidStatsLocked(); - mLastPersistNetworkSnapshot = networkSnapshot; + mLastPersistUidSnapshot = networkSnapshot; } }