mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1854 - Use profile location label to automatically give good metric name for @Transactional (with profile location enhancement)
This commit is contained in:
@@ -11,4 +11,9 @@ public interface TimedMetricStats extends MetaTimedMetric {
|
||||
* Additionally set the location.
|
||||
*/
|
||||
void setLocation(String location);
|
||||
|
||||
/**
|
||||
* Override the name based on profile location.
|
||||
*/
|
||||
void setName(String name);
|
||||
}
|
||||
|
||||
@@ -49,10 +49,15 @@ class DProfileLocation implements ProfileLocation {
|
||||
label = UtilLocation.label(shortDesc);
|
||||
shortDescription = shortDesc;
|
||||
location = loc;
|
||||
initWith(label);
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
protected void initWith(String label) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return label;
|
||||
|
||||
@@ -38,6 +38,10 @@ class DQueryPlanMeta {
|
||||
return profileLocation;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return (profileLocation == null) ? null : profileLocation.shortDescription();
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class DQueryPlanMetric implements QueryPlanMetric {
|
||||
|
||||
@Override
|
||||
public String getLocation() {
|
||||
return stats.getLocation();
|
||||
return meta.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ class DTimeMetricStats implements TimedMetricStats {
|
||||
|
||||
private final MetricType metricType;
|
||||
|
||||
private final String name;
|
||||
private String name;
|
||||
|
||||
private String location;
|
||||
|
||||
@@ -39,9 +39,6 @@ class DTimeMetricStats implements TimedMetricStats {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (location != null) {
|
||||
sb.append("loc:").append(location).append(" ");
|
||||
}
|
||||
if (name != null) {
|
||||
sb.append("name:").append(name).append(" ");
|
||||
}
|
||||
@@ -49,6 +46,9 @@ class DTimeMetricStats implements TimedMetricStats {
|
||||
.append(" total:").append(total)
|
||||
.append(" max:").append(max)
|
||||
.append(" beanCount:").append(beanCount);
|
||||
if (location != null) {
|
||||
sb.append(" loc:").append(location);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ class DTimeMetricStats implements TimedMetricStats {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricType getMetricType() {
|
||||
return metricType;
|
||||
|
||||
@@ -13,10 +13,22 @@ class DTimedProfileLocation extends DProfileLocation implements TimedProfileLoca
|
||||
|
||||
private final TimedMetric timedMetric;
|
||||
|
||||
private final boolean overrideMetricName;
|
||||
|
||||
private String fullName;
|
||||
|
||||
DTimedProfileLocation(int lineNumber, String label, TimedMetric timedMetric) {
|
||||
super(lineNumber);
|
||||
this.label = label;
|
||||
this.timedMetric = timedMetric;
|
||||
this.overrideMetricName = "".equals(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initWith(String locationLabel) {
|
||||
if (overrideMetricName) {
|
||||
fullName = "txn.named." + locationLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +50,10 @@ class DTimedProfileLocation extends DProfileLocation implements TimedProfileLoca
|
||||
public void visit(MetricVisitor visitor) {
|
||||
TimedMetricStats collect = timedMetric.collect(visitor.isReset());
|
||||
if (collect != null) {
|
||||
collect.setLocation(obtain());
|
||||
if (overrideMetricName) {
|
||||
collect.setName(fullName);
|
||||
}
|
||||
collect.setLocation(shortDescription());
|
||||
visitor.visitTimed(collect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public class CQueryPlan {
|
||||
}
|
||||
|
||||
private String location() {
|
||||
return (profileLocation == null) ? "" : profileLocation.shortDescription();
|
||||
return (profileLocation == null) ? null : profileLocation.shortDescription();
|
||||
}
|
||||
|
||||
private CQueryPlanKey buildPlanKey(String sql, boolean rowNumberIncluded, String logWhereSql) {
|
||||
|
||||
Reference in New Issue
Block a user