Migrate NetworkStack metrics off StatsLog.write

Now that the new metrics API can be used, NetworkStack
metrics need to migrate off the legacy StatsLog.write.

Bug: 130323000
Test: Test with ./out/host/linux-x86/bin/statsd_testdrive 121
      to ensure log properly
Test: Ensure NetworkStackStatsLog will be generated as expected
Test: atest NetworkStackTest

Change-Id: I8c70503cf1d9f1d06f30a1936d2d88857d0cff53
This commit is contained in:
Chiachang Wang
2019-04-11 21:24:28 +08:00
parent 7757b14c3b
commit e512b26913
7 changed files with 19 additions and 18 deletions

View File

@@ -208,7 +208,7 @@ message Atom {
119 [(log_from_module) = "docsui"];
DocsUISearchTypeReported docs_ui_search_type_reported =
120 [(log_from_module) = "docsui"];
DataStallEvent data_stall_event = 121;
DataStallEvent data_stall_event = 121 [(log_from_module) = "network_stack"];
RescuePartyResetReported rescue_party_reset_reported = 122;
SignedConfigReported signed_config_reported = 123;
GnssNiEventReported gnss_ni_event_reported = 124;
@@ -269,7 +269,7 @@ message Atom {
StyleUIChanged style_ui_changed = 179;
PrivacyIndicatorsInteracted privacy_indicators_interacted = 180;
AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181;
NetworkStackReported network_stack_reported = 182;
NetworkStackReported network_stack_reported = 182 [(log_from_module) = "network_stack"];
AppMovedStorageReported app_moved_storage_reported = 183;
BiometricEnrolled biometric_enrolled = 184;
SystemServerWatchdogOccurred system_server_watchdog_occurred = 185;

View File

@@ -198,11 +198,6 @@ public final class StatsLog extends StatsLogInternal {
write(id, (long) params[0], (int) params[1], (String) params[2], (String) params[3],
(boolean) params[4], (int) params[5]);
break;
case DATA_STALL_EVENT:
// Refer to the defintion in frameworks/base/cmds/statsd/src/atoms.proto.
write(id, (int) params[0], (int) params[1], (int) params[2], (byte[]) params[3],
(byte[]) params[4], (byte[]) params[5]);
break;
}
}

View File

@@ -37,6 +37,7 @@ android_library {
"src/**/*.java",
":framework-networkstack-shared-srcs",
":services-networkstack-shared-srcs",
":statslog-networkstack-java-gen",
],
static_libs: [
"androidx.annotation_annotation",
@@ -104,3 +105,11 @@ android_app {
certificate: "networkstack",
manifest: "AndroidManifest.xml",
}
genrule {
name: "statslog-networkstack-java-gen",
tools: ["stats-log-api-gen"],
cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
" --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog",
out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package android.net.metrics;
package com.android.networkstack.metrics;
import android.annotation.NonNull;
import android.annotation.Nullable;

View File

@@ -14,13 +14,12 @@
* limitations under the License.
*/
package android.net.metrics;
package com.android.networkstack.metrics;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.util.Log;
import android.util.StatsLog;
import com.android.internal.util.HexDump;
import com.android.server.connectivity.nano.DataStallEventProto;
@@ -37,13 +36,11 @@ import com.android.server.connectivity.nano.DataStallEventProto;
*/
public class DataStallStatsUtils {
private static final String TAG = DataStallStatsUtils.class.getSimpleName();
private static final int DATA_STALL_EVENT_ID = 121;
private static final boolean DBG = false;
private static int probeResultToEnum(@Nullable final CaptivePortalProbeResult result) {
if (result == null) return DataStallEventProto.INVALID;
// TODO: Add partial connectivity support.
if (result.isSuccessful()) {
return DataStallEventProto.VALID;
} else if (result.isPortal()) {
@@ -65,8 +62,7 @@ public class DataStallStatsUtils {
Log.d(TAG, "write: " + stats + " with result: " + validationResult
+ ", dns: " + HexDump.toHexString(stats.mDns));
}
// TODO(b/124613085): Update API once the public StatsLog API is ready.
StatsLog.write(DATA_STALL_EVENT_ID,
NetworkStackStatsLog.write(NetworkStackStatsLog.DATA_STALL_EVENT,
stats.mEvaluationType,
validationResult,
stats.mNetworkType,

View File

@@ -65,8 +65,6 @@ import android.net.TrafficStats;
import android.net.Uri;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.captiveportal.CaptivePortalProbeSpec;
import android.net.metrics.DataStallDetectionStats;
import android.net.metrics.DataStallStatsUtils;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
import android.net.metrics.ValidationProbeEvent;
@@ -101,6 +99,8 @@ import com.android.internal.util.RingBufferIndices;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.networkstack.R;
import com.android.networkstack.metrics.DataStallDetectionStats;
import com.android.networkstack.metrics.DataStallStatsUtils;
import java.io.IOException;
import java.net.HttpURLConnection;

View File

@@ -59,8 +59,6 @@ import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.metrics.DataStallDetectionStats;
import android.net.metrics.DataStallStatsUtils;
import android.net.metrics.IpConnectivityLog;
import android.net.util.SharedLog;
import android.net.wifi.WifiInfo;
@@ -78,6 +76,9 @@ import android.util.ArrayMap;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.networkstack.metrics.DataStallDetectionStats;
import com.android.networkstack.metrics.DataStallStatsUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;