diff options
| author | 2019-04-23 21:57:09 +0000 | |
|---|---|---|
| committer | 2019-04-23 21:57:09 +0000 | |
| commit | 32b47dece456a16865b160152be56f9e6b6dda6e (patch) | |
| tree | ab7d9b817a7e84c4504115c9f4a6d7ae99d4a5b4 | |
| parent | 388f6726ea5bfbf34d8fdb1bdb9328afa9ed6953 (diff) | |
| parent | db910397907965142667ef60f34a242861606abd (diff) | |
Merge "Ask netd to swap stats map before reading" into qt-dev
| -rw-r--r-- | services/core/java/com/android/server/net/NetworkStatsFactory.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/net/NetworkStatsFactory.java b/services/core/java/com/android/server/net/NetworkStatsFactory.java index 174f60091d21..69efd02dea9c 100644 --- a/services/core/java/com/android/server/net/NetworkStatsFactory.java +++ b/services/core/java/com/android/server/net/NetworkStatsFactory.java @@ -24,7 +24,10 @@ import static android.net.NetworkStats.UID_ALL; import static com.android.server.NetworkManagementSocketTagger.kernelToTag; import android.annotation.Nullable; +import android.net.INetd; import android.net.NetworkStats; +import android.net.util.NetdService; +import android.os.RemoteException; import android.os.StrictMode; import android.os.SystemClock; @@ -65,6 +68,8 @@ public class NetworkStatsFactory { private boolean mUseBpfStats; + private INetd mNetdService; + // A persistent Snapshot since device start for eBPF stats @GuardedBy("mPersistSnapshot") private final NetworkStats mPersistSnapshot; @@ -274,6 +279,19 @@ public class NetworkStatsFactory { return stats; } + @GuardedBy("mPersistSnapshot") + private void requestSwapActiveStatsMapLocked() throws RemoteException { + // Ask netd to do a active map stats swap. When the binder call successfully returns, + // the system server should be able to safely read and clean the inactive map + // without race problem. + if (mUseBpfStats) { + if (mNetdService == null) { + mNetdService = NetdService.getInstance(); + } + mNetdService.trafficSwapActiveStatsMap(); + } + } + // TODO: delete the lastStats parameter private NetworkStats readNetworkStatsDetailInternal(int limitUid, String[] limitIfaces, int limitTag, NetworkStats lastStats) throws IOException { @@ -287,6 +305,13 @@ public class NetworkStatsFactory { } if (mUseBpfStats) { synchronized (mPersistSnapshot) { + try { + requestSwapActiveStatsMapLocked(); + } catch (RemoteException e) { + throw new IOException(e); + } + // Stats are always read from the inactive map, so they must be read after the + // swap if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL, null, TAG_ALL, mUseBpfStats) != 0) { throw new IOException("Failed to parse network stats"); |