Commit a62f7cd4 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Recognize Torperf DATEPERCx fields for 0 <= x <= 100.

And don't break if x is non-numeric.  Spotted by iwakeh.
parent 45ad8a0d
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
- Also accept \r\n as newline in Torperf results files. - Also accept \r\n as newline in Torperf results files.
- Make unrecognized keys of Torperf results available together with - Make unrecognized keys of Torperf results available together with
the corresponding values, rather than just the whole line. the corresponding values, rather than just the whole line.
- In Torperf results, recognize all percentiles of expected bytes
read for 0 <= x <= 100 rather than just x = { 10, 20, ..., 90 }.
* Minor changes * Minor changes
- Include a Torperf results line with more than one unrecognized - Include a Torperf results line with more than one unrecognized
......
...@@ -55,9 +55,9 @@ public interface TorperfResult extends Descriptor { ...@@ -55,9 +55,9 @@ public interface TorperfResult extends Descriptor {
* if the torperf line didn't contain that information. */ * if the torperf line didn't contain that information. */
public Boolean didTimeout(); public Boolean didTimeout();
/* Return the times when x% of expected bytes were read for x = { 10, /* Return the times when x% of expected bytes were read for
* 20, 30, 40, 50, 60, 70, 80, 90 }, or null if the torperf line didn't * 0 <= x <= 100, or null if the torperf line didn't contain that
* contain that information. */ * information. */
public SortedMap<Integer, Long> getDataPercentiles(); public SortedMap<Integer, Long> getDataPercentiles();
/* Return the time when the circuit was launched, or -1 if the torperf /* Return the time when the circuit was launched, or -1 if the torperf
......
...@@ -275,22 +275,28 @@ public class TorperfResultImpl extends DescriptorImpl ...@@ -275,22 +275,28 @@ public class TorperfResultImpl extends DescriptorImpl
} }
} }
private Set<String> unparsedPercentiles = new HashSet<>(
Arrays.asList("10,20,30,40,50,60,70,80,90".split(",")));
private void parseDataPercentile(String value, String keyValue, private void parseDataPercentile(String value, String keyValue,
String line) throws DescriptorParseException { String line) throws DescriptorParseException {
String key = keyValue.substring(0, keyValue.indexOf("=")); String key = keyValue.substring(0, keyValue.indexOf("="));
String percentileString = key.substring("DATAPERC".length()); String percentileString = key.substring("DATAPERC".length());
if (!this.unparsedPercentiles.contains(percentileString)) { int percentile = -1;
try {
percentile = Integer.parseInt(percentileString);
} catch (NumberFormatException e) {
/* Treat key as unrecognized below. */
percentile = -1;
}
if (percentile < 0 || percentile > 100) {
if (this.unrecognizedKeys == null) { if (this.unrecognizedKeys == null) {
this.unrecognizedKeys = new TreeMap<>(); this.unrecognizedKeys = new TreeMap<>();
} }
this.unrecognizedKeys.put(key, value); this.unrecognizedKeys.put(key, value);
} else { } else {
this.unparsedPercentiles.remove(percentileString);
int decileIndex = (Integer.parseInt(percentileString) / 10) - 1;
long timestamp = this.parseTimestamp(value, keyValue, line); long timestamp = this.parseTimestamp(value, keyValue, line);
this.dataDeciles[decileIndex] = timestamp; if (this.dataPercentiles == null) {
this.dataPercentiles = new TreeMap<>();
}
this.dataPercentiles.put(percentile, timestamp);
} }
} }
...@@ -466,18 +472,10 @@ public class TorperfResultImpl extends DescriptorImpl ...@@ -466,18 +472,10 @@ public class TorperfResultImpl extends DescriptorImpl
return this.didTimeout; return this.didTimeout;
} }
private Long[] dataDeciles = new Long[9]; private SortedMap<Integer, Long> dataPercentiles;
public SortedMap<Integer, Long> getDataPercentiles() { public SortedMap<Integer, Long> getDataPercentiles() {
if (this.dataDeciles == null) { return this.dataPercentiles == null ? null
return null; : new TreeMap<>(this.dataPercentiles);
}
SortedMap<Integer, Long> result = new TreeMap<>();
for (int i = 0; i < dataDeciles.length; i++) {
if (dataDeciles[i] > 0L) {
result.put(10 * (i + 1), dataDeciles[i]);
}
}
return result;
} }
private long launchMillis = -1L; private long launchMillis = -1L;
......
...@@ -44,7 +44,7 @@ public class TorperfResultImplTest { ...@@ -44,7 +44,7 @@ public class TorperfResultImplTest {
} }
@Test() @Test()
public void testAllAnnotatedInput() throws Exception{ public void testAllAnnotatedInput() throws Exception {
byte[] asciiBytes = (torperfAnnotation + input byte[] asciiBytes = (torperfAnnotation + input
+ torperfAnnotation + input + torperfAnnotation + input
+ torperfAnnotation + input).getBytes("US-ASCII"); + torperfAnnotation + input).getBytes("US-ASCII");
...@@ -82,5 +82,16 @@ public class TorperfResultImplTest { ...@@ -82,5 +82,16 @@ public class TorperfResultImplTest {
+ "READBYTES=51416 REQUEST=1441065601.86 RESPONSE=1441065602.38 " + "READBYTES=51416 REQUEST=1441065601.86 RESPONSE=1441065602.38 "
+ "SOCKET=1441065601.86 SOURCE=moria START=1441065601.86 " + "SOCKET=1441065601.86 SOURCE=moria START=1441065601.86 "
+ "TIMEOUT=1500 USED_AT=1441065603.40 USED_BY=2475 WRITEBYTES=75\n"; + "TIMEOUT=1500 USED_AT=1441065603.40 USED_BY=2475 WRITEBYTES=75\n";
@Test()
public void testDatapercNonNumeric() throws Exception {
List<Descriptor> result = TorperfResultImpl.parseTorperfResults(
("DATAPERMILLE=2.0 " + input).getBytes(), false);
assertEquals(1, result.size());
TorperfResultImpl torperfResult = (TorperfResultImpl) result.get(0);
assertEquals(1, torperfResult.getUnrecognizedKeys().size());
assertEquals("DATAPERMILLE",
torperfResult.getUnrecognizedKeys().firstKey());
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment