diff --git a/src/main/java/io/ebean/meta/MetaCountMetric.java b/src/main/java/io/ebean/meta/MetaCountMetric.java index ea3c833b0..8b6af3594 100644 --- a/src/main/java/io/ebean/meta/MetaCountMetric.java +++ b/src/main/java/io/ebean/meta/MetaCountMetric.java @@ -1,19 +1,9 @@ package io.ebean.meta; /** - * Count metrics. + * Count metrics. For example L2 cache hits. */ -public interface MetaCountMetric { - - /** - * Return the metric type. - */ - MetricType getMetricType(); - - /** - * Return the metric name. - */ - String getName(); +public interface MetaCountMetric extends MetaMetric { /** * Return the total count. diff --git a/src/main/java/io/ebean/meta/MetaMetric.java b/src/main/java/io/ebean/meta/MetaMetric.java new file mode 100644 index 000000000..c6ab21c59 --- /dev/null +++ b/src/main/java/io/ebean/meta/MetaMetric.java @@ -0,0 +1,18 @@ +package io.ebean.meta; + +/** + * Metrics collected by Ebean including timed metrics and counters. + */ +public interface MetaMetric { + + /** + * Return the metric type. + */ + MetricType getMetricType(); + + /** + * Return the metric name. + */ + String getName(); + +} diff --git a/src/main/java/io/ebean/meta/MetaQueryMetric.java b/src/main/java/io/ebean/meta/MetaQueryMetric.java index 6816128db..c59142dc6 100644 --- a/src/main/java/io/ebean/meta/MetaQueryMetric.java +++ b/src/main/java/io/ebean/meta/MetaQueryMetric.java @@ -1,7 +1,5 @@ package io.ebean.meta; -import io.ebean.ProfileLocation; - /** * Query execution metrics. */ @@ -17,11 +15,6 @@ public interface MetaQueryMetric extends MetaTimedMetric { */ String getLabel(); - /** - * Return the profile location. - */ - ProfileLocation getProfileLocation(); - /** * The actual SQL of the query. */ diff --git a/src/main/java/io/ebean/meta/MetaTimedMetric.java b/src/main/java/io/ebean/meta/MetaTimedMetric.java index 53f67109d..eebdb69d2 100644 --- a/src/main/java/io/ebean/meta/MetaTimedMetric.java +++ b/src/main/java/io/ebean/meta/MetaTimedMetric.java @@ -4,17 +4,7 @@ package io.ebean.meta; /** * Timed execution statistics. */ -public interface MetaTimedMetric { - - /** - * Return the metric type. - */ - MetricType getMetricType(); - - /** - * Return the metric name. - */ - String getName(); +public interface MetaTimedMetric extends MetaMetric { /** * Return the metric location if defined. diff --git a/src/main/java/io/ebeaninternal/server/core/DumpMetrics.java b/src/main/java/io/ebeaninternal/server/core/DumpMetrics.java index 54bdf8956..b035e20f5 100644 --- a/src/main/java/io/ebeaninternal/server/core/DumpMetrics.java +++ b/src/main/java/io/ebeaninternal/server/core/DumpMetrics.java @@ -153,18 +153,16 @@ class DumpMetrics { } private void appendProfileAndSql(MetaQueryMetric metric, StringBuilder sb) { - ProfileLocation profileLocation = metric.getProfileLocation(); - if (dumpLoc && profileLocation != null) { - sb.append("\n loc:").append(profileLocation.shortDescription()); + String location = metric.getLocation(); + if (dumpLoc && location != null) { + sb.append("\n loc:").append(location); } - if (dumpSql) { sb.append(" \n\n sql:").append(metric.getSql()).append("\n\n"); } } private void log(MetaTimedMetric metric) { - StringBuilder sb = new StringBuilder(); sb.append(padNameTimed(metric.getName())).append(" "); appendCounters(metric, sb); diff --git a/src/main/java/io/ebeaninternal/server/core/DumpMetricsJson.java b/src/main/java/io/ebeaninternal/server/core/DumpMetricsJson.java index 11c01149a..90bad3c95 100644 --- a/src/main/java/io/ebeaninternal/server/core/DumpMetricsJson.java +++ b/src/main/java/io/ebeaninternal/server/core/DumpMetricsJson.java @@ -1,8 +1,8 @@ package io.ebeaninternal.server.core; import io.ebean.Database; -import io.ebean.ProfileLocation; import io.ebean.meta.MetaCountMetric; +import io.ebean.meta.MetaMetric; import io.ebean.meta.MetaOrmQueryMetric; import io.ebean.meta.MetaQueryMetric; import io.ebean.meta.MetaTimedMetric; @@ -20,36 +20,35 @@ class DumpMetricsJson implements ServerMetricsAsJson { private final StringWriter writer = new StringWriter(); - private boolean dumpHash = true; - private boolean dumpSql = true; - private boolean dumpLoc = true; + private boolean withHash = true; + private boolean withSql = true; + private boolean withLocation = true; + private String newLine = "\n"; private Comparator sortBy = SortMetric.NAME; private int listCounter; private int objKeyCounter; - private String newLine = "\n"; - DumpMetricsJson(Database database) { this.database = database; } @Override public ServerMetricsAsJson withLocation(boolean withLocation) { - this.dumpLoc = withLocation; + this.withLocation = withLocation; return this; } @Override public ServerMetricsAsJson withSql(boolean withSql) { - this.dumpSql = withSql; + this.withSql = withSql; return this; } @Override public ServerMetricsAsJson withHash(boolean withHash) { - this.dumpHash = withHash; + this.withHash = withHash; return this; } @@ -71,7 +70,6 @@ class DumpMetricsJson implements ServerMetricsAsJson { return writer.toString(); } - private void collect(ServerMetrics serverMetrics) { start(); @@ -158,67 +156,72 @@ class DumpMetricsJson implements ServerMetricsAsJson { writer.append("\"").append(val).append("\""); } - private void log(MetaTimedMetric metric) { - - metricStart(); - key("name"); - val(metric.getName()); - appendCounters(metric); - objEnd(); - } - - private void metricStart() { + private void metricStart(MetaMetric metric) { if (listCounter++ > 0) { writer.append(",").append(newLine); } objStart(); + key("name"); + val(metric.getName()); + key("type"); + val(metric.getMetricType().name()); + } + + private void metricEnd() { + objEnd(); + } + + private void log(MetaTimedMetric metric) { + metricStart(metric); + appendCounters(metric); + if (withLocation) { + appendLocation(metric.getLocation()); + } + metricEnd(); } private void logCount(MetaCountMetric metric) { - metricStart(); - key("name"); - val(metric.getName()); + metricStart(metric); key("count"); val(metric.getCount()); - objEnd(); + metricEnd(); } private void logQuery(MetaOrmQueryMetric metric) { - - metricStart(); - key("name"); - val(metric.getName()); + metricStart(metric); appendCounters(metric); - if (dumpHash) { + if (withHash) { key("hash"); val(metric.getSqlHash()); } - appendProfileAndSql(metric); - objEnd(); + appendLocationAndSql(metric); + metricEnd(); } private void logDtoQuery(MetaQueryMetric metric) { - - metricStart(); - key("name"); - val(metric.getName()); + metricStart(metric); appendCounters(metric); - appendProfileAndSql(metric); - objEnd(); + appendLocationAndSql(metric); + metricEnd(); } - private void appendProfileAndSql(MetaQueryMetric metric) { - ProfileLocation profileLocation = metric.getProfileLocation(); - if (dumpLoc && profileLocation != null) { - key("loc"); - val(profileLocation.shortDescription()); + private void appendLocationAndSql(MetaQueryMetric metric) { + if (withLocation) { + appendLocation(metric.getLocation()); } - if (dumpSql) { + if (withSql) { key("sql"); val(metric.getSql()); } } + private void appendLocation(String location) { + if (location != null) { + key("loc"); + val(location); + } + } + private void appendCounters(MetaTimedMetric timedMetric) { key("count"); val(timedMetric.getCount()); diff --git a/src/main/java/io/ebeaninternal/server/profile/DQueryPlanMetric.java b/src/main/java/io/ebeaninternal/server/profile/DQueryPlanMetric.java index e5dbde4b6..0adbd10cb 100644 --- a/src/main/java/io/ebeaninternal/server/profile/DQueryPlanMetric.java +++ b/src/main/java/io/ebeaninternal/server/profile/DQueryPlanMetric.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.profile; -import io.ebean.ProfileLocation; import io.ebean.meta.MetaQueryMetric; import io.ebean.meta.MetricType; import io.ebean.meta.MetricVisitor; @@ -61,11 +60,6 @@ class DQueryPlanMetric implements QueryPlanMetric { return meta.getLabel(); } - @Override - public ProfileLocation getProfileLocation() { - return meta.getProfileLocation(); - } - @Override public String getSql() { return meta.getSql(); diff --git a/src/main/java/io/ebeaninternal/server/query/CQueryPlanStats.java b/src/main/java/io/ebeaninternal/server/query/CQueryPlanStats.java index 54a8defbc..8bf9b06fc 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQueryPlanStats.java +++ b/src/main/java/io/ebeaninternal/server/query/CQueryPlanStats.java @@ -192,11 +192,6 @@ public final class CQueryPlanStats { return queryPlan.getLocation(); } - @Override - public ProfileLocation getProfileLocation() { - return queryPlan.getProfileLocation(); - } - @Override public long getBeanCount() { return metrics.getBeanCount(); diff --git a/src/test/java/io/ebean/DtoQueryFromOrmTest.java b/src/test/java/io/ebean/DtoQueryFromOrmTest.java index 7b26a3181..6054aa13b 100644 --- a/src/test/java/io/ebean/DtoQueryFromOrmTest.java +++ b/src/test/java/io/ebean/DtoQueryFromOrmTest.java @@ -63,7 +63,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase { for (MetaQueryMetric stat : stats) { long meanMicros = stat.getMean(); assertThat(meanMicros).isLessThan(900_000); - assertThat(stat.getProfileLocation()).isSameAs(loc0); + assertThat(stat.getLocation()).isSameAs(loc0.shortDescription()); } assertThat(stats).hasSize(1); diff --git a/src/test/java/org/tests/query/finder/TestCustomerFinder.java b/src/test/java/org/tests/query/finder/TestCustomerFinder.java index 7ab664a09..4aa9fcc3b 100644 --- a/src/test/java/org/tests/query/finder/TestCustomerFinder.java +++ b/src/test/java/org/tests/query/finder/TestCustomerFinder.java @@ -179,7 +179,7 @@ public class TestCustomerFinder extends BaseTestCase { .json(); System.out.println(metricsJson); - assertThat(metricsJson).contains("\"name\":\"txn.main\""); + assertThat(metricsJson).contains("\"name\":\"txn.main\", \"type\":\"TXN\""); assertThat(metricsJson).contains("\"name\":\"Customer.findList\""); assertThat(metricsJson).contains("\"loc\":\"CustomerFinder.byNameStatus(CustomerFinder.java:44)\""); assertThat(metricsJson).contains("\"hash\":\"4d648ce0542aedfb042ad68746342730\"");