public class NetworkStatsRecorder extends Object
NetworkStats
snapshots into
NetworkStatsHistory
that belong to NetworkStatsCollection
.
Keeps pending changes in memory until they pass a specific threshold, in
bytes. Uses FileRotator
for persistence logic if present.
Not inherently thread safe.
Modifier and Type | Class and Description |
---|---|
static class |
NetworkStatsRecorder.RemoveUidRewriter
Rewriter that will remove any
NetworkStatsHistory attributed to
the requested UID, only writing data back when modified. |
Constructor and Description |
---|
NetworkStatsRecorder()
Non-persisted recorder, with only one bucket.
|
NetworkStatsRecorder(FileRotator rotator,
NetworkStats.NonMonotonicObserver<String> observer,
DropBoxManager dropBox,
String cookie,
long bucketDuration,
boolean onlyTags)
Persisted recorder.
|
Modifier and Type | Method and Description |
---|---|
void |
dumpCheckin(PrintWriter pw,
long start,
long end) |
void |
dumpLocked(IndentingPrintWriter pw,
boolean fullHistory) |
void |
forcePersistLocked(long currentTimeMillis)
Force persisting any pending deltas.
|
NetworkStatsCollection |
getOrLoadCompleteLocked()
Load complete history represented by
FileRotator . |
NetworkStatsCollection |
getOrLoadPartialLocked(long start,
long end) |
NetworkStatsCollection |
getSinceBoot() |
NetworkStats.Entry |
getTotalSinceBootLocked(NetworkTemplate template) |
void |
importLegacyNetworkLocked(File file) |
void |
importLegacyUidLocked(File file) |
void |
maybePersistLocked(long currentTimeMillis)
Consider persisting any pending deltas, if they are beyond
mPersistThresholdBytes . |
void |
recordSnapshotLocked(NetworkStats snapshot,
Map<String,NetworkIdentitySet> ifaceIdent,
VpnInfo[] vpnArray,
long currentTimeMillis)
Record any delta that occurred since last
NetworkStats snapshot,
using the given Map to identify network interfaces. |
void |
removeUidsLocked(int[] uids)
Remove the given UID from all
FileRotator history, migrating it
to TrafficStats.UID_REMOVED . |
void |
resetLocked() |
void |
setPersistThreshold(long thresholdBytes) |
public NetworkStatsRecorder()
NetworkStatsObservers
.public NetworkStatsRecorder(FileRotator rotator, NetworkStats.NonMonotonicObserver<String> observer, DropBoxManager dropBox, String cookie, long bucketDuration, boolean onlyTags)
public void setPersistThreshold(long thresholdBytes)
public void resetLocked()
public NetworkStats.Entry getTotalSinceBootLocked(NetworkTemplate template)
public NetworkStatsCollection getSinceBoot()
public NetworkStatsCollection getOrLoadCompleteLocked()
FileRotator
. Caches
internally as a WeakReference
, and updated with future
#recordSnapshotLocked(NetworkStats, Map, long)
snapshots as long
as reference is valid.public NetworkStatsCollection getOrLoadPartialLocked(long start, long end)
public void recordSnapshotLocked(NetworkStats snapshot, Map<String,NetworkIdentitySet> ifaceIdent, VpnInfo[] vpnArray, long currentTimeMillis)
NetworkStats
snapshot,
using the given Map
to identify network interfaces. First
snapshot is considered bootstrap, and is not counted as delta.vpnArray
- Optional info about the currently active VPN, if any. This is used to
redistribute traffic from the VPN app to the underlying responsible apps.
This should always be set to null if the provided snapshot is aggregated
across all UIDs (e.g. contains UID_ALL buckets), regardless of VPN state.public void maybePersistLocked(long currentTimeMillis)
mPersistThresholdBytes
.public void forcePersistLocked(long currentTimeMillis)
public void removeUidsLocked(int[] uids)
FileRotator
history, migrating it
to TrafficStats.UID_REMOVED
.public void importLegacyNetworkLocked(File file) throws IOException
IOException
public void importLegacyUidLocked(File file) throws IOException
IOException
public void dumpLocked(IndentingPrintWriter pw, boolean fullHistory)
public void dumpCheckin(PrintWriter pw, long start, long end)