Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Library
Commits
a62f7cd4
Commit
a62f7cd4
authored
Apr 15, 2016
by
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
a62f7cd4
...
...
@@ -6,6 +6,8 @@
-
Also accept
\r\n
as newline in Torperf results files.
-
Make unrecognized keys of Torperf results available together with
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
-
Include a Torperf results line with more than one unrecognized
...
...
src/org/torproject/descriptor/TorperfResult.java
View file @
a62f7cd4
...
...
@@ -55,9 +55,9 @@ public interface TorperfResult extends Descriptor {
* if the torperf line didn't contain that information. */
public
Boolean
didTimeout
();
/* Return the times when x% of expected bytes were read for
x = { 10,
*
20, 30, 40, 50, 60, 70, 80, 90 }
, or null if the torperf line didn't
*
contain that
information. */
/* Return the times when x% of expected bytes were read for
*
0 <= x <= 100
, or null if the torperf line didn't
contain that
* information. */
public
SortedMap
<
Integer
,
Long
>
getDataPercentiles
();
/* Return the time when the circuit was launched, or -1 if the torperf
...
...
src/org/torproject/descriptor/impl/TorperfResultImpl.java
View file @
a62f7cd4
...
...
@@ -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
,
String
line
)
throws
DescriptorParseException
{
String
key
=
keyValue
.
substring
(
0
,
keyValue
.
indexOf
(
"="
));
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
)
{
this
.
unrecognizedKeys
=
new
TreeMap
<>();
}
this
.
unrecognizedKeys
.
put
(
key
,
value
);
}
else
{
this
.
unparsedPercentiles
.
remove
(
percentileString
);
int
decileIndex
=
(
Integer
.
parseInt
(
percentileString
)
/
10
)
-
1
;
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
return
this
.
didTimeout
;
}
private
Long
[]
data
Deciles
=
new
Long
[
9
]
;
private
SortedMap
<
Integer
,
Long
>
data
Percentiles
;
public
SortedMap
<
Integer
,
Long
>
getDataPercentiles
()
{
if
(
this
.
dataDeciles
==
null
)
{
return
null
;
}
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
;
return
this
.
dataPercentiles
==
null
?
null
:
new
TreeMap
<>(
this
.
dataPercentiles
);
}
private
long
launchMillis
=
-
1L
;
...
...
test/org/torproject/descriptor/impl/TorperfResultImplTest.java
View file @
a62f7cd4
...
...
@@ -44,7 +44,7 @@ public class TorperfResultImplTest {
}
@Test
()
public
void
testAllAnnotatedInput
()
throws
Exception
{
public
void
testAllAnnotatedInput
()
throws
Exception
{
byte
[]
asciiBytes
=
(
torperfAnnotation
+
input
+
torperfAnnotation
+
input
+
torperfAnnotation
+
input
).
getBytes
(
"US-ASCII"
);
...
...
@@ -82,5 +82,16 @@ public class TorperfResultImplTest {
+
"READBYTES=51416 REQUEST=1441065601.86 RESPONSE=1441065602.38 "
+
"SOCKET=1441065601.86 SOURCE=moria START=1441065601.86 "
+
"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
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment