Merge "Add SkDestroyListener log in dumpsys netstats" into main
This commit is contained in:
commit
65b4c3f0f1
3 changed files with 33 additions and 1 deletions
|
|
@ -481,6 +481,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||
@Nullable
|
||||
private final SkDestroyListener mSkDestroyListener;
|
||||
|
||||
private static final int MAX_SOCKET_DESTROY_LISTENER_LOGS = 20;
|
||||
|
||||
private static @NonNull Clock getDefaultClock() {
|
||||
return new BestClock(ZoneOffset.UTC, SystemClock.currentNetworkTimeClock(),
|
||||
Clock.systemUTC());
|
||||
|
|
@ -881,7 +883,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||
/** Create a new SkDestroyListener. */
|
||||
public SkDestroyListener makeSkDestroyListener(
|
||||
IBpfMap<CookieTagMapKey, CookieTagMapValue> cookieTagMap, Handler handler) {
|
||||
return new SkDestroyListener(cookieTagMap, handler, new SharedLog(TAG));
|
||||
return new SkDestroyListener(
|
||||
cookieTagMap, handler, new SharedLog(MAX_SOCKET_DESTROY_LISTENER_LOGS, TAG));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2912,6 +2915,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||
dumpStatsMapLocked(mStatsMapB, pw, "mStatsMapB");
|
||||
dumpIfaceStatsMapLocked(pw);
|
||||
pw.decreaseIndent();
|
||||
|
||||
pw.println();
|
||||
pw.println("SkDestroyListener logs:");
|
||||
pw.increaseIndent();
|
||||
mSkDestroyListener.dump(pw);
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import com.android.net.module.util.netlink.InetDiagMessage;
|
|||
import com.android.net.module.util.netlink.NetlinkMessage;
|
||||
import com.android.net.module.util.netlink.StructInetDiagSockId;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Monitor socket destroy and delete entry from cookie tag bpf map.
|
||||
*/
|
||||
|
|
@ -72,4 +74,11 @@ public class SkDestroyListener extends NetlinkMonitor {
|
|||
mLog.e("Failed to delete CookieTagMap entry for " + sockId.cookie + ": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the contents of SkDestroyListener log.
|
||||
*/
|
||||
public void dump(PrintWriter pw) {
|
||||
mLog.reverseDump(pw);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
|
|||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
|
@ -130,6 +131,7 @@ import android.system.ErrnoException;
|
|||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -2802,4 +2804,16 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||
final String dump = getDump();
|
||||
assertDumpContains(dump, pollReasonNameOf(POLL_REASON_RAT_CHANGED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDumpSkDestroyListenerLogs() throws ErrnoException {
|
||||
doAnswer((invocation) -> {
|
||||
final IndentingPrintWriter ipw = (IndentingPrintWriter) invocation.getArgument(0);
|
||||
ipw.println("Log for testing");
|
||||
return null;
|
||||
}).when(mSkDestroyListener).dump(any());
|
||||
|
||||
final String dump = getDump();
|
||||
assertDumpContains(dump, "Log for testing");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue