diff --git a/presto-common/src/main/java/com/facebook/presto/common/RuntimeMetric.java b/presto-common/src/main/java/com/facebook/presto/common/RuntimeMetric.java index a3460b8da5eda..daa8eea438e02 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/RuntimeMetric.java +++ b/presto-common/src/main/java/com/facebook/presto/common/RuntimeMetric.java @@ -30,6 +30,7 @@ public class RuntimeMetric { private final String name; + private final RuntimeUnit unit; private final AtomicLong sum = new AtomicLong(); private final AtomicLong count = new AtomicLong(); private final AtomicLong max = new AtomicLong(Long.MIN_VALUE); @@ -39,28 +40,31 @@ public class RuntimeMetric * Creates a new empty RuntimeMetric. * * @param name Name of this metric. If used in the presto core code base, this should be a value defined in {@link RuntimeMetricName}. But connectors could use arbitrary names. + * @param unit Unit of this metric. Available units are defined in {@link RuntimeUnit}. */ - public RuntimeMetric(String name) + public RuntimeMetric(String name, RuntimeUnit unit) { this.name = requireNonNull(name, "name is null"); + this.unit = requireNonNull(unit, "unit is null"); } public static RuntimeMetric copyOf(RuntimeMetric metric) { requireNonNull(metric, "metric is null"); - return new RuntimeMetric(metric.getName(), metric.getSum(), metric.getCount(), metric.getMax(), metric.getMin()); + return new RuntimeMetric(metric.getName(), metric.getUnit(), metric.getSum(), metric.getCount(), metric.getMax(), metric.getMin()); } @JsonCreator @ThriftConstructor public RuntimeMetric( @JsonProperty("name") String name, + @JsonProperty("unit") RuntimeUnit unit, @JsonProperty("sum") long sum, @JsonProperty("count") long count, @JsonProperty("max") long max, @JsonProperty("min") long min) { - this(name); + this(name, unit); set(sum, count, max, min); } @@ -75,6 +79,7 @@ private void set(long sum, long count, long max, long min) public void set(RuntimeMetric metric) { requireNonNull(metric, "metric is null"); + checkState(unit == metric.getUnit(), "The metric must have the same unit type as the current one."); set(metric.getSum(), metric.getCount(), metric.getMax(), metric.getMin()); } @@ -104,6 +109,8 @@ public static RuntimeMetric merge(RuntimeMetric metric1, RuntimeMetric metric2) if (metric2 == null) { return metric1; } + checkState(metric1.getUnit() == metric2.getUnit(), "Two metrics to be merged must have the same unit type."); + RuntimeMetric mergedMetric = copyOf(metric1); mergedMetric.mergeWith(metric2); return mergedMetric; @@ -117,6 +124,7 @@ public void mergeWith(RuntimeMetric metric) if (metric == null) { return; } + checkState(unit == metric.getUnit(), "The metric to be merged must have the same unit type as the current one."); sum.addAndGet(metric.getSum()); count.addAndGet(metric.getCount()); max.accumulateAndGet(metric.getMax(), Math::max); @@ -150,4 +158,18 @@ public long getMin() { return min.get(); } + + @JsonProperty + @ThriftField(6) + public RuntimeUnit getUnit() + { + return unit; + } + + private static void checkState(boolean condition, String message) + { + if (!condition) { + throw new IllegalStateException(message); + } + } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/RuntimeStats.java b/presto-common/src/main/java/com/facebook/presto/common/RuntimeStats.java index 57bce3e317249..4e503e1d129dd 100644 --- a/presto-common/src/main/java/com/facebook/presto/common/RuntimeStats.java +++ b/presto-common/src/main/java/com/facebook/presto/common/RuntimeStats.java @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; +import static com.facebook.presto.common.RuntimeUnit.NANO; import static java.util.Objects.requireNonNull; /** @@ -44,7 +45,7 @@ public RuntimeStats() public RuntimeStats(Map metrics) { requireNonNull(metrics, "metrics is null"); - metrics.forEach((name, newMetric) -> this.metrics.computeIfAbsent(name, RuntimeMetric::new).mergeWith(newMetric)); + metrics.forEach((name, newMetric) -> this.metrics.computeIfAbsent(name, k -> new RuntimeMetric(name, newMetric.getUnit())).mergeWith(newMetric)); } public static RuntimeStats copyOf(RuntimeStats stats) @@ -85,17 +86,17 @@ public Map getMetrics() return Collections.unmodifiableMap(metrics); } - public void addMetricValue(String name, long value) + public void addMetricValue(String name, RuntimeUnit unit, long value) { - metrics.computeIfAbsent(name, RuntimeMetric::new).addValue(value); + metrics.computeIfAbsent(name, k -> new RuntimeMetric(name, unit)).addValue(value); } - public void addMetricValueIgnoreZero(String name, long value) + public void addMetricValueIgnoreZero(String name, RuntimeUnit unit, long value) { if (value == 0) { return; } - addMetricValue(name, value); + addMetricValue(name, unit, value); } /** @@ -103,7 +104,7 @@ public void addMetricValueIgnoreZero(String name, long value) */ public void mergeMetric(String name, RuntimeMetric metric) { - metrics.computeIfAbsent(name, RuntimeMetric::new).mergeWith(metric); + metrics.computeIfAbsent(name, k -> new RuntimeMetric(name, metric.getUnit())).mergeWith(metric); } /** @@ -114,7 +115,7 @@ public void mergeWith(RuntimeStats stats) if (stats == null) { return; } - stats.getMetrics().forEach((name, newMetric) -> metrics.computeIfAbsent(name, RuntimeMetric::new).mergeWith(newMetric)); + stats.getMetrics().forEach((name, newMetric) -> metrics.computeIfAbsent(name, k -> new RuntimeMetric(name, newMetric.getUnit())).mergeWith(newMetric)); } /** @@ -126,14 +127,14 @@ public void update(RuntimeStats stats) if (stats == null) { return; } - stats.getMetrics().forEach((name, newMetric) -> metrics.computeIfAbsent(name, RuntimeMetric::new).set(newMetric)); + stats.getMetrics().forEach((name, newMetric) -> metrics.computeIfAbsent(name, k -> new RuntimeMetric(name, newMetric.getUnit())).set(newMetric)); } public V profileNanos(String tag, Supplier supplier) { long startTime = System.nanoTime(); V result = supplier.get(); - addMetricValueIgnoreZero(tag, System.nanoTime() - startTime); + addMetricValueIgnoreZero(tag, NANO, System.nanoTime() - startTime); return result; } } diff --git a/presto-common/src/main/java/com/facebook/presto/common/RuntimeUnit.java b/presto-common/src/main/java/com/facebook/presto/common/RuntimeUnit.java new file mode 100644 index 0000000000000..a5bc593232ea5 --- /dev/null +++ b/presto-common/src/main/java/com/facebook/presto/common/RuntimeUnit.java @@ -0,0 +1,36 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.common; + +import com.facebook.drift.annotations.ThriftEnum; +import com.facebook.drift.annotations.ThriftEnumValue; + +@ThriftEnum +public enum RuntimeUnit +{ + NONE(0), NANO(1), BYTE(2); + + private final int value; + + RuntimeUnit(int value) + { + this.value = value; + } + + @ThriftEnumValue + public int getValue() + { + return value; + } +} diff --git a/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeMetric.java b/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeMetric.java index c65d327252269..31c7ea43f242a 100644 --- a/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeMetric.java +++ b/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeMetric.java @@ -16,6 +16,9 @@ import com.facebook.airlift.json.JsonCodec; import org.testng.annotations.Test; +import static com.facebook.presto.common.RuntimeUnit.BYTE; +import static com.facebook.presto.common.RuntimeUnit.NANO; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static org.testng.Assert.assertEquals; public class TestRuntimeMetric @@ -25,6 +28,7 @@ public class TestRuntimeMetric private void assertRuntimeMetricEquals(RuntimeMetric m1, RuntimeMetric m2) { assertEquals(m1.getName(), m2.getName()); + assertEquals(m1.getUnit(), m2.getUnit()); assertEquals(m1.getSum(), m2.getSum()); assertEquals(m1.getCount(), m2.getCount()); assertEquals(m1.getMax(), m2.getMax()); @@ -34,63 +38,82 @@ private void assertRuntimeMetricEquals(RuntimeMetric m1, RuntimeMetric m2) @Test public void testAddValue() { - RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME); + RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME, NONE); metric.addValue(101); - assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, 101, 1, 101, 101)); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 101, 1, 101, 101)); metric.addValue(99); - assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, 200, 2, 101, 99)); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 200, 2, 101, 99)); metric.addValue(201); - assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, 401, 3, 201, 99)); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 401, 3, 201, 99)); + + metric.addValue(202); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 603, 4, 202, 99)); } @Test public void testCopy() { - RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME, 1, 1, 1, 1); + RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME, NONE, 1, 1, 1, 1); RuntimeMetric metricCopy = RuntimeMetric.copyOf(metric); // Verify that updating one metric doesn't affect its copy. metric.addValue(2); - assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, 3, 2, 2, 1)); - assertRuntimeMetricEquals(metricCopy, new RuntimeMetric(TEST_METRIC_NAME, 1, 1, 1, 1)); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 3, 2, 2, 1)); + assertRuntimeMetricEquals(metricCopy, new RuntimeMetric(TEST_METRIC_NAME, NONE, 1, 1, 1, 1)); metricCopy.addValue(2); - assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, 3, 2, 2, 1)); + assertRuntimeMetricEquals(metric, new RuntimeMetric(TEST_METRIC_NAME, NONE, 3, 2, 2, 1)); assertRuntimeMetricEquals(metricCopy, metric); } @Test public void testMergeWith() { - RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, 5, 2, 4, 1); - RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, 20, 2, 11, 9); + RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 5, 2, 4, 1); + RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 20, 2, 11, 9); metric1.mergeWith(metric2); - assertRuntimeMetricEquals(metric1, new RuntimeMetric(TEST_METRIC_NAME, 25, 4, 11, 1)); + assertRuntimeMetricEquals(metric1, new RuntimeMetric(TEST_METRIC_NAME, NONE, 25, 4, 11, 1)); metric2.mergeWith(metric2); - assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, 40, 4, 11, 9)); + assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, NONE, 40, 4, 11, 9)); metric2.mergeWith(null); - assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, 40, 4, 11, 9)); + assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, NONE, 40, 4, 11, 9)); + } + + @Test(expectedExceptions = {IllegalStateException.class}) + public void testMergeWithWithConflictUnits() + { + RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, NANO, 5, 2, 4, 1); + RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, BYTE, 20, 2, 11, 9); + metric1.mergeWith(metric2); } @Test public void testMerge() { - RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, 5, 2, 4, 1); - RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, 20, 2, 11, 9); - assertRuntimeMetricEquals(RuntimeMetric.merge(metric1, metric2), new RuntimeMetric(TEST_METRIC_NAME, 25, 4, 11, 1)); + RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 5, 2, 4, 1); + RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 20, 2, 11, 9); + assertRuntimeMetricEquals(RuntimeMetric.merge(metric1, metric2), new RuntimeMetric(TEST_METRIC_NAME, NONE, 25, 4, 11, 1)); + + assertRuntimeMetricEquals(metric1, new RuntimeMetric(TEST_METRIC_NAME, NONE, 5, 2, 4, 1)); + assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, NONE, 20, 2, 11, 9)); + } - assertRuntimeMetricEquals(metric1, new RuntimeMetric(TEST_METRIC_NAME, 5, 2, 4, 1)); - assertRuntimeMetricEquals(metric2, new RuntimeMetric(TEST_METRIC_NAME, 20, 2, 11, 9)); + @Test(expectedExceptions = {IllegalStateException.class}) + public void testMergeWithConflictUnits() + { + RuntimeMetric metric1 = new RuntimeMetric(TEST_METRIC_NAME, NANO, 5, 2, 4, 1); + RuntimeMetric metric2 = new RuntimeMetric(TEST_METRIC_NAME, BYTE, 20, 2, 11, 9); + RuntimeMetric.merge(metric1, metric2); } @Test public void testJson() { JsonCodec codec = JsonCodec.jsonCodec(RuntimeMetric.class); - RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME); + RuntimeMetric metric = new RuntimeMetric(TEST_METRIC_NAME, NANO); metric.addValue(101); metric.addValue(202); diff --git a/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeStats.java b/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeStats.java index df381e0658df1..c6eb4a3977e4d 100644 --- a/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeStats.java +++ b/presto-common/src/test/java/com/facebook/presto/common/TestRuntimeStats.java @@ -16,6 +16,9 @@ import com.facebook.airlift.json.JsonCodec; import org.testng.annotations.Test; +import static com.facebook.presto.common.RuntimeUnit.BYTE; +import static com.facebook.presto.common.RuntimeUnit.NANO; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; @@ -24,10 +27,14 @@ public class TestRuntimeStats private static final String TEST_METRIC_NAME_1 = "test1"; private static final String TEST_METRIC_NAME_2 = "test2"; private static final String TEST_METRIC_NAME_3 = "test3"; + private static final String TEST_METRIC_NAME_NANO_1 = "test_nano_1"; + private static final String TEST_METRIC_NAME_NANO_2 = "test_nano_2"; + private static final String TEST_METRIC_NAME_BYTE = "test_byte"; private void assertRuntimeMetricEquals(RuntimeMetric m1, RuntimeMetric m2) { assertEquals(m1.getName(), m2.getName()); + assertEquals(m1.getUnit(), m2.getUnit()); assertEquals(m1.getSum(), m2.getSum()); assertEquals(m1.getCount(), m2.getCount()); assertEquals(m1.getMax(), m2.getMax()); @@ -38,13 +45,17 @@ private void assertRuntimeMetricEquals(RuntimeMetric m1, RuntimeMetric m2) public void testAddMetricValue() { RuntimeStats stats = new RuntimeStats(); - stats.addMetricValue(TEST_METRIC_NAME_1, 2); - stats.addMetricValue(TEST_METRIC_NAME_1, 3); - stats.addMetricValue(TEST_METRIC_NAME_1, 5); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 3); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 5); + stats.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 7); assertRuntimeMetricEquals( stats.getMetric(TEST_METRIC_NAME_1), - new RuntimeMetric(TEST_METRIC_NAME_1, 10, 3, 5, 2)); + new RuntimeMetric(TEST_METRIC_NAME_1, NONE, 10, 3, 5, 2)); + assertRuntimeMetricEquals( + stats.getMetric(TEST_METRIC_NAME_NANO_1), + new RuntimeMetric(TEST_METRIC_NAME_NANO_1, NANO, 7, 1, 7, 7)); stats.reset(); assertEquals(stats.getMetrics().size(), 0); @@ -54,93 +65,152 @@ public void testAddMetricValue() public void testMergeMetric() { RuntimeStats stats1 = new RuntimeStats(); - stats1.addMetricValue(TEST_METRIC_NAME_1, 2); - stats1.addMetricValue(TEST_METRIC_NAME_1, 3); + stats1.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); + stats1.addMetricValue(TEST_METRIC_NAME_1, NONE, 3); + stats1.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 3); RuntimeStats stats2 = new RuntimeStats(); + stats2.addMetricValue(TEST_METRIC_NAME_NANO_2, NANO, 5); stats2.mergeMetric(TEST_METRIC_NAME_2, stats1.getMetric(TEST_METRIC_NAME_1)); + stats2.mergeMetric(TEST_METRIC_NAME_NANO_2, stats1.getMetric(TEST_METRIC_NAME_NANO_1)); - assertEquals(stats2.getMetrics().size(), 1); + assertEquals(stats2.getMetrics().size(), 2); assertRuntimeMetricEquals( stats2.getMetric(TEST_METRIC_NAME_2), - new RuntimeMetric(TEST_METRIC_NAME_2, 5, 2, 3, 2)); + new RuntimeMetric(TEST_METRIC_NAME_2, NONE, 5, 2, 3, 2)); + assertRuntimeMetricEquals( + stats2.getMetric(TEST_METRIC_NAME_NANO_2), + new RuntimeMetric(TEST_METRIC_NAME_NANO_2, NANO, 8, 2, 5, 3)); + } + + @Test(expectedExceptions = {IllegalStateException.class}) + public void testMergeMetricWithConflictUnits() + { + RuntimeStats stats1 = new RuntimeStats(); + stats1.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 3); + + RuntimeStats stats2 = new RuntimeStats(); + stats2.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 3); + stats2.mergeMetric(TEST_METRIC_NAME_BYTE, stats1.getMetric(TEST_METRIC_NAME_NANO_1)); } @Test public void testMerge() { RuntimeStats stats1 = new RuntimeStats(); - stats1.addMetricValue(TEST_METRIC_NAME_1, 2); - stats1.addMetricValue(TEST_METRIC_NAME_1, 3); - stats1.addMetricValue(TEST_METRIC_NAME_2, 1); - stats1.addMetricValue(TEST_METRIC_NAME_2, 2); + stats1.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); + stats1.addMetricValue(TEST_METRIC_NAME_1, NONE, 3); + stats1.addMetricValue(TEST_METRIC_NAME_2, NONE, 1); + stats1.addMetricValue(TEST_METRIC_NAME_2, NONE, 2); + stats1.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 2); + stats1.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 1); RuntimeStats stats2 = new RuntimeStats(); - stats2.addMetricValue(TEST_METRIC_NAME_2, 0); - stats2.addMetricValue(TEST_METRIC_NAME_2, 3); - stats2.addMetricValue(TEST_METRIC_NAME_3, 8); + stats2.addMetricValue(TEST_METRIC_NAME_2, NONE, 0); + stats2.addMetricValue(TEST_METRIC_NAME_2, NONE, 3); + stats2.addMetricValue(TEST_METRIC_NAME_3, NONE, 8); + stats2.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 3); RuntimeStats mergedStats = RuntimeStats.merge(stats1, stats2); assertRuntimeMetricEquals( mergedStats.getMetric(TEST_METRIC_NAME_1), - new RuntimeMetric(TEST_METRIC_NAME_1, 5, 2, 3, 2)); + new RuntimeMetric(TEST_METRIC_NAME_1, NONE, 5, 2, 3, 2)); assertRuntimeMetricEquals( mergedStats.getMetric(TEST_METRIC_NAME_2), - new RuntimeMetric(TEST_METRIC_NAME_2, 6, 4, 3, 0)); + new RuntimeMetric(TEST_METRIC_NAME_2, NONE, 6, 4, 3, 0)); assertRuntimeMetricEquals( mergedStats.getMetric(TEST_METRIC_NAME_3), - new RuntimeMetric(TEST_METRIC_NAME_3, 8, 1, 8, 8)); + new RuntimeMetric(TEST_METRIC_NAME_3, NONE, 8, 1, 8, 8)); + assertRuntimeMetricEquals( + mergedStats.getMetric(TEST_METRIC_NAME_NANO_1), + new RuntimeMetric(TEST_METRIC_NAME_NANO_1, NANO, 2, 1, 2, 2)); + assertRuntimeMetricEquals( + mergedStats.getMetric(TEST_METRIC_NAME_BYTE), + new RuntimeMetric(TEST_METRIC_NAME_BYTE, BYTE, 4, 2, 3, 1)); stats1.mergeWith(stats2); mergedStats.getMetrics().values().forEach(metric -> assertRuntimeMetricEquals(metric, stats1.getMetric(metric.getName()))); assertEquals(mergedStats.getMetrics().size(), stats1.getMetrics().size()); } + @Test(expectedExceptions = {IllegalStateException.class}) + public void testMergeWithConflictUnits() + { + RuntimeStats stats1 = new RuntimeStats(); + stats1.addMetricValue(TEST_METRIC_NAME_BYTE, NANO, 1); + + RuntimeStats stats2 = new RuntimeStats(); + stats2.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 3); + + RuntimeStats.merge(stats1, stats2); + } + @Test public void testMergeWithNull() { RuntimeStats stats = new RuntimeStats(); - stats.addMetricValue(TEST_METRIC_NAME_1, 2); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); stats.mergeWith(null); assertRuntimeMetricEquals( stats.getMetric(TEST_METRIC_NAME_1), - new RuntimeMetric(TEST_METRIC_NAME_1, 2, 1, 2, 2)); + new RuntimeMetric(TEST_METRIC_NAME_1, NONE, 2, 1, 2, 2)); } @Test public void testUpdate() { RuntimeStats stats1 = new RuntimeStats(); - stats1.addMetricValue(TEST_METRIC_NAME_1, 2); + stats1.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); stats1.update(null); assertRuntimeMetricEquals( stats1.getMetric(TEST_METRIC_NAME_1), - new RuntimeMetric(TEST_METRIC_NAME_1, 2, 1, 2, 2)); + new RuntimeMetric(TEST_METRIC_NAME_1, NONE, 2, 1, 2, 2)); RuntimeStats stats2 = new RuntimeStats(); - stats2.addMetricValue(TEST_METRIC_NAME_2, 2); + stats2.addMetricValue(TEST_METRIC_NAME_2, NONE, 2); stats1.update(stats2); assertRuntimeMetricEquals( stats1.getMetric(TEST_METRIC_NAME_1), - new RuntimeMetric(TEST_METRIC_NAME_1, 2, 1, 2, 2)); + new RuntimeMetric(TEST_METRIC_NAME_1, NONE, 2, 1, 2, 2)); assertRuntimeMetricEquals( stats1.getMetric(TEST_METRIC_NAME_2), stats1.getMetric(TEST_METRIC_NAME_2)); - stats2.addMetricValue(TEST_METRIC_NAME_2, 4); + stats2.addMetricValue(TEST_METRIC_NAME_2, NONE, 4); stats1.update(stats2); assertRuntimeMetricEquals( stats1.getMetric(TEST_METRIC_NAME_2), stats1.getMetric(TEST_METRIC_NAME_2)); + + stats2.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 4); + stats1.update(stats2); + assertRuntimeMetricEquals( + stats1.getMetric(TEST_METRIC_NAME_NANO_1), + stats1.getMetric(TEST_METRIC_NAME_NANO_1)); + } + + @Test(expectedExceptions = {IllegalStateException.class}) + public void testUpdateWithConflictUnits() + { + RuntimeStats stats1 = new RuntimeStats(); + stats1.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 4); + + RuntimeStats stats2 = new RuntimeStats(); + stats2.addMetricValue(TEST_METRIC_NAME_BYTE, NANO, 4); + + stats1.update(stats2); } @Test public void testJson() { RuntimeStats stats = new RuntimeStats(); - stats.addMetricValue(TEST_METRIC_NAME_1, 2); - stats.addMetricValue(TEST_METRIC_NAME_1, 3); - stats.addMetricValue(TEST_METRIC_NAME_2, 8); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 2); + stats.addMetricValue(TEST_METRIC_NAME_1, NONE, 3); + stats.addMetricValue(TEST_METRIC_NAME_2, NONE, 8); + stats.addMetricValue(TEST_METRIC_NAME_3, NONE, 8); + stats.addMetricValue(TEST_METRIC_NAME_NANO_1, NANO, 8); + stats.addMetricValue(TEST_METRIC_NAME_BYTE, BYTE, 8); JsonCodec codec = JsonCodec.jsonCodec(RuntimeStats.class); String json = codec.toJson(stats); @@ -162,6 +232,6 @@ public void testNullJson() public void testReturnUnmodifiedMetrics() { RuntimeStats stats = new RuntimeStats(); - stats.getMetrics().put(TEST_METRIC_NAME_1, new RuntimeMetric(TEST_METRIC_NAME_1)); + stats.getMetrics().put(TEST_METRIC_NAME_1, new RuntimeMetric(TEST_METRIC_NAME_1, NONE)); } } diff --git a/presto-hive-common/src/main/java/com/facebook/presto/hive/HiveFileContext.java b/presto-hive-common/src/main/java/com/facebook/presto/hive/HiveFileContext.java index 34f5419aa7e40..598d6165eebd3 100644 --- a/presto-hive-common/src/main/java/com/facebook/presto/hive/HiveFileContext.java +++ b/presto-hive-common/src/main/java/com/facebook/presto/hive/HiveFileContext.java @@ -17,6 +17,7 @@ import java.util.Optional; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.hive.CacheQuota.NO_CACHE_CONSTRAINTS; import static java.util.Objects.requireNonNull; @@ -82,7 +83,7 @@ public interface ExtraHiveFileInfo public void incrementCounter(String name, long value) { if (verboseRuntimeStatsEnabled) { - stats.addMetricValue(name, value); + stats.addMetricValue(name, NONE, value); } } diff --git a/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java b/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java index 30abef91e1f8d..598ed83e09461 100644 --- a/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java +++ b/presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java @@ -14,7 +14,6 @@ package com.facebook.presto.execution; import com.facebook.airlift.stats.Distribution.DistributionSnapshot; -import com.facebook.presto.common.RuntimeMetricName; import com.facebook.presto.common.RuntimeStats; import com.facebook.presto.operator.BlockedReason; import com.facebook.presto.operator.OperatorStats; @@ -34,7 +33,13 @@ import java.util.Optional; import java.util.Set; +import static com.facebook.presto.common.RuntimeMetricName.DRIVER_COUNT_PER_TASK; import static com.facebook.presto.common.RuntimeMetricName.GET_SPLITS_TIME_NANOS; +import static com.facebook.presto.common.RuntimeMetricName.TASK_BLOCKED_TIME_NANOS; +import static com.facebook.presto.common.RuntimeMetricName.TASK_ELAPSED_TIME_NANOS; +import static com.facebook.presto.common.RuntimeMetricName.TASK_QUEUED_TIME_NANOS; +import static com.facebook.presto.common.RuntimeMetricName.TASK_SCHEDULED_TIME_NANOS; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.execution.StageExecutionState.FINISHED; import static io.airlift.units.DataSize.succinctBytes; import static io.airlift.units.Duration.succinctDuration; @@ -109,7 +114,7 @@ public static StageExecutionInfo create( Map operatorToStats = new HashMap<>(); RuntimeStats mergedRuntimeStats = new RuntimeStats(); - mergedRuntimeStats.addMetricValueIgnoreZero(GET_SPLITS_TIME_NANOS, (long) getSplitDistribution.getTotal()); + mergedRuntimeStats.addMetricValueIgnoreZero(GET_SPLITS_TIME_NANOS, NONE, (long) getSplitDistribution.getTotal()); for (TaskInfo taskInfo : taskInfos) { TaskState taskState = taskInfo.getTaskStatus().getState(); if (taskState.isDone()) { @@ -175,11 +180,11 @@ public static StageExecutionInfo create( } } mergedRuntimeStats.mergeWith(taskStats.getRuntimeStats()); - mergedRuntimeStats.addMetricValue(RuntimeMetricName.DRIVER_COUNT_PER_TASK, taskStats.getTotalDrivers()); - mergedRuntimeStats.addMetricValue(RuntimeMetricName.TASK_ELAPSED_TIME_NANOS, taskStats.getElapsedTimeInNanos()); - mergedRuntimeStats.addMetricValueIgnoreZero(RuntimeMetricName.TASK_QUEUED_TIME_NANOS, taskStats.getQueuedTimeInNanos()); - mergedRuntimeStats.addMetricValue(RuntimeMetricName.TASK_SCHEDULED_TIME_NANOS, taskStats.getTotalScheduledTimeInNanos()); - mergedRuntimeStats.addMetricValueIgnoreZero(RuntimeMetricName.TASK_BLOCKED_TIME_NANOS, taskStats.getTotalBlockedTimeInNanos()); + mergedRuntimeStats.addMetricValue(DRIVER_COUNT_PER_TASK, NONE, taskStats.getTotalDrivers()); + mergedRuntimeStats.addMetricValue(TASK_ELAPSED_TIME_NANOS, NONE, taskStats.getElapsedTimeInNanos()); + mergedRuntimeStats.addMetricValueIgnoreZero(TASK_QUEUED_TIME_NANOS, NONE, taskStats.getQueuedTimeInNanos()); + mergedRuntimeStats.addMetricValue(TASK_SCHEDULED_TIME_NANOS, NONE, taskStats.getTotalScheduledTimeInNanos()); + mergedRuntimeStats.addMetricValueIgnoreZero(TASK_BLOCKED_TIME_NANOS, NONE, taskStats.getTotalBlockedTimeInNanos()); } StageExecutionStats stageExecutionStats = new StageExecutionStats( diff --git a/presto-main/src/main/java/com/facebook/presto/metadata/MetadataManager.java b/presto-main/src/main/java/com/facebook/presto/metadata/MetadataManager.java index c6dfc1643254a..898b16405a005 100644 --- a/presto-main/src/main/java/com/facebook/presto/metadata/MetadataManager.java +++ b/presto-main/src/main/java/com/facebook/presto/metadata/MetadataManager.java @@ -101,6 +101,7 @@ import static com.facebook.presto.SystemSessionProperties.isIgnoreStatsCalculatorFailures; import static com.facebook.presto.common.RuntimeMetricName.GET_LAYOUT_TIME_NANOS; import static com.facebook.presto.common.RuntimeMetricName.GET_MATERIALIZED_VIEW_STATUS_TIME_NANOS; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.common.function.OperatorType.BETWEEN; import static com.facebook.presto.common.function.OperatorType.EQUAL; import static com.facebook.presto.common.function.OperatorType.GREATER_THAN; @@ -395,7 +396,7 @@ public TableLayoutResult getLayout(Session session, TableHandle table, Constrain ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId); ConnectorSession connectorSession = session.toConnectorSession(connectorId); List layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns); - session.getRuntimeStats().addMetricValue(GET_LAYOUT_TIME_NANOS, System.nanoTime() - startTime); + session.getRuntimeStats().addMetricValue(GET_LAYOUT_TIME_NANOS, NONE, System.nanoTime() - startTime); if (layouts.size() != 1) { throw new PrestoException(NOT_SUPPORTED, "Connector returned multiple layouts for table " + table); diff --git a/presto-main/src/main/java/com/facebook/presto/operator/Driver.java b/presto-main/src/main/java/com/facebook/presto/operator/Driver.java index 4b55c02a26e81..795fbc758907a 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/Driver.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/Driver.java @@ -15,7 +15,6 @@ import com.facebook.airlift.log.Logger; import com.facebook.presto.common.Page; -import com.facebook.presto.common.RuntimeMetricName; import com.facebook.presto.execution.FragmentResultCacheContext; import com.facebook.presto.execution.ScheduledSplit; import com.facebook.presto.execution.TaskSource; @@ -48,6 +47,9 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.function.Supplier; +import static com.facebook.presto.common.RuntimeMetricName.FRAGMENT_RESULT_CACHE_HIT; +import static com.facebook.presto.common.RuntimeMetricName.FRAGMENT_RESULT_CACHE_MISS; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.operator.Operator.NOT_BLOCKED; import static com.facebook.presto.operator.SpillingUtils.checkSpillSucceeded; import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; @@ -266,7 +268,7 @@ private void processNewSources() .getFragmentResultCacheManager() .get(fragmentResultCacheContext.get().get().getHashedCanonicalPlanFragment(), split); sourceOperator.getOperatorContext().getRuntimeStats().addMetricValue( - pages.isPresent() ? RuntimeMetricName.FRAGMENT_RESULT_CACHE_HIT : RuntimeMetricName.FRAGMENT_RESULT_CACHE_MISS, 1); + pages.isPresent() ? FRAGMENT_RESULT_CACHE_HIT : FRAGMENT_RESULT_CACHE_MISS, NONE, 1); this.cachedResult.set(pages); this.split.set(split); } diff --git a/presto-main/src/main/java/com/facebook/presto/operator/ScanFilterAndProjectOperator.java b/presto-main/src/main/java/com/facebook/presto/operator/ScanFilterAndProjectOperator.java index a6bc3541dcb19..e0af6a04dcf5a 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/ScanFilterAndProjectOperator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/ScanFilterAndProjectOperator.java @@ -57,6 +57,7 @@ import static com.facebook.airlift.concurrent.MoreFutures.toListenableFuture; import static com.facebook.presto.common.RuntimeMetricName.STORAGE_READ_DATA_BYTES; import static com.facebook.presto.common.RuntimeMetricName.STORAGE_READ_TIME_NANOS; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; @@ -361,8 +362,8 @@ private void recordInputStats() operatorContext.recordRawInputWithTiming(inputBytes, positionCount, inputBytesReadTime); RuntimeStats runtimeStats = pageSource.getRuntimeStats(); if (runtimeStats != null) { - runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_TIME_NANOS, inputBytesReadTime); - runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_DATA_BYTES, inputBytes); + runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_TIME_NANOS, NONE, inputBytesReadTime); + runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_DATA_BYTES, NONE, inputBytes); operatorContext.updateStats(runtimeStats); } completedBytes = endCompletedBytes; diff --git a/presto-main/src/main/java/com/facebook/presto/operator/TableScanOperator.java b/presto-main/src/main/java/com/facebook/presto/operator/TableScanOperator.java index 424c257ad32f7..9e5ac21321aea 100644 --- a/presto-main/src/main/java/com/facebook/presto/operator/TableScanOperator.java +++ b/presto-main/src/main/java/com/facebook/presto/operator/TableScanOperator.java @@ -42,6 +42,7 @@ import static com.facebook.airlift.concurrent.MoreFutures.toListenableFuture; import static com.facebook.presto.common.RuntimeMetricName.STORAGE_READ_DATA_BYTES; import static com.facebook.presto.common.RuntimeMetricName.STORAGE_READ_TIME_NANOS; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; @@ -288,8 +289,8 @@ private void recordInputStats() operatorContext.recordRawInputWithTiming(inputBytes, positionCount, inputBytesReadTime); RuntimeStats runtimeStats = source.getRuntimeStats(); if (runtimeStats != null) { - runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_TIME_NANOS, inputBytesReadTime); - runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_DATA_BYTES, inputBytes); + runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_TIME_NANOS, NONE, inputBytesReadTime); + runtimeStats.addMetricValueIgnoreZero(STORAGE_READ_DATA_BYTES, NONE, inputBytes); operatorContext.updateStats(runtimeStats); } completedBytes = endCompletedBytes; diff --git a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java index b9436ddc005aa..fc2c150d95138 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java @@ -178,6 +178,7 @@ import static com.facebook.presto.common.RuntimeMetricName.GET_TABLE_METADATA_TIME_NANOS; import static com.facebook.presto.common.RuntimeMetricName.GET_VIEW_TIME_NANOS; import static com.facebook.presto.common.RuntimeMetricName.SKIP_READING_FROM_MATERIALIZED_VIEW_COUNT; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.common.type.BooleanType.BOOLEAN; import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature; @@ -1385,7 +1386,7 @@ private String getMaterializedViewSQL( String materializedViewCreateSql = connectorMaterializedViewDefinition.getOriginalSql(); if (materializedViewStatus.isNotMaterialized() || materializedViewStatus.isTooManyPartitionsMissing()) { - session.getRuntimeStats().addMetricValue(SKIP_READING_FROM_MATERIALIZED_VIEW_COUNT, 1); + session.getRuntimeStats().addMetricValue(SKIP_READING_FROM_MATERIALIZED_VIEW_COUNT, NONE, 1); return materializedViewCreateSql; } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java index fb6e987a814c3..a04a4d45b94b6 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java @@ -94,6 +94,7 @@ import java.util.Set; import static com.facebook.presto.SystemSessionProperties.isPrintStatsForNonJoinQuery; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.common.type.BigintType.BIGINT; import static com.facebook.presto.common.type.VarbinaryType.VARBINARY; import static com.facebook.presto.metadata.MetadataUtil.toSchemaTableName; @@ -118,7 +119,6 @@ import static com.google.common.collect.Streams.zip; import static java.lang.String.format; import static java.util.Objects.requireNonNull; - public class LogicalPlanner { public enum Stage @@ -196,7 +196,7 @@ public Plan plan(Analysis analysis, Stage stage) root = optimizer.optimize(root, session, variableAllocator.getTypes(), variableAllocator, idAllocator, warningCollector); requireNonNull(root, format("%s returned a null plan", optimizer.getClass().getName())); if (enableVerboseRuntimeStats) { - session.getRuntimeStats().addMetricValue(String.format("optimizer%sTimeNanos", optimizer.getClass().getSimpleName()), System.nanoTime() - start); + session.getRuntimeStats().addMetricValue(String.format("optimizer%sTimeNanos", optimizer.getClass().getSimpleName()), NONE, System.nanoTime() - start); } } } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/IterativeOptimizer.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/IterativeOptimizer.java index 273042e2bd49a..101445dd947bb 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/IterativeOptimizer.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/IterativeOptimizer.java @@ -40,6 +40,7 @@ import java.util.Set; import java.util.stream.Stream; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.spi.StandardErrorCode.OPTIMIZER_TIMEOUT; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; @@ -174,7 +175,7 @@ private Rule.Result transform(PlanNode node, Rule rule, Matcher matcher, } stats.record(rule, duration, !result.isEmpty()); if (SystemSessionProperties.isVerboseRuntimeStatsEnabled(context.session)) { - context.session.getRuntimeStats().addMetricValue(String.format("rule%sTimeNanos", rule.getClass().getSimpleName()), duration); + context.session.getRuntimeStats().addMetricValue(String.format("rule%sTimeNanos", rule.getClass().getSimpleName()), NONE, duration); } return result; diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RewriteAggregationIfToFilter.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RewriteAggregationIfToFilter.java index f0d954318c940..f4a4969d2d6e1 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RewriteAggregationIfToFilter.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RewriteAggregationIfToFilter.java @@ -49,6 +49,7 @@ import static com.facebook.presto.SystemSessionProperties.getAggregationIfToFilterRewriteStrategy; import static com.facebook.presto.common.RuntimeMetricName.REWRITE_AGGREGATION_IF_TO_FILTER_APPLIED; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.expressions.LogicalRowExpressions.TRUE_CONSTANT; import static com.facebook.presto.expressions.LogicalRowExpressions.or; import static com.facebook.presto.matching.Capture.newCapture; @@ -127,7 +128,7 @@ public Result apply(AggregationNode aggregationNode, Captures captures, Context return Result.empty(); } - context.getSession().getRuntimeStats().addMetricValue(REWRITE_AGGREGATION_IF_TO_FILTER_APPLIED, 1); + context.getSession().getRuntimeStats().addMetricValue(REWRITE_AGGREGATION_IF_TO_FILTER_APPLIED, NONE, 1); // Get the corresponding assignments in the input project. // The aggregationReferences only has the aggregations to rewrite, thus the sourceAssignments only has IF/CAST(IF) expressions with NULL false results. // Multiple aggregations may reference the same input. We use a map to dedup them based on the VariableReferenceExpression, so that we only do the rewrite once per input diff --git a/presto-main/src/main/java/com/facebook/presto/sql/rewrite/MaterializedViewOptimizationRewriteUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/rewrite/MaterializedViewOptimizationRewriteUtils.java index 1802a6ef01f0f..329c233a9a7e1 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/rewrite/MaterializedViewOptimizationRewriteUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/rewrite/MaterializedViewOptimizationRewriteUtils.java @@ -33,6 +33,7 @@ import static com.facebook.presto.SystemSessionProperties.isMaterializedViewDataConsistencyEnabled; import static com.facebook.presto.common.RuntimeMetricName.MANY_PARTITIONS_MISSING_IN_MATERIALIZED_VIEW_COUNT; import static com.facebook.presto.common.RuntimeMetricName.OPTIMIZED_WITH_MATERIALIZED_VIEW_COUNT; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.sql.ParsingUtil.createParsingOptions; public class MaterializedViewOptimizationRewriteUtils @@ -60,15 +61,15 @@ public static Query optimizeQueryUsingMaterializedView( //TODO: We should be able to leverage this information in the StatementAnalyzer as well. MaterializedViewStatus materializedViewStatus = metadata.getMaterializedViewStatus(session, candidate); if (materializedViewStatus.isFullyMaterialized() || materializedViewStatus.isPartiallyMaterialized()) { - session.getRuntimeStats().addMetricValue(OPTIMIZED_WITH_MATERIALIZED_VIEW_COUNT, 1); + session.getRuntimeStats().addMetricValue(OPTIMIZED_WITH_MATERIALIZED_VIEW_COUNT, NONE, 1); return optimizedQuery; } else { - session.getRuntimeStats().addMetricValue(MANY_PARTITIONS_MISSING_IN_MATERIALIZED_VIEW_COUNT, 1); + session.getRuntimeStats().addMetricValue(MANY_PARTITIONS_MISSING_IN_MATERIALIZED_VIEW_COUNT, NONE, 1); } } else { - session.getRuntimeStats().addMetricValue(OPTIMIZED_WITH_MATERIALIZED_VIEW_COUNT, 1); + session.getRuntimeStats().addMetricValue(OPTIMIZED_WITH_MATERIALIZED_VIEW_COUNT, NONE, 1); return optimizedQuery; } } diff --git a/presto-main/src/test/java/com/facebook/presto/execution/TestQueryStats.java b/presto-main/src/test/java/com/facebook/presto/execution/TestQueryStats.java index 56b721afa2784..7302d2fb21fa5 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/TestQueryStats.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/TestQueryStats.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Optional; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static io.airlift.units.DataSize.Unit.BYTE; import static io.airlift.units.DataSize.succinctBytes; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -41,8 +42,8 @@ public class TestQueryStats { private static final String TEST_METRIC_NAME = "test_metric"; - private static final RuntimeMetric TEST_RUNTIME_METRIC_1 = new RuntimeMetric(TEST_METRIC_NAME, 10, 2, 9, 1); - private static final RuntimeMetric TEST_RUNTIME_METRIC_2 = new RuntimeMetric(TEST_METRIC_NAME, 5, 2, 3, 2); + private static final RuntimeMetric TEST_RUNTIME_METRIC_1 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 10, 2, 9, 1); + private static final RuntimeMetric TEST_RUNTIME_METRIC_2 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 5, 2, 3, 2); private static final List OPERATOR_SUMMARIES = ImmutableList.of( new OperatorStats( @@ -332,6 +333,7 @@ static void assertExpectedQueryStats(QueryStats actual) private static void assertRuntimeMetricEquals(RuntimeMetric m1, RuntimeMetric m2) { assertEquals(m1.getName(), m2.getName()); + assertEquals(m1.getUnit(), m2.getUnit()); assertEquals(m1.getSum(), m2.getSum()); assertEquals(m1.getCount(), m2.getCount()); assertEquals(m1.getMax(), m2.getMax()); diff --git a/presto-main/src/test/java/com/facebook/presto/operator/TestOperatorStats.java b/presto-main/src/test/java/com/facebook/presto/operator/TestOperatorStats.java index 3a187d55beb75..49df1d6fd7823 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/TestOperatorStats.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/TestOperatorStats.java @@ -26,6 +26,7 @@ import java.util.Optional; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static io.airlift.units.DataSize.Unit.BYTE; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.testng.Assert.assertEquals; @@ -36,8 +37,8 @@ public class TestOperatorStats private static final SplitOperatorInfo NON_MERGEABLE_INFO = new SplitOperatorInfo("some_info"); private static final PartitionedOutputInfo MERGEABLE_INFO = new PartitionedOutputInfo(1, 2, 1024); private static final String TEST_METRIC_NAME = "test_metric"; - private static final RuntimeMetric TEST_RUNTIME_METRIC_1 = new RuntimeMetric(TEST_METRIC_NAME, 10, 2, 9, 1); - private static final RuntimeMetric TEST_RUNTIME_METRIC_2 = new RuntimeMetric(TEST_METRIC_NAME, 5, 2, 3, 2); + private static final RuntimeMetric TEST_RUNTIME_METRIC_1 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 10, 2, 9, 1); + private static final RuntimeMetric TEST_RUNTIME_METRIC_2 = new RuntimeMetric(TEST_METRIC_NAME, NONE, 5, 2, 3, 2); public static final OperatorStats EXPECTED = new OperatorStats( 0, diff --git a/presto-orc/src/main/java/com/facebook/presto/orc/CachingStripeMetadataSource.java b/presto-orc/src/main/java/com/facebook/presto/orc/CachingStripeMetadataSource.java index 099d1f584915b..163607a40ae03 100644 --- a/presto-orc/src/main/java/com/facebook/presto/orc/CachingStripeMetadataSource.java +++ b/presto-orc/src/main/java/com/facebook/presto/orc/CachingStripeMetadataSource.java @@ -36,6 +36,7 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; +import static com.facebook.presto.common.RuntimeUnit.NONE; import static com.facebook.presto.orc.metadata.Stream.StreamKind.BLOOM_FILTER; import static com.facebook.presto.orc.metadata.Stream.StreamKind.ROW_INDEX; import static com.google.common.base.Throwables.throwIfInstanceOf; @@ -130,13 +131,13 @@ public List getRowIndexes( if (rowGroupIndexCache.isPresent()) { List rowGroupIndices = rowGroupIndexCache.get().getIfPresent(new StripeStreamId(stripId, streamId)); if (rowGroupIndices != null) { - runtimeStats.addMetricValue("OrcRowGroupIndexCacheHit", 1); - runtimeStats.addMetricValue("OrcRowGroupIndexInMemoryBytesRead", rowGroupIndices.stream().mapToLong(RowGroupIndex::getRetainedSizeInBytes).sum()); + runtimeStats.addMetricValue("OrcRowGroupIndexCacheHit", NONE, 1); + runtimeStats.addMetricValue("OrcRowGroupIndexInMemoryBytesRead", NONE, rowGroupIndices.stream().mapToLong(RowGroupIndex::getRetainedSizeInBytes).sum()); return rowGroupIndices; } else { - runtimeStats.addMetricValue("OrcRowGroupIndexCacheHit", 0); - runtimeStats.addMetricValue("OrcRowGroupIndexStorageBytesRead", inputStream.getRetainedSizeInBytes()); + runtimeStats.addMetricValue("OrcRowGroupIndexCacheHit", NONE, 0); + runtimeStats.addMetricValue("OrcRowGroupIndexStorageBytesRead", NONE, inputStream.getRetainedSizeInBytes()); } } List rowGroupIndices = delegate.getRowIndexes(metadataReader, hiveWriterVersion, stripId, streamId, inputStream, bloomFilters, runtimeStats); diff --git a/presto-orc/src/main/java/com/facebook/presto/orc/metadata/DwrfMetadataReader.java b/presto-orc/src/main/java/com/facebook/presto/orc/metadata/DwrfMetadataReader.java index 93f10c5c54ba3..e8c0a9fc9e240 100644 --- a/presto-orc/src/main/java/com/facebook/presto/orc/metadata/DwrfMetadataReader.java +++ b/presto-orc/src/main/java/com/facebook/presto/orc/metadata/DwrfMetadataReader.java @@ -14,6 +14,7 @@ package com.facebook.presto.orc.metadata; import com.facebook.presto.common.RuntimeStats; +import com.facebook.presto.common.RuntimeUnit; import com.facebook.presto.orc.DwrfDataEncryptor; import com.facebook.presto.orc.DwrfEncryptionProvider; import com.facebook.presto.orc.DwrfKeyProvider; @@ -107,7 +108,7 @@ public PostScript readPostScript(byte[] data, int offset, int length) stripeCacheLength = OptionalInt.of(postScript.getCacheSize()); stripeCacheMode = Optional.of(toStripeCacheMode(postScript.getCacheMode())); } - runtimeStats.addMetricValue("DwrfReadPostScriptTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("DwrfReadPostScriptTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return new PostScript( ImmutableList.of(), @@ -149,7 +150,7 @@ public Footer readFooter(HiveWriterVersion hiveWriterVersion, EncryptionLibrary encryptionLibrary = dwrfEncryptionProvider.getEncryptionLibrary(encryption.get().getKeyProvider()); fileStats = decryptAndCombineFileStatistics(hiveWriterVersion, encryption.get(), encryptionLibrary, fileStats, fileStripes, keys, orcDataSource, decompressor); } - runtimeStats.addMetricValue("DwrfReadFooterTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("DwrfReadFooterTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); OptionalLong rawSize = footer.hasRawDataSize() ? OptionalLong.of(footer.getRawDataSize()) : OptionalLong.empty(); return new Footer( @@ -319,7 +320,7 @@ public StripeFooter readStripeFooter(OrcDataSourceId orcDataSourceId, List readRowIndexes(HiveWriterVersion hiveWriterVersion, I long cpuStart = THREAD_MX_BEAN.getCurrentThreadCpuTime(); CodedInputStream input = CodedInputStream.newInstance(inputStream); DwrfProto.RowIndex rowIndex = DwrfProto.RowIndex.parseFrom(input); - runtimeStats.addMetricValue("DwrfReadRowIndexesTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("DwrfReadRowIndexesTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return IntStream.range(0, rowIndex.getEntryCount()) .mapToObj(i -> toRowGroupIndex(hiveWriterVersion, rowIndex.getEntry(i), bloomFilters == null || bloomFilters.isEmpty() ? null : bloomFilters.get(i))) .collect(toImmutableList()); diff --git a/presto-orc/src/main/java/com/facebook/presto/orc/metadata/OrcMetadataReader.java b/presto-orc/src/main/java/com/facebook/presto/orc/metadata/OrcMetadataReader.java index b731d7e6eeaea..c5c9fa9c0116f 100644 --- a/presto-orc/src/main/java/com/facebook/presto/orc/metadata/OrcMetadataReader.java +++ b/presto-orc/src/main/java/com/facebook/presto/orc/metadata/OrcMetadataReader.java @@ -14,6 +14,7 @@ package com.facebook.presto.orc.metadata; import com.facebook.presto.common.RuntimeStats; +import com.facebook.presto.common.RuntimeUnit; import com.facebook.presto.orc.DwrfEncryptionProvider; import com.facebook.presto.orc.DwrfKeyProvider; import com.facebook.presto.orc.OrcDataSource; @@ -97,7 +98,7 @@ public PostScript readPostScript(byte[] data, int offset, int length) long cpuStart = THREAD_MX_BEAN.getCurrentThreadCpuTime(); CodedInputStream input = CodedInputStream.newInstance(data, offset, length); OrcProto.PostScript postScript = OrcProto.PostScript.parseFrom(input); - runtimeStats.addMetricValue("OrcReadPostScriptTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("OrcReadPostScriptTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return new PostScript( postScript.getVersionList(), @@ -126,7 +127,7 @@ public Metadata readMetadata(HiveWriterVersion hiveWriterVersion, InputStream in CodedInputStream input = CodedInputStream.newInstance(inputStream); input.setSizeLimit(PROTOBUF_MESSAGE_MAX_LIMIT); OrcProto.Metadata metadata = OrcProto.Metadata.parseFrom(input); - runtimeStats.addMetricValue("OrcReadMetadataTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("OrcReadMetadataTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return new Metadata(toStripeStatistics(hiveWriterVersion, metadata.getStripeStatsList())); } @@ -155,7 +156,7 @@ public Footer readFooter(HiveWriterVersion hiveWriterVersion, CodedInputStream input = CodedInputStream.newInstance(inputStream); input.setSizeLimit(PROTOBUF_MESSAGE_MAX_LIMIT); OrcProto.Footer footer = OrcProto.Footer.parseFrom(input); - runtimeStats.addMetricValue("OrcReadFooterTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("OrcReadFooterTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return new Footer( footer.getNumberOfRows(), footer.getRowIndexStride(), @@ -194,7 +195,7 @@ public StripeFooter readStripeFooter(OrcDataSourceId orcDataSourceId, List readRowIndexes(HiveWriterVersion hiveWriterVersion, I long cpuStart = THREAD_MX_BEAN.getCurrentThreadCpuTime(); CodedInputStream input = CodedInputStream.newInstance(inputStream); OrcProto.RowIndex rowIndex = OrcProto.RowIndex.parseFrom(input); - runtimeStats.addMetricValue("OrcReadRowIndexesTimeNanos", THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); + runtimeStats.addMetricValue("OrcReadRowIndexesTimeNanos", RuntimeUnit.NONE, THREAD_MX_BEAN.getCurrentThreadCpuTime() - cpuStart); return IntStream.range(0, rowIndex.getEntryCount()) .mapToObj(i -> toRowGroupIndex(hiveWriterVersion, rowIndex.getEntry(i), bloomFilters == null || bloomFilters.isEmpty() ? null : bloomFilters.get(i))) .collect(toImmutableList());