Expose measurement results to interested callers.
am: 6ba9b90805
* commit '6ba9b90805d3e9a759a9b9a364b9ac406d9d573b':
Expose measurement results to interested callers.
This commit is contained in:
@@ -49,7 +49,9 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -107,27 +109,33 @@ public class NetworkDiagnostics {
|
|||||||
// so callers can wait for completion.
|
// so callers can wait for completion.
|
||||||
private final CountDownLatch mCountDownLatch;
|
private final CountDownLatch mCountDownLatch;
|
||||||
|
|
||||||
private class Measurement {
|
public class Measurement {
|
||||||
private static final String SUCCEEDED = "SUCCEEDED";
|
private static final String SUCCEEDED = "SUCCEEDED";
|
||||||
private static final String FAILED = "FAILED";
|
private static final String FAILED = "FAILED";
|
||||||
|
|
||||||
// TODO: Refactor to make these private for better encapsulation.
|
private boolean succeeded;
|
||||||
public String description = "";
|
|
||||||
public long startTime;
|
|
||||||
public long finishTime;
|
|
||||||
public String result = "";
|
|
||||||
public Thread thread;
|
|
||||||
|
|
||||||
public void recordSuccess(String msg) {
|
// Package private. TODO: investigate better encapsulation.
|
||||||
|
String description = "";
|
||||||
|
long startTime;
|
||||||
|
long finishTime;
|
||||||
|
String result = "";
|
||||||
|
Thread thread;
|
||||||
|
|
||||||
|
public boolean checkSucceeded() { return succeeded; }
|
||||||
|
|
||||||
|
void recordSuccess(String msg) {
|
||||||
maybeFixupTimes();
|
maybeFixupTimes();
|
||||||
|
succeeded = true;
|
||||||
result = SUCCEEDED + ": " + msg;
|
result = SUCCEEDED + ": " + msg;
|
||||||
if (mCountDownLatch != null) {
|
if (mCountDownLatch != null) {
|
||||||
mCountDownLatch.countDown();
|
mCountDownLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recordFailure(String msg) {
|
void recordFailure(String msg) {
|
||||||
maybeFixupTimes();
|
maybeFixupTimes();
|
||||||
|
succeeded = false;
|
||||||
result = FAILED + ": " + msg;
|
result = FAILED + ": " + msg;
|
||||||
if (mCountDownLatch != null) {
|
if (mCountDownLatch != null) {
|
||||||
mCountDownLatch.countDown();
|
mCountDownLatch.countDown();
|
||||||
@@ -265,6 +273,51 @@ public class NetworkDiagnostics {
|
|||||||
} catch (InterruptedException ignored) {}
|
} catch (InterruptedException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Measurement> getMeasurements() {
|
||||||
|
// TODO: Consider moving waitForMeasurements() in here to minimize the
|
||||||
|
// chance of caller errors.
|
||||||
|
|
||||||
|
ArrayList<Measurement> measurements = new ArrayList(totalMeasurementCount());
|
||||||
|
|
||||||
|
// Sort measurements IPv4 first.
|
||||||
|
for (Map.Entry<InetAddress, Measurement> entry : mIcmpChecks.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof Inet4Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<Pair<InetAddress, InetAddress>, Measurement> entry :
|
||||||
|
mExplicitSourceIcmpChecks.entrySet()) {
|
||||||
|
if (entry.getKey().first instanceof Inet4Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<InetAddress, Measurement> entry : mDnsUdpChecks.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof Inet4Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPv6 measurements second.
|
||||||
|
for (Map.Entry<InetAddress, Measurement> entry : mIcmpChecks.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof Inet6Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<Pair<InetAddress, InetAddress>, Measurement> entry :
|
||||||
|
mExplicitSourceIcmpChecks.entrySet()) {
|
||||||
|
if (entry.getKey().first instanceof Inet6Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<InetAddress, Measurement> entry : mDnsUdpChecks.entrySet()) {
|
||||||
|
if (entry.getKey() instanceof Inet6Address) {
|
||||||
|
measurements.add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return measurements;
|
||||||
|
}
|
||||||
|
|
||||||
public void dump(IndentingPrintWriter pw) {
|
public void dump(IndentingPrintWriter pw) {
|
||||||
pw.println(TAG + ":" + mDescription);
|
pw.println(TAG + ":" + mDescription);
|
||||||
final long unfinished = mCountDownLatch.getCount();
|
final long unfinished = mCountDownLatch.getCount();
|
||||||
@@ -276,30 +329,13 @@ public class NetworkDiagnostics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
for (Map.Entry<InetAddress, Measurement> entry : mIcmpChecks.entrySet()) {
|
|
||||||
if (entry.getKey() instanceof Inet4Address) {
|
String prefix;
|
||||||
pw.println(entry.getValue().toString());
|
for (Measurement m : getMeasurements()) {
|
||||||
}
|
prefix = m.checkSucceeded() ? "." : "F";
|
||||||
}
|
pw.println(prefix + " " + m.toString());
|
||||||
for (Map.Entry<InetAddress, Measurement> entry : mIcmpChecks.entrySet()) {
|
|
||||||
if (entry.getKey() instanceof Inet6Address) {
|
|
||||||
pw.println(entry.getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Map.Entry<Pair<InetAddress, InetAddress>, Measurement> entry :
|
|
||||||
mExplicitSourceIcmpChecks.entrySet()) {
|
|
||||||
pw.println(entry.getValue().toString());
|
|
||||||
}
|
|
||||||
for (Map.Entry<InetAddress, Measurement> entry : mDnsUdpChecks.entrySet()) {
|
|
||||||
if (entry.getKey() instanceof Inet4Address) {
|
|
||||||
pw.println(entry.getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Map.Entry<InetAddress, Measurement> entry : mDnsUdpChecks.entrySet()) {
|
|
||||||
if (entry.getKey() instanceof Inet6Address) {
|
|
||||||
pw.println(entry.getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user