summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-06-14 22:40:40 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-06-14 22:40:41 +0000
commit1af2a6345963b5dbf6404b78e212a1b67e28c2dc (patch)
tree6a5c20ac533095ed623cff28f697cad735f3ac1c /service
parentae733ef1ea87e66b1c02184434372103a19a5920 (diff)
parent279abf6c5af5d42f6deb8e8738c7f030521976ef (diff)
Merge "[WifiScoreReport] Add dumpsys for scoring data" into oc-dr1-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiScoreReport.java70
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java9
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java5
3 files changed, 81 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java
index 74ddf99ec..5aadc1e9b 100644
--- a/service/java/com/android/server/wifi/WifiScoreReport.java
+++ b/service/java/com/android/server/wifi/WifiScoreReport.java
@@ -24,6 +24,13 @@ import android.util.Log;
import com.android.internal.R;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.Locale;
+
/**
* Class used to calculate scores for connected wifi networks and report it to the associated
* network agent.
@@ -47,6 +54,7 @@ public class WifiScoreReport {
private static final int LINK_STUCK_PENALTY = 2;
private static final int BAD_LINKSPEED_PENALTY = 4;
private static final int GOOD_LINKSPEED_BONUS = 4;
+ private static final int DUMPSYS_ENTRY_COUNT_LIMIT = 14400; // 12 hours on 3 second poll
// Device configs. The values are examples.
private final int mThresholdMinimumRssi5; // -82
@@ -71,7 +79,10 @@ public class WifiScoreReport {
private boolean mMultiBandScanResults;
private boolean mIsHomeNetwork;
- WifiScoreReport(Context context, WifiConfigManager wifiConfigManager) {
+ private final Clock mClock;
+ private int mSessionNumber = 0;
+
+ WifiScoreReport(Context context, WifiConfigManager wifiConfigManager, Clock clock) {
// Fetch all the device configs.
mThresholdMinimumRssi5 = context.getResources().getInteger(
R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz);
@@ -95,6 +106,7 @@ public class WifiScoreReport {
R.integer.config_wifi_framework_wifi_score_good_link_speed_5);
mWifiConfigManager = wifiConfigManager;
+ mClock = clock;
}
/**
@@ -112,6 +124,8 @@ public class WifiScoreReport {
public void reset() {
mReport = "";
mReportValid = false;
+ mSessionNumber++;
+ if (mVerboseLoggingEnabled) Log.d(TAG, "reset");
}
/**
@@ -148,6 +162,7 @@ public class WifiScoreReport {
int aggressiveHandover, WifiMetrics wifiMetrics) {
int score;
+ logLinkMetrics(wifiInfo);
if (aggressiveHandover == 0) {
// Use the old method
updateScoringState(wifiInfo, aggressiveHandover);
@@ -175,7 +190,7 @@ public class WifiScoreReport {
}
}
- mReport = String.format(" score=%d", score);
+ mReport = String.format(Locale.US, " score=%d", score);
mReportValid = true;
wifiMetrics.incrementWifiScoreCount(score);
}
@@ -338,4 +353,55 @@ public class WifiScoreReport {
return (int) Math.round(score);
}
+ /**
+ * Data for dumpsys
+ *
+ * These are stored as csv formatted lines
+ */
+ private LinkedList<String> mLinkMetricsHistory = new LinkedList<String>();
+
+ /**
+ * Data logging for dumpsys
+ */
+ private void logLinkMetrics(WifiInfo wifiInfo) {
+ long now = mClock.getWallClockMillis();
+ double rssi = wifiInfo.getRssi();
+ int freq = wifiInfo.getFrequency();
+ int linkSpeed = wifiInfo.getLinkSpeed();
+ double txSuccessRate = wifiInfo.txSuccessRate;
+ double txRetriesRate = wifiInfo.txRetriesRate;
+ double txBadRate = wifiInfo.txBadRate;
+ double rxSuccessRate = wifiInfo.rxSuccessRate;
+ try {
+ String timestamp = new SimpleDateFormat("MM-dd HH:mm:ss.SSS").format(new Date(now));
+ String s = String.format(Locale.US, // Use US to avoid comma/decimal confusion
+ "%s,%d,%.1f,%d,%d,%.2f,%.2f,%.2f,%.2f",
+ timestamp, mSessionNumber, rssi, freq, linkSpeed,
+ txSuccessRate, txRetriesRate, txBadRate, rxSuccessRate);
+ mLinkMetricsHistory.add(s);
+ } catch (Exception e) {
+ Log.e(TAG, "format problem", e);
+ }
+ while (mLinkMetricsHistory.size() > DUMPSYS_ENTRY_COUNT_LIMIT) {
+ mLinkMetricsHistory.removeFirst();
+ }
+ }
+
+ /**
+ * Tag to be used in dumpsys request
+ */
+ public static final String DUMP_ARG = "WifiScoreReport";
+
+ /**
+ * Dump logged signal strength and traffic measurements.
+ * @param fd unused
+ * @param pw PrintWriter for writing dump to
+ * @param args unused
+ */
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ pw.println("time,session,rssi,freq,linkspeed,tx_good,tx_retry,tx_bad,rx");
+ for (String line : mLinkMetricsHistory) {
+ pw.println(line);
+ }
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 3306fb608..02773ee2e 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2239,6 +2239,9 @@ public class WifiServiceImpl extends IWifiManager.Stub {
String[] ipManagerArgs = new String[args.length - 1];
System.arraycopy(args, 1, ipManagerArgs, 0, ipManagerArgs.length);
mWifiStateMachine.dumpIpManager(fd, pw, ipManagerArgs);
+ } else if (args != null && args.length > 0 && WifiScoreReport.DUMP_ARG.equals(args[0])) {
+ WifiScoreReport wifiScoreReport = mWifiStateMachine.getWifiScoreReport();
+ if (wifiScoreReport != null) wifiScoreReport.dump(fd, pw, args);
} else {
pw.println("Wi-Fi is " + mWifiStateMachine.syncGetWifiStateByName());
pw.println("Stay-awake conditions: " +
@@ -2263,6 +2266,12 @@ public class WifiServiceImpl extends IWifiManager.Stub {
pw.println();
mWifiBackupRestore.dump(fd, pw, args);
pw.println();
+ WifiScoreReport wifiScoreReport = mWifiStateMachine.getWifiScoreReport();
+ if (wifiScoreReport != null) {
+ pw.println("WifiScoreReport:");
+ wifiScoreReport.dump(fd, pw, args);
+ }
+ pw.println();
}
}
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 06714c72f..72f596507 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -222,6 +222,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
private final WifiCountryCode mCountryCode;
// Object holding most recent wifi score report and bad Linkspeed count
private final WifiScoreReport mWifiScoreReport;
+ public WifiScoreReport getWifiScoreReport() {
+ return mWifiScoreReport;
+ }
private final PasspointManager mPasspointManager;
/* Scan results handling */
@@ -945,7 +948,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mCountryCode = countryCode;
- mWifiScoreReport = new WifiScoreReport(mContext, mWifiConfigManager);
+ mWifiScoreReport = new WifiScoreReport(mContext, mWifiConfigManager, mClock);
mUserWantsSuspendOpt.set(mFacade.getIntegerSetting(mContext,
Settings.Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1);