summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java79
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java12
2 files changed, 64 insertions, 27 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index 39266a638..a3bd1697c 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -50,6 +50,10 @@ import com.android.server.wifi.rtt.RttMetrics;
import com.android.server.wifi.util.InformationElementUtil;
import com.android.server.wifi.util.ScanResultUtil;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -137,8 +141,8 @@ public class WifiMetrics {
* combination. Indexed by WifiLog.WifiState * (1 + screenOn)
*/
private final SparseIntArray mWifiSystemStateEntries = new SparseIntArray();
- /** Mapping of RSSI values to counts. */
- private final SparseIntArray mRssiPollCounts = new SparseIntArray();
+ /** Mapping of channel frequency to its RSSI distribution histogram **/
+ private final Map<Integer, SparseIntArray> mRssiPollCountsMap = new HashMap<>();
/** Mapping of RSSI scan-poll delta values to counts. */
private final SparseIntArray mRssiDeltaCounts = new SparseIntArray();
/** RSSI of the scan result for the last connection event*/
@@ -1095,20 +1099,26 @@ public class WifiMetrics {
mLastPollRssi = wifiInfo.getRssi();
mLastPollLinkSpeed = wifiInfo.getLinkSpeed();
mLastPollFreq = wifiInfo.getFrequency();
- incrementRssiPollRssiCount(mLastPollRssi);
+ incrementRssiPollRssiCount(mLastPollFreq, mLastPollRssi);
}
/**
- * Increment occurence count of RSSI level from RSSI poll.
- * Ignores rssi values outside the bounds of [MIN_RSSI_POLL, MAX_RSSI_POLL]
+ * Increment occurence count of RSSI level from RSSI poll for the given frequency.
+ * @param frequency (MHz)
+ * @param rssi
*/
- public void incrementRssiPollRssiCount(int rssi) {
+ @VisibleForTesting
+ public void incrementRssiPollRssiCount(int frequency, int rssi) {
if (!(rssi >= MIN_RSSI_POLL && rssi <= MAX_RSSI_POLL)) {
return;
}
synchronized (mLock) {
- int count = mRssiPollCounts.get(rssi);
- mRssiPollCounts.put(rssi, count + 1);
+ if (!mRssiPollCountsMap.containsKey(frequency)) {
+ mRssiPollCountsMap.put(frequency, new SparseIntArray());
+ }
+ SparseIntArray sparseIntArray = mRssiPollCountsMap.get(frequency);
+ int count = sparseIntArray.get(rssi);
+ sparseIntArray.put(rssi, count + 1);
maybeIncrementRssiDeltaCount(rssi - mScanResultRssi);
}
}
@@ -1907,16 +1917,32 @@ public class WifiMetrics {
+ mWifiLogProto.numLastResortWatchdogSuccesses);
pw.println("mWifiLogProto.recordDurationSec="
+ ((mClock.getElapsedSinceBootMillis() / 1000) - mRecordStartTimeSec));
- pw.println("mWifiLogProto.rssiPollRssiCount: Printing counts for [" + MIN_RSSI_POLL
- + ", " + MAX_RSSI_POLL + "]");
- StringBuilder sb = new StringBuilder();
- for (int i = MIN_RSSI_POLL; i <= MAX_RSSI_POLL; i++) {
- sb.append(mRssiPollCounts.get(i) + " ");
+
+ try {
+ JSONObject rssiMap = new JSONObject();
+ for (Map.Entry<Integer, SparseIntArray> entry : mRssiPollCountsMap.entrySet()) {
+ int frequency = entry.getKey();
+ final SparseIntArray histogram = entry.getValue();
+ JSONArray histogramElements = new JSONArray();
+ for (int i = MIN_RSSI_POLL; i <= MAX_RSSI_POLL; i++) {
+ int count = histogram.get(i);
+ if (count == 0) {
+ continue;
+ }
+ JSONObject histogramElement = new JSONObject();
+ histogramElement.put(Integer.toString(i), count);
+ histogramElements.put(histogramElement);
+ }
+ rssiMap.put(Integer.toString(frequency), histogramElements);
+ }
+ pw.println("mWifiLogProto.rssiPollCount: " + rssiMap.toString());
+ } catch (JSONException e) {
+ pw.println("JSONException occurred: " + e.getMessage());
}
- pw.println(" " + sb.toString());
+
pw.println("mWifiLogProto.rssiPollDeltaCount: Printing counts for ["
+ MIN_RSSI_DELTA + ", " + MAX_RSSI_DELTA + "]");
- sb.setLength(0);
+ StringBuilder sb = new StringBuilder();
for (int i = MIN_RSSI_DELTA; i <= MAX_RSSI_DELTA; i++) {
sb.append(mRssiDeltaCounts.get(i) + " ");
}
@@ -2238,14 +2264,19 @@ public class WifiMetrics {
- mRecordStartTimeSec);
/**
- * Convert the SparseIntArray of RSSI poll rssi's and counts to the proto's repeated
- * IntKeyVal array.
+ * Convert the SparseIntArrays of RSSI poll rssi, counts, and frequency to the
+ * proto's repeated ntKeyVal array.
*/
- for (int i = 0; i < mRssiPollCounts.size(); i++) {
- WifiMetricsProto.RssiPollCount keyVal = new WifiMetricsProto.RssiPollCount();
- keyVal.rssi = mRssiPollCounts.keyAt(i);
- keyVal.count = mRssiPollCounts.valueAt(i);
- rssis.add(keyVal);
+ for (Map.Entry<Integer, SparseIntArray> entry : mRssiPollCountsMap.entrySet()) {
+ int frequency = entry.getKey();
+ SparseIntArray histogram = entry.getValue();
+ for (int i = 0; i < histogram.size(); i++) {
+ WifiMetricsProto.RssiPollCount keyVal = new WifiMetricsProto.RssiPollCount();
+ keyVal.rssi = histogram.keyAt(i);
+ keyVal.count = histogram.valueAt(i);
+ keyVal.frequency = frequency;
+ rssis.add(keyVal);
+ }
}
mWifiLogProto.rssiPollRssiCount = rssis.toArray(mWifiLogProto.rssiPollRssiCount);
@@ -2261,6 +2292,8 @@ public class WifiMetrics {
}
mWifiLogProto.rssiPollDeltaCount = rssiDeltas.toArray(mWifiLogProto.rssiPollDeltaCount);
+
+
/**
* Convert the SparseIntArray of alert reasons and counts to the proto's repeated
* IntKeyVal array.
@@ -2460,7 +2493,7 @@ public class WifiMetrics {
mScanReturnEntries.clear();
mWifiSystemStateEntries.clear();
mRecordStartTimeSec = mClock.getElapsedSinceBootMillis() / 1000;
- mRssiPollCounts.clear();
+ mRssiPollCountsMap.clear();
mRssiDeltaCounts.clear();
mWifiAlertReasonCounts.clear();
mWifiScoreCounts.clear();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 9682750d2..2a60a1096 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -232,6 +232,7 @@ public class WifiMetricsTest {
private static final int NUM_LAST_RESORT_WATCHDOG_TRIGGERS_WITH_BAD_OTHER = 10;
private static final int NUM_LAST_RESORT_WATCHDOG_SUCCESSES = 5;
private static final int WATCHDOG_TOTAL_CONNECTION_FAILURE_COUNT_AFTER_TRIGGER = 6;
+ private static final int RSSI_POLL_FREQUENCY = 5150;
private static final int NUM_RSSI_LEVELS_TO_INCREMENT = 20;
private static final int FIRST_RSSI_LEVEL = -80;
private static final int NUM_OPEN_NETWORK_SCAN_RESULTS = 1;
@@ -490,15 +491,16 @@ public class WifiMetricsTest {
}
for (int i = 0; i < NUM_RSSI_LEVELS_TO_INCREMENT; i++) {
for (int j = 0; j <= i; j++) {
- mWifiMetrics.incrementRssiPollRssiCount(MIN_RSSI_LEVEL + i);
+ mWifiMetrics.incrementRssiPollRssiCount(RSSI_POLL_FREQUENCY, MIN_RSSI_LEVEL + i);
}
}
for (int i = 1; i < NUM_OUT_OF_BOUND_ENTRIES; i++) {
- mWifiMetrics.incrementRssiPollRssiCount(MIN_RSSI_LEVEL - i);
+ mWifiMetrics.incrementRssiPollRssiCount(RSSI_POLL_FREQUENCY, MIN_RSSI_LEVEL - i);
}
for (int i = 1; i < NUM_OUT_OF_BOUND_ENTRIES; i++) {
- mWifiMetrics.incrementRssiPollRssiCount(MAX_RSSI_LEVEL + i);
+ mWifiMetrics.incrementRssiPollRssiCount(RSSI_POLL_FREQUENCY, MAX_RSSI_LEVEL + i);
}
+
// Test alert-reason clamping.
mWifiMetrics.incrementAlertReasonCount(WifiLoggerHal.WIFI_ALERT_REASON_MIN - 1);
mWifiMetrics.incrementAlertReasonCount(WifiLoggerHal.WIFI_ALERT_REASON_MAX + 1);
@@ -813,6 +815,8 @@ public class WifiMetricsTest {
assertEquals(TEST_RECORD_DURATION_SEC,
mDecodedProto.recordDurationSec);
for (int i = 0; i < NUM_RSSI_LEVELS_TO_INCREMENT; i++) {
+ assertEquals(RSSI_POLL_FREQUENCY,
+ mDecodedProto.rssiPollRssiCount[i].frequency);
assertEquals(MIN_RSSI_LEVEL + i, mDecodedProto.rssiPollRssiCount[i].rssi);
assertEquals(i + 1, mDecodedProto.rssiPollRssiCount[i].count);
}
@@ -1817,7 +1821,7 @@ public class WifiMetricsTest {
if (!dontDeserializeBeforePoll) {
dumpProtoAndDeserialize();
}
- mWifiMetrics.incrementRssiPollRssiCount(scanRssi + rssiDelta);
+ mWifiMetrics.incrementRssiPollRssiCount(RSSI_POLL_FREQUENCY, scanRssi + rssiDelta);
}
/**