diff options
author | Etan Cohen <etancohen@google.com> | 2018-03-13 07:27:40 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2018-03-14 11:44:11 -0700 |
commit | 05dbaa4579483e9f53f4b6c6e02c02d620f1890f (patch) | |
tree | 0dd1cb3b09a8f1fcbdb4d0d2a8a3112686c5895d /service | |
parent | b7dc1893e5c56a443e162a6147518046583f73bf (diff) |
[AWARE] Metrics for Discovery + Ranging
Add metrics for Wi-Fi Aware discovery with ranging constraints.
Bug: 63906015
Test: unit tests for aware
Test: integration tests ThroughputTest
Change-Id: I06330edb906a72de33b8777587deed4f27fc6f41
Diffstat (limited to 'service')
3 files changed, 226 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java index 062b5d953..18b917799 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java @@ -48,6 +48,7 @@ public class WifiAwareDiscoverySessionState { private byte mPubSubId; private IWifiAwareDiscoverySessionCallback mCallback; private boolean mIsPublishSession; + private boolean mIsRangingEnabled; private final long mCreationTime; static class PeerInfo { @@ -71,12 +72,13 @@ public class WifiAwareDiscoverySessionState { public WifiAwareDiscoverySessionState(WifiAwareNativeApi wifiAwareNativeApi, int sessionId, byte pubSubId, IWifiAwareDiscoverySessionCallback callback, boolean isPublishSession, - long creationTime) { + boolean isRangingEnabled, long creationTime) { mWifiAwareNativeApi = wifiAwareNativeApi; mSessionId = sessionId; mPubSubId = pubSubId; mCallback = callback; mIsPublishSession = isPublishSession; + mIsRangingEnabled = isRangingEnabled; mCreationTime = creationTime; } @@ -92,6 +94,10 @@ public class WifiAwareDiscoverySessionState { return mIsPublishSession; } + public boolean isRangingEnabled() { + return mIsRangingEnabled; + } + public long getCreationTime() { return mCreationTime; } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareMetrics.java b/service/java/com/android/server/wifi/aware/WifiAwareMetrics.java index 4f5f46b0c..e85ade115 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareMetrics.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareMetrics.java @@ -55,6 +55,14 @@ public class WifiAwareMetrics { // 10^7 -> 10^8: 9 @ 10^7 --> 10^8 ms -> 10^5s -> 28 hours private static final HistParms DURATION_LOG_HISTOGRAM = new HistParms(0, 1, 10, 9, 8); + // Histogram for ranging limits in discovery. Indicates the following 5 buckets (in meters): + // < 10 + // [10, 30) + // [30, 60) + // [60, 100) + // >= 100 + private static final int[] RANGING_LIMIT_METERS = { 10, 30, 60, 100 }; + private final Object mLock = new Object(); private final Clock mClock; @@ -92,6 +100,17 @@ public class WifiAwareMetrics { private SparseIntArray mHistogramSubscribeDuration = new SparseIntArray(); private Set<Integer> mAppsWithDiscoverySessionResourceFailure = new HashSet<>(); + // discovery with ranging data + private int mMaxPublishWithRangingInApp = 0; + private int mMaxSubscribeWithRangingInApp = 0; + private int mMaxPublishWithRangingInSystem = 0; + private int mMaxSubscribeWithRangingInSystem = 0; + private SparseIntArray mHistogramSubscribeGeofenceMin = new SparseIntArray(); + private SparseIntArray mHistogramSubscribeGeofenceMax = new SparseIntArray(); + private int mNumSubscribesWithRanging = 0; + private int mNumMatchesWithRanging = 0; + private int mNumMatchesWithoutRangingForRangingEnabledSubscribes = 0; + // data-path (NDI/NDP) data private int mMaxNdiInApp = 0; private int mMaxNdpInApp = 0; @@ -231,14 +250,34 @@ public class WifiAwareMetrics { /** * Push information about the new discovery session. */ - public void recordDiscoverySession(int uid, boolean isPublish, - SparseArray<WifiAwareClientState> clients) { + public void recordDiscoverySession(int uid, SparseArray<WifiAwareClientState> clients) { + recordDiscoverySessionInternal(uid, clients, false, -1, -1); + } + + /** + * Push information about the new discovery session with ranging enabled + */ + public void recordDiscoverySessionWithRanging(int uid, boolean isSubscriberWithRanging, + int minRange, int maxRange, SparseArray<WifiAwareClientState> clients) { + recordDiscoverySessionInternal(uid, clients, isSubscriberWithRanging, minRange, maxRange); + } + + /** + * Internal combiner of discovery session information. + */ + private void recordDiscoverySessionInternal(int uid, SparseArray<WifiAwareClientState> clients, + boolean isRangingEnabledSubscriber, int minRange, int maxRange) { // count the number of sessions per uid and overall int numPublishesInSystem = 0; int numSubscribesInSystem = 0; int numPublishesOnUid = 0; int numSubscribesOnUid = 0; + int numPublishesWithRangingInSystem = 0; + int numSubscribesWithRangingInSystem = 0; + int numPublishesWithRangingOnUid = 0; + int numSubscribesWithRangingOnUid = 0; + for (int i = 0; i < clients.size(); ++i) { WifiAwareClientState client = clients.valueAt(i); boolean sameUid = client.getUid() == uid; @@ -246,16 +285,29 @@ public class WifiAwareMetrics { SparseArray<WifiAwareDiscoverySessionState> sessions = client.getSessions(); for (int j = 0; j < sessions.size(); ++j) { WifiAwareDiscoverySessionState session = sessions.valueAt(j); + boolean isRangingEnabledForThisSession = session.isRangingEnabled(); if (session.isPublishSession()) { numPublishesInSystem += 1; + if (isRangingEnabledForThisSession) { + numPublishesWithRangingInSystem += 1; + } if (sameUid) { numPublishesOnUid += 1; + if (isRangingEnabledForThisSession) { + numPublishesWithRangingOnUid += 1; + } } } else { numSubscribesInSystem += 1; + if (isRangingEnabledForThisSession) { + numSubscribesWithRangingInSystem += 1; + } if (sameUid) { numSubscribesOnUid += 1; + if (isRangingEnabledForThisSession) { + numSubscribesWithRangingOnUid += 1; + } } } } @@ -270,6 +322,27 @@ public class WifiAwareMetrics { mMaxSubscribeInSystem = Math.max(mMaxSubscribeInSystem, numSubscribesInSystem); mMaxDiscoveryInSystem = Math.max(mMaxDiscoveryInSystem, numPublishesInSystem + numSubscribesInSystem); + + mMaxPublishWithRangingInApp = Math.max(mMaxPublishWithRangingInApp, + numPublishesWithRangingOnUid); + mMaxSubscribeWithRangingInApp = Math.max(mMaxSubscribeWithRangingInApp, + numSubscribesWithRangingOnUid); + mMaxPublishWithRangingInSystem = Math.max(mMaxPublishWithRangingInSystem, + numPublishesWithRangingInSystem); + mMaxSubscribeWithRangingInSystem = Math.max(mMaxSubscribeWithRangingInSystem, + numSubscribesWithRangingInSystem); + if (isRangingEnabledSubscriber) { + mNumSubscribesWithRanging += 1; + } + + if (minRange != -1) { + addLinearValueToHistogram(minRange, mHistogramSubscribeGeofenceMin, + RANGING_LIMIT_METERS); + } + if (maxRange != -1) { + addLinearValueToHistogram(maxRange, mHistogramSubscribeGeofenceMax, + RANGING_LIMIT_METERS); + } } } @@ -303,6 +376,19 @@ public class WifiAwareMetrics { } /** + * Push information about Match indication (aka service discovered) for subscribe sessions + * which enabled ranging. Collect information about whether or not service discovery was + * triggered with ranging information or without (i.e. ranging disabled for some reason). + */ + public void recordMatchIndicationForRangeEnabledSubscribe(boolean rangeProvided) { + if (rangeProvided) { + mNumMatchesWithRanging++; + } else { + mNumMatchesWithoutRangingForRangingEnabledSubscribes++; + } + } + + /** * Record NDP (and by extension NDI) usage - on successful creation of an NDP. */ public void recordNdpCreation(int uid, @@ -456,6 +542,19 @@ public class WifiAwareMetrics { log.histogramSubscribeSessionDurationMs = histogramToProtoArray( mHistogramSubscribeDuration, DURATION_LOG_HISTOGRAM); + log.maxConcurrentPublishWithRangingInApp = mMaxPublishWithRangingInApp; + log.maxConcurrentSubscribeWithRangingInApp = mMaxSubscribeWithRangingInApp; + log.maxConcurrentPublishWithRangingInSystem = mMaxPublishWithRangingInSystem; + log.maxConcurrentSubscribeWithRangingInSystem = mMaxSubscribeWithRangingInSystem; + log.histogramSubscribeGeofenceMin = histogramToProtoArray( + mHistogramSubscribeGeofenceMin, RANGING_LIMIT_METERS); + log.histogramSubscribeGeofenceMax = histogramToProtoArray( + mHistogramSubscribeGeofenceMax, RANGING_LIMIT_METERS); + log.numSubscribesWithRanging = mNumSubscribesWithRanging; + log.numMatchesWithRanging = mNumMatchesWithRanging; + log.numMatchesWithoutRangingForRangingEnabledSubscribes = + mNumMatchesWithoutRangingForRangingEnabledSubscribes; + log.maxConcurrentNdiInApp = mMaxNdiInApp; log.maxConcurrentNdiInSystem = mMaxNdiInSystem; log.maxConcurrentNdpInApp = mMaxNdpInApp; @@ -516,6 +615,16 @@ public class WifiAwareMetrics { mHistogramSubscribeDuration.clear(); mAppsWithDiscoverySessionResourceFailure.clear(); + mMaxPublishWithRangingInApp = 0; + mMaxSubscribeWithRangingInApp = 0; + mMaxPublishWithRangingInSystem = 0; + mMaxSubscribeWithRangingInSystem = 0; + mHistogramSubscribeGeofenceMin.clear(); + mHistogramSubscribeGeofenceMax.clear(); + mNumSubscribesWithRanging = 0; + mNumMatchesWithRanging = 0; + mNumMatchesWithoutRangingForRangingEnabledSubscribes = 0; + mMaxNdiInApp = 0; mMaxNdpInApp = 0; mMaxSecureNdpInApp = 0; @@ -613,7 +722,27 @@ public class WifiAwareMetrics { pw.println("mAppsWithDiscoverySessionResourceFailure:"); for (Integer uid: mAppsWithDiscoverySessionResourceFailure) { pw.println(" " + uid); + + } + + pw.println("mMaxPublishWithRangingInApp:" + mMaxPublishWithRangingInApp); + pw.println("mMaxSubscribeWithRangingInApp:" + mMaxSubscribeWithRangingInApp); + pw.println("mMaxPublishWithRangingInSystem:" + mMaxPublishWithRangingInSystem); + pw.println("mMaxSubscribeWithRangingInSystem:" + mMaxSubscribeWithRangingInSystem); + pw.println("mHistogramSubscribeGeofenceMin:"); + for (int i = 0; i < mHistogramSubscribeGeofenceMin.size(); ++i) { + pw.println(" " + mHistogramSubscribeGeofenceMin.keyAt(i) + ": " + + mHistogramSubscribeGeofenceMin.valueAt(i)); } + pw.println("mHistogramSubscribeGeofenceMax:"); + for (int i = 0; i < mHistogramSubscribeGeofenceMax.size(); ++i) { + pw.println(" " + mHistogramSubscribeGeofenceMax.keyAt(i) + ": " + + mHistogramSubscribeGeofenceMax.valueAt(i)); + } + pw.println("mNumSubscribesWithRanging:" + mNumSubscribesWithRanging); + pw.println("mNumMatchesWithRanging:" + mNumMatchesWithRanging); + pw.println("mNumMatchesWithoutRangingForRangingEnabledSubscribes:" + + mNumMatchesWithoutRangingForRangingEnabledSubscribes); pw.println("mMaxNdiInApp:" + mMaxNdiInApp); pw.println("mMaxNdpInApp:" + mMaxNdpInApp); @@ -762,6 +891,63 @@ public class WifiAwareMetrics { } /** + * Adds the input value to the histogram based on the lineaer histogram parameters. + * + * The 'int[] hp' contains a list of bucket limits. The number of buckets is hp.length() + 1 + * where buckets are: + * - < hp[0] + * - [hp[0], hp[1]) + * ... + * - >= hp[hp.length() - 1] + */ + @VisibleForTesting + public static int addLinearValueToHistogram(int x, SparseIntArray histogram, int[] hp) { + int bucket = 0; + for (int limit : hp) { + if (x >= limit) { + bucket++; + continue; + } + break; + } + + // note that get() returns 0 if index not there already + int newValue = histogram.get(bucket) + 1; + histogram.put(bucket, newValue); + + return newValue; + } + + /** + * Converts the histogram (with the specified linear histogram parameters) to an array of + * proto histogram buckets. + */ + @VisibleForTesting + public static WifiMetricsProto.WifiAwareLog.HistogramBucket[] histogramToProtoArray( + SparseIntArray histogram, int[] linearHistParams) { + WifiMetricsProto.WifiAwareLog.HistogramBucket[] protoArray = + new WifiMetricsProto.WifiAwareLog.HistogramBucket[histogram.size()]; + for (int i = 0; i < histogram.size(); ++i) { + int bucket = histogram.keyAt(i); + + protoArray[i] = new WifiMetricsProto.WifiAwareLog.HistogramBucket(); + if (bucket == 0) { + protoArray[i].start = Integer.MIN_VALUE; + protoArray[i].end = linearHistParams[0]; + } else if (bucket != linearHistParams.length) { + protoArray[i].start = linearHistParams[bucket - 1]; + protoArray[i].end = linearHistParams[bucket]; + } else { + protoArray[i].start = linearHistParams[linearHistParams.length - 1]; + protoArray[i].end = Integer.MAX_VALUE; + } + protoArray[i].count = histogram.valueAt(i); + } + + return protoArray; + } + + /** * Adds the NanStatusType to the histogram (translating to the proto enumeration of the status). */ public static void addNanHalStatusToHistogram(int halStatus, SparseIntArray histogram) { diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index 8eb31cc6b..2ec3f7578 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -2656,14 +2656,39 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe return; } + boolean isRangingEnabled = false; + int minRange = -1; + int maxRange = -1; + if (completedCommand.arg1 == COMMAND_TYPE_PUBLISH) { + PublishConfig publishConfig = completedCommand.getData().getParcelable( + MESSAGE_BUNDLE_KEY_CONFIG); + isRangingEnabled = publishConfig.mEnableRanging; + } else { + SubscribeConfig subscribeConfig = completedCommand.getData().getParcelable( + MESSAGE_BUNDLE_KEY_CONFIG); + isRangingEnabled = + subscribeConfig.mMinDistanceMmSet || subscribeConfig.mMaxDistanceMmSet; + if (subscribeConfig.mMinDistanceMmSet) { + minRange = subscribeConfig.mMinDistanceMm; + } + if (subscribeConfig.mMaxDistanceMmSet) { + maxRange = subscribeConfig.mMaxDistanceMm; + } + } + WifiAwareDiscoverySessionState session = new WifiAwareDiscoverySessionState( - mWifiAwareNativeApi, sessionId, pubSubId, callback, isPublish, + mWifiAwareNativeApi, sessionId, pubSubId, callback, isPublish, isRangingEnabled, SystemClock.elapsedRealtime()); session.mDbg = mDbg; client.addSession(session); - mAwareMetrics.recordDiscoverySession(client.getUid(), - completedCommand.arg1 == COMMAND_TYPE_PUBLISH, mClients); + if (isRangingEnabled) { + mAwareMetrics.recordDiscoverySessionWithRanging(client.getUid(), + completedCommand.arg1 != COMMAND_TYPE_PUBLISH, minRange, maxRange, + mClients); + } else { + mAwareMetrics.recordDiscoverySession(client.getUid(), mClients); + } mAwareMetrics.recordDiscoveryStatus(client.getUid(), NanStatusType.SUCCESS, completedCommand.arg1 == COMMAND_TYPE_PUBLISH); @@ -2957,6 +2982,9 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe return; } + if (data.second.isRangingEnabled()) { + mAwareMetrics.recordMatchIndicationForRangeEnabledSubscribe(rangingIndication != 0); + } data.second.onMatch(requestorInstanceId, peerMac, serviceSpecificInfo, matchFilter, rangingIndication, rangeMm); } |