mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1858 - Modify JSON dumped metrics to include metric type and location for timed metrics
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<MetaTimedMetric> 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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user