#2290 - Add MetaTimedMetric locationHash() which is a crc32 checksum of package + type + method (excludes line number)

This commit is contained in:
rbygrave
2021-08-06 14:48:42 +12:00
parent 4787303160
commit fea7de42d5
19 changed files with 124 additions and 43 deletions
@@ -134,6 +134,7 @@ class DumpMetrics {
String location = metric.location();
if (dumpLoc && location != null) {
sb.append("\n loc:").append(location);
sb.append("\n locHash:").append(metric.locationHash());
}
if (dumpSql) {
sb.append(" \n\n sql:").append(metric.sql()).append("\n\n");
@@ -56,6 +56,7 @@ class DumpMetricsData {
final MetricData data = create(metric);
appendCounters(data, metric);
data.setLoc(metric.location());
data.setLocHash(metric.locationHash());
}
private void addCount(MetaCountMetric metric) {
@@ -71,6 +72,7 @@ class DumpMetricsData {
}
private void appendLocationAndSql(MetricData data, MetaQueryMetric metric) {
data.setLocHash(metric.locationHash());
data.setLoc(metric.location());
data.setSql(metric.sql());
}
@@ -188,6 +188,7 @@ class DumpMetricsJson implements ServerMetricsAsJson {
metricStart(metric);
appendTiming(metric);
if (isIncludeDetail(metric)) {
keyVal("locHash", metric.locationHash());
appendExtra("loc", metric.location());
}
metricEnd();
@@ -198,6 +199,7 @@ class DumpMetricsJson implements ServerMetricsAsJson {
appendTiming(metric);
if (withHash) {
keyVal("sqlHash", metric.sqlHash());
keyVal("locHash", metric.locationHash());
}
if (isIncludeDetail(metric)) {
appendExtra("loc", metric.location());
@@ -10,9 +10,11 @@ final class BasicProfileLocation implements ProfileLocation {
private final String fullLocation;
private final String location;
private final String label;
private final long hash;
BasicProfileLocation(String fullLocation) {
this.fullLocation = fullLocation;
this.hash = UtilLocation.hash(fullLocation);
this.location = shortDesc(fullLocation);
this.label = UtilLocation.label(location);
}
@@ -42,6 +44,11 @@ final class BasicProfileLocation implements ProfileLocation {
return location;
}
@Override
public long hash() {
return hash;
}
@Override
public String fullLocation() {
return fullLocation;
@@ -8,17 +8,14 @@ import io.ebean.ProfileLocation;
class DProfileLocation implements ProfileLocation {
private static final String IO_EBEAN = "io.ebean";
private static final String UNKNOWN = "unknown";
private String fullLocation;
private String location;
private String label;
private long hash;
private final int lineNumber;
private int traceCount;
DProfileLocation() {
@@ -53,6 +50,7 @@ class DProfileLocation implements ProfileLocation {
label = UtilLocation.label(shortDesc);
location = shortDesc;
fullLocation = loc;
hash = UtilLocation.hash(loc);
initWith(label);
return true;
}
@@ -71,6 +69,11 @@ class DProfileLocation implements ProfileLocation {
return location;
}
@Override
public long hash() {
return hash;
}
@Override
public String fullLocation() {
return fullLocation;
@@ -49,6 +49,10 @@ class DQueryPlanMeta {
return (profileLocation == null) ? null : profileLocation.location();
}
public long getLocationHash() {
return (profileLocation == null) ? 0 : profileLocation.hash();
}
public String getSql() {
return sql;
}
@@ -83,6 +83,11 @@ class DQueryPlanMetric implements QueryPlanMetric {
return meta.getLocation();
}
@Override
public long locationHash() {
return meta.getLocationHash();
}
@Override
public long count() {
return stats.count();
@@ -7,18 +7,15 @@ import io.ebean.metric.TimedMetricStats;
*/
class DTimeMetricStats implements TimedMetricStats {
private String name;
private final boolean collected;
private String location;
private final long count;
private final long total;
private final long max;
private String name;
private String location;
private long locationHash;
DTimeMetricStats(String name, boolean collected, long count, long total, long max) {
this.name = name;
this.collected = collected;
@@ -40,6 +37,7 @@ class DTimeMetricStats implements TimedMetricStats {
.append(" max:").append(max);
if (location != null) {
sb.append(" loc:").append(location);
sb.append(" locHash:").append(locationHash);
}
return sb.toString();
}
@@ -49,6 +47,11 @@ class DTimeMetricStats implements TimedMetricStats {
this.location = location;
}
@Override
public void setLocationHash(long locationHash) {
this.locationHash = locationHash;
}
@Override
public boolean initialCollection() {
return !collected;
@@ -69,6 +72,11 @@ class DTimeMetricStats implements TimedMetricStats {
return location;
}
@Override
public long locationHash() {
return locationHash;
}
/**
* Return the count of values collected.
*/
@@ -1,7 +1,21 @@
package io.ebeaninternal.server.profile;
import io.ebeaninternal.server.util.Checksum;
final class UtilLocation {
/**
* Return a hash of the full description excluding the source line number.
*/
static long hash(String full) {
final int pos = full.lastIndexOf('(');
if (pos > -1) {
return Checksum.checksum(full.substring(0, pos));
} else {
return Checksum.checksum(full);
}
}
static String label(String shortDescription) {
int pos = shortDescription.indexOf("(");
if (pos == -1) {
@@ -21,5 +35,4 @@ final class UtilLocation {
}
return desc;
}
}
@@ -54,46 +54,32 @@ public class CQueryPlan implements SpiQueryPlan {
static final String RESULT_SET_BASED_RAW_SQL = "--ResultSetBasedRawSql";
private final SpiEbeanServer server;
private final ProfileLocation profileLocation;
private final String location;
private final long locationHash;
private final String label;
private final String name;
private final CQueryPlanKey planKey;
private final boolean rawSql;
private final String sql;
private final long sqlHash;
private final String logWhereSql;
private final SqlTree sqlTree;
/**
* Encrypted properties required additional binding.
*/
private final STreeProperty[] encryptedProps;
private final CQueryPlanStats stats;
private final Class<?> beanType;
final DataTimeZone dataTimeZone;
private final int asOfTableCount;
/**
* Key used to identify the query plan in audit logging.
*/
private volatile String auditQueryHash;
private final Set<String> dependentTables;
private final SpiQueryBindCapture bindCapture;
/**
@@ -106,9 +92,10 @@ public class CQueryPlan implements SpiQueryPlan {
this.planKey = request.getQueryPlanKey();
SpiQuery<?> query = request.getQuery();
this.profileLocation = query.getProfileLocation();
this.location = (profileLocation == null) ? null : profileLocation.location();
this.locationHash = (profileLocation == null) ? 0 : profileLocation.hash();
this.label = query.getPlanLabel();
this.name = deriveName(label, query.getType(), request.getBeanDescriptor().getSimpleName());
this.location = location();
this.asOfTableCount = query.getAsOfTableCount();
this.sql = sqlRes.getSql();
this.sqlTree = sqlTree;
@@ -130,9 +117,10 @@ public class CQueryPlan implements SpiQueryPlan {
this.beanType = request.getBeanDescriptor().getBeanType();
SpiQuery<?> query = request.getQuery();
this.profileLocation = query.getProfileLocation();
this.location = (profileLocation == null) ? null : profileLocation.location();
this.locationHash = (profileLocation == null) ? 0 : profileLocation.hash();
this.label = query.getPlanLabel();
this.name = deriveName(label, query.getType(), request.getBeanDescriptor().getSimpleName());
this.location = location();
this.planKey = buildPlanKey(sql, logWhereSql);
this.asOfTableCount = 0;
this.sql = sql;
@@ -169,10 +157,6 @@ public class CQueryPlan implements SpiQueryPlan {
return sql.equals(RESULT_SET_BASED_RAW_SQL) || query.getType().isUpdate() ? SpiQueryBindCapture.NOOP : server.createQueryBindCapture(this);
}
private String location() {
return (profileLocation == null) ? null : profileLocation.location();
}
private CQueryPlanKey buildPlanKey(String sql, String logWhereSql) {
return new RawSqlQueryPlanKey(sql, false, logWhereSql);
}
@@ -219,6 +203,10 @@ public class CQueryPlan implements SpiQueryPlan {
return location;
}
public long getLocationHash() {
return locationHash;
}
@Override
public void queryPlanInit(long thresholdMicros) {
bindCapture.queryPlanInit(thresholdMicros);
@@ -106,6 +106,11 @@ public final class CQueryPlanStats {
return queryPlan.getLocation();
}
@Override
public long locationHash() {
return queryPlan.getLocationHash();
}
@Override
public long count() {
return metrics.count();