Keep debug information in NetworkStats files

Create two special SETs.

SET_DBG_VPN_IN is used by individual applications to know
how much traffic of the NetworkIdentity was actually moved
from a VPN app.
SET_DBG_VPN_OUT is used by the VPN app to know how much
traffic of the NetworkIdentity was deducted.

A debug application can restore the raw stats by these
entries.
  raw_traffic = recorded_entry (TAG_NONE, SET_ALL)
              + recorded_entry (TAG_NONE, SET_DBF_VPN_OUT)
              - recorded_entry (TAG_NONE, SET_DBF_VPN_IN)

The two debug SETs are not returned by
NetworkStatsService.openSession(). These debug entries are
retrieved by NetworkStatsCollection.dump().

Bug: 19536273
Change-Id: I03ef9f7667f5f2f48cbe3f6b11447fe7ead8ad3b
This commit is contained in:
Wenchao Tong
2015-03-17 16:14:23 -07:00
parent b293e46f2c
commit efd57ecab8
2 changed files with 44 additions and 4 deletions

View File

@@ -182,8 +182,7 @@ public class NetworkStatsCollection implements FileRotator.Reader {
for (int i = 0; i < mStats.size(); i++) {
final Key key = mStats.keyAt(i);
final boolean setMatches = set == SET_ALL || key.set == set;
if (key.uid == uid && setMatches && key.tag == tag
if (key.uid == uid && NetworkStats.setMatches(set, key.set) && key.tag == tag
&& templateMatches(template, key.ident)) {
final NetworkStatsHistory value = mStats.valueAt(i);
combined.recordHistory(value, start, end);
@@ -209,7 +208,8 @@ public class NetworkStatsCollection implements FileRotator.Reader {
final int callerUid = Binder.getCallingUid();
for (int i = 0; i < mStats.size(); i++) {
final Key key = mStats.keyAt(i);
if (templateMatches(template, key.ident) && isAccessibleToUser(key.uid, callerUid)) {
if (templateMatches(template, key.ident) && isAccessibleToUser(key.uid, callerUid)
&& key.set < NetworkStats.SET_DEBUG_START) {
final NetworkStatsHistory value = mStats.valueAt(i);
historyEntry = value.getValues(start, end, now, historyEntry);
@@ -542,6 +542,7 @@ public class NetworkStatsCollection implements FileRotator.Reader {
final NetworkStatsHistory value = mStats.valueAt(i);
if (!templateMatches(groupTemplate, key.ident)) continue;
if (key.set >= NetworkStats.SET_DEBUG_START) continue;
final Key groupKey = new Key(null, key.uid, key.set, key.tag);
NetworkStatsHistory groupHistory = grouped.get(groupKey);