use of io.trino.spi.metrics.Metrics in project trino by trinodb.
the class TestMetrics method testDurationTiming.
@Test
public void testDurationTiming() {
DurationTiming d1 = new DurationTiming(new Duration(1234, NANOSECONDS));
DurationTiming d2 = new DurationTiming(new Duration(1, NANOSECONDS));
assertThat(d1.toString()).matches("\\{duration=1.23us\\}");
Metrics m1 = new Metrics(ImmutableMap.of("a", d1));
Metrics m2 = new Metrics(ImmutableMap.of("a", d2));
DurationTiming merged = (DurationTiming) merge(m1, m2).getMetrics().get("a");
assertThat(merged.getAirliftDuration().roundTo(NANOSECONDS)).isEqualTo(1235);
assertThat(merged.getDuration().toNanos()).isEqualTo(1235);
assertThat(merged.toString()).matches("\\{duration=1.24us\\}");
}
use of io.trino.spi.metrics.Metrics in project trino by trinodb.
the class TestMetrics method testFailIncompatibleTypes.
@Test(expectedExceptions = ClassCastException.class)
public void testFailIncompatibleTypes() {
Metrics m1 = new Metrics(ImmutableMap.of("a", new TDigestHistogram(new TDigest())));
Metrics m2 = new Metrics(ImmutableMap.of("a", new LongCount(0)));
merge(m1, m2);
}
use of io.trino.spi.metrics.Metrics in project trino by trinodb.
the class TextRenderer method printMetrics.
private void printMetrics(StringBuilder output, String label, Function<BasicOperatorStats, Metrics> metricsGetter, PlanNodeStats stats) {
if (!verbose) {
return;
}
Map<String, String> translatedOperatorTypes = translateOperatorTypes(stats.getOperatorTypes());
for (String operator : translatedOperatorTypes.keySet()) {
String translatedOperatorType = translatedOperatorTypes.get(operator);
Metrics metrics = metricsGetter.apply(stats.getOperatorStats().get(operator));
if (metrics.getMetrics().isEmpty()) {
continue;
}
output.append(translatedOperatorType + label).append("\n");
Map<String, Metric<?>> sortedMap = new TreeMap<>(metrics.getMetrics());
sortedMap.forEach((name, metric) -> output.append(format(" '%s' = %s\n", name, metric)));
}
}
use of io.trino.spi.metrics.Metrics in project trino by trinodb.
the class TestMemoryConnectorTest method testCustomMetricsScanOnly.
@Test
@Flaky(issue = "https://github.com/trinodb/trino/issues/8691", match = "ComparisonFailure: expected:<LongCount\\{total=\\[\\d+]}> but was:<(LongCount\\{total=\\[\\d+]}|null)>")
public void testCustomMetricsScanOnly() {
Metrics metrics = collectCustomMetrics("SELECT partkey FROM part");
assertThat(metrics.getMetrics().get("rows")).isEqualTo(new LongCount(PART_COUNT));
assertThat(metrics.getMetrics().get("started")).isEqualTo(metrics.getMetrics().get("finished"));
assertThat(((Count<?>) metrics.getMetrics().get("finished")).getTotal()).isGreaterThan(0);
}
use of io.trino.spi.metrics.Metrics in project trino by trinodb.
the class TestMemoryConnectorTest method collectCustomMetrics.
private Metrics collectCustomMetrics(String sql) {
DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner();
ResultWithQueryId<MaterializedResult> result = runner.executeWithQueryId(getSession(), sql);
return runner.getCoordinator().getQueryManager().getFullQueryInfo(result.getQueryId()).getQueryStats().getOperatorSummaries().stream().map(OperatorStats::getConnectorMetrics).reduce(Metrics.EMPTY, Metrics::mergeWith);
}
Aggregations