use of com.linkedin.r2.message.timing.TimingKey in project rest.li by linkedin.
the class TestLatencyInstrumentation method checkTimingKeyConsistency.
/**
* Ensures that the set of recorded timing keys is "consistent", meaning that for any code path (denoted by key "A")
* which is a subset of another code path (denoted by key "B"), the duration of key A must be less than that of key B.
*/
private void checkTimingKeyConsistency() {
ArrayList<Map.Entry<TimingKey, TimingContextUtil.TimingContext>> entrySet = new ArrayList<>(_resultMap.entrySet());
int size = entrySet.size();
// (e.g. duration of "fwk/server/response" > duration of "fwk/server/response/restli")
for (int i = 0; i < size; i++) {
TimingKey keyA = entrySet.get(i).getKey();
if (!keyA.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
continue;
}
for (int j = 0; j < size; j++) {
TimingKey keyB = entrySet.get(j).getKey();
if (i == j || !keyB.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
continue;
}
if (keyA.getName().contains(keyB.getName())) {
TimingContextUtil.TimingContext contextA = entrySet.get(i).getValue();
TimingContextUtil.TimingContext contextB = entrySet.get(j).getValue();
String message = String.format("Expected %s (%.2fms) < %s (%.2fms)", keyA, contextA.getDurationNano() * NANOS_TO_MILLIS, keyB, contextB.getDurationNano() * NANOS_TO_MILLIS);
Assert.assertTrue(contextA.getDurationNano() < contextB.getDurationNano(), message);
}
}
}
}
Aggregations