mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-23 23:13:55 +00:00
Merge pull request #2983 from ebean-orm/feature/profileLocationWithLineNumbers
ENH: Add profile-line-number-mode with options none | all | auto ... to control adding line numbers to profile locations
This commit is contained in:
19 files changed
+115
-53
No files matched your search
@@ -17,15 +17,32 @@ public interface ProfileLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and return a new ProfileLocation with a given lineNumber and label.
|
* Create and return a new ProfileLocation with line number.
|
||||||
*/
|
*/
|
||||||
static ProfileLocation create(int lineNumber, String label) {
|
static ProfileLocation createWithLine() {
|
||||||
return XServiceProvider.profileLocationFactory().create(lineNumber, label);
|
return XServiceProvider.profileLocationFactory().createWithLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create and return a new ProfileLocation with a given lineNumber and label.
|
||||||
|
*/
|
||||||
|
static ProfileLocation create(String label) {
|
||||||
|
return XServiceProvider.profileLocationFactory().create(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated in favor of {@link #create(String)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
static ProfileLocation create(int lineNumber, String label) {
|
||||||
|
return create(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated for removal - not used.
|
||||||
* Create and return a new ProfileLocation with a given location.
|
* Create and return a new ProfileLocation with a given location.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
static ProfileLocation createAt(String location) {
|
static ProfileLocation createAt(String location) {
|
||||||
return XServiceProvider.profileLocationFactory().createAt(location);
|
return XServiceProvider.profileLocationFactory().createAt(location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,16 @@ public interface SpiProfileLocationFactory {
|
|||||||
ProfileLocation create();
|
ProfileLocation create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a profile location with a line number.
|
* Create a profile location with line numbering.
|
||||||
*/
|
*/
|
||||||
ProfileLocation create(int lineNumber, String label);
|
ProfileLocation createWithLine();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create with a given label - used only with {@code @Transaction}.
|
||||||
|
*
|
||||||
|
* @param label the label for the transaction
|
||||||
|
*/
|
||||||
|
ProfileLocation create(String label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a known location.
|
* Create a known location.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
ebean-version: 142
|
ebean-version: 143
|
||||||
@@ -12,21 +12,14 @@ class DProfileLocation implements ProfileLocation {
|
|||||||
|
|
||||||
private static final String UNKNOWN = "unknown";
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
|
private final boolean withLine;
|
||||||
private String fullLocation;
|
private String fullLocation;
|
||||||
private String location;
|
private String location;
|
||||||
private String label;
|
private String label;
|
||||||
private final int lineNumber;
|
|
||||||
private int traceCount;
|
private int traceCount;
|
||||||
|
|
||||||
DProfileLocation() {
|
DProfileLocation(boolean withLine) {
|
||||||
this(0);
|
this.withLine = withLine;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create with a given line number.
|
|
||||||
*/
|
|
||||||
DProfileLocation(int lineNumber) {
|
|
||||||
this.lineNumber = lineNumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,7 +39,7 @@ class DProfileLocation implements ProfileLocation {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String loc = create();
|
final String loc = create();
|
||||||
final String location = UtilLocation.loc(loc);
|
final String location = UtilLocation.loc(loc, withLine);
|
||||||
this.label = UtilLocation.label(location);
|
this.label = UtilLocation.label(location);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.fullLocation = loc;
|
this.fullLocation = loc;
|
||||||
@@ -96,19 +89,8 @@ class DProfileLocation implements ProfileLocation {
|
|||||||
private String filter(Stream<StackWalker.StackFrame> frames) {
|
private String filter(Stream<StackWalker.StackFrame> frames) {
|
||||||
return frames.filter(StackWalkFilter.filter())
|
return frames.filter(StackWalkFilter.filter())
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(line -> withLineNumber(line.toString()))
|
.map(Object::toString)
|
||||||
.orElse(UNKNOWN);
|
.orElse(UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String withLineNumber(String traceLine) {
|
|
||||||
if (lineNumber == 0) {
|
|
||||||
return traceLine;
|
|
||||||
} else if (traceLine.endsWith(":1)")) {
|
|
||||||
return traceLine.substring(0, traceLine.length() - 3) + ":" + lineNumber + ")";
|
|
||||||
} else if (traceLine.contains(":")) {
|
|
||||||
return traceLine;
|
|
||||||
} else {
|
|
||||||
return traceLine.substring(0, traceLine.length() - 1) + ":" + lineNumber + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+8
-6
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.profile;
|
|||||||
|
|
||||||
import io.ebean.ProfileLocation;
|
import io.ebean.ProfileLocation;
|
||||||
import io.ebean.metric.MetricFactory;
|
import io.ebean.metric.MetricFactory;
|
||||||
import io.ebean.metric.TimedMetric;
|
|
||||||
import io.ebean.service.SpiProfileLocationFactory;
|
import io.ebean.service.SpiProfileLocationFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,15 +11,18 @@ public final class DProfileLocationFactory implements SpiProfileLocationFactory
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProfileLocation create() {
|
public ProfileLocation create() {
|
||||||
return new DProfileLocation();
|
return new DProfileLocation(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProfileLocation create(int lineNumber, String label) {
|
public ProfileLocation createWithLine() {
|
||||||
|
return new DProfileLocation(true);
|
||||||
|
}
|
||||||
|
|
||||||
TimedMetric timedMetric = MetricFactory.get().createTimedMetric("txn.named." + label);
|
@Override
|
||||||
|
public ProfileLocation create(String label) {
|
||||||
DTimedProfileLocation loc = new DTimedProfileLocation(lineNumber, label, timedMetric);
|
final var timedMetric = MetricFactory.get().createTimedMetric("txn.named." + label);
|
||||||
|
final var loc = new DTimedProfileLocation(label, timedMetric);
|
||||||
TimedProfileLocationRegistry.register(loc);
|
TimedProfileLocationRegistry.register(loc);
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ final class DTimedProfileLocation extends DProfileLocation implements TimedProfi
|
|||||||
private String fullName;
|
private String fullName;
|
||||||
private String reportName;
|
private String reportName;
|
||||||
|
|
||||||
DTimedProfileLocation(int lineNumber, String label, TimedMetric timedMetric) {
|
DTimedProfileLocation(String label, TimedMetric timedMetric) {
|
||||||
super(lineNumber);
|
super(false);
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.timedMetric = timedMetric;
|
this.timedMetric = timedMetric;
|
||||||
this.overrideMetricName = "".equals(label);
|
this.overrideMetricName = "".equals(label);
|
||||||
|
|||||||
@@ -3,14 +3,23 @@ package io.ebeaninternal.server.profile;
|
|||||||
final class UtilLocation {
|
final class UtilLocation {
|
||||||
|
|
||||||
static String loc(String full) {
|
static String loc(String full) {
|
||||||
|
return loc(full, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String loc(String full, boolean includeLineNumber) {
|
||||||
final int pos = full.lastIndexOf('(');
|
final int pos = full.lastIndexOf('(');
|
||||||
if (pos > -1) {
|
if (pos > -1) {
|
||||||
return full.substring(0, pos);
|
return !includeLineNumber ? full.substring(0, pos) : full.substring(0, pos) + lineNumberFrom(full);
|
||||||
} else {
|
} else {
|
||||||
return full;
|
return full;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String lineNumberFrom(String full) {
|
||||||
|
int pos = full.lastIndexOf(':');
|
||||||
|
return pos == -1 ? "" : full.substring(pos, full.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
static String label(String location) {
|
static String label(String location) {
|
||||||
return trimInit(shortDesc(location));
|
return trimInit(shortDesc(location));
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@ class BasicProfileLocationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void metricNameFromOverride() {
|
void metricNameFromOverride() {
|
||||||
DTimedProfileLocation loc = new DTimedProfileLocation(12, "", MetricFactory.get().createTimedMetric("a.b.c"));
|
DTimedProfileLocation loc = new DTimedProfileLocation("", MetricFactory.get().createTimedMetric("a.b.c"));
|
||||||
loc.initWith("foo.label");
|
loc.initWith("foo.label");
|
||||||
loc.add(42);
|
loc.add(42);
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class BasicProfileLocationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void metricNameFromTimed() {
|
void metricNameFromTimed() {
|
||||||
DTimedProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("a.b.c"));
|
DTimedProfileLocation loc = new DTimedProfileLocation("foo", MetricFactory.get().createTimedMetric("a.b.c"));
|
||||||
loc.add(42);
|
loc.add(42);
|
||||||
|
|
||||||
BasicMetricVisitor visitor = new BasicMetricVisitor("v", naming);
|
BasicMetricVisitor visitor = new BasicMetricVisitor("v", naming);
|
||||||
@@ -52,7 +52,7 @@ class BasicProfileLocationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void obtain() {
|
void obtain() {
|
||||||
DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("junk"));
|
DProfileLocation loc = new DTimedProfileLocation("foo", MetricFactory.get().createTimedMetric("junk"));
|
||||||
|
|
||||||
assertThat(loc.obtain()).isTrue();
|
assertThat(loc.obtain()).isTrue();
|
||||||
assertThat(loc.fullLocation()).endsWith("org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)");
|
assertThat(loc.fullLocation()).endsWith("org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)");
|
||||||
|
|||||||
@@ -5,17 +5,23 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class UtilLocationTest {
|
class UtilLocationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void label() {
|
void label() {
|
||||||
Assertions.assertThat(UtilLocation.label("foo")).isEqualTo("foo");
|
Assertions.assertThat(UtilLocation.label("foo")).isEqualTo("foo");
|
||||||
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
|
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loc() {
|
void loc() {
|
||||||
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo("org.foo.MyFoo.doIt");
|
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo("org.foo.MyFoo.doIt");
|
||||||
assertThat(UtilLocation.label("org.foo.MyFoo.doIt")).isEqualTo("MyFoo.doIt");
|
assertThat(UtilLocation.label("org.foo.MyFoo.doIt")).isEqualTo("MyFoo.doIt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void locWithLineNumber() {
|
||||||
|
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)", true)).isEqualTo("org.foo.MyFoo.doIt:12");
|
||||||
|
assertThat(UtilLocation.label("org.foo.MyFoo.doIt:12")).isEqualTo("MyFoo.doIt:12");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
ebean-version: 142
|
ebean-version: 143
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<tiles>
|
<tiles>
|
||||||
<tile>io.ebean.tile:enhancement:13.12.0</tile>
|
<tile>io.ebean.tile:enhancement:13.13.1</tile>
|
||||||
</tiles>
|
</tiles>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -9,9 +9,21 @@ public class QContactTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_oneToManyMap() {
|
public void test_oneToManyMap() {
|
||||||
|
findThem();
|
||||||
|
findThem(ZonedDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
void findThem() {
|
||||||
new QContact()
|
new QContact()
|
||||||
.others.fetch()
|
.others.fetch()
|
||||||
.zoneDateTime.before(ZonedDateTime.now())
|
.zoneDateTime.before(ZonedDateTime.now())
|
||||||
.findList();
|
.findList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void findThem(ZonedDateTime dateTime) {
|
||||||
|
new QContact()
|
||||||
|
.others.fetch()
|
||||||
|
.zoneDateTime.before(dateTime)
|
||||||
|
.findList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -368,6 +368,17 @@ public class QCustomerTest {
|
|||||||
.findList();
|
.findList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTwoDiffQueryTypes_expect_NoLineNumbers() {
|
||||||
|
new QCustomer()
|
||||||
|
.id.isIn(34L)
|
||||||
|
.findList();
|
||||||
|
|
||||||
|
new QContact()
|
||||||
|
.email.isNull()
|
||||||
|
.findList();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryBoolean() {
|
public void testQueryBoolean() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
ebean.ddl.generate=true
|
ebean.ddl.generate=true
|
||||||
ebean.ddl.run=true
|
ebean.ddl.run=true
|
||||||
ebean.ddl.initSql=init-db.sql
|
ebean.ddl.initSql=init-db.sql
|
||||||
|
ebean.dumpMetricsOnShutdown=true
|
||||||
|
ebean.dumpMetricsOptions=sql,hash,loc
|
||||||
|
|
||||||
datasource.default=h2
|
datasource.default=h2
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
entity-packages: org.example.domain
|
entity-packages: org.example.domain
|
||||||
querybean-packages: org.example.domain,org.querytest
|
querybean-packages: org.example.domain,org.querytest
|
||||||
debug: 0
|
debug: 0
|
||||||
synthetic: false
|
synthetic: true
|
||||||
entity-field-access: true
|
entity-field-access: true
|
||||||
|
profile-line-number-mode: auto
|
||||||
|
|
||||||
@@ -10,10 +10,12 @@ class ProfileLocationTest {
|
|||||||
private static final ProfileLocation loc = ProfileLocation.create(12, "foo");
|
private static final ProfileLocation loc = ProfileLocation.create(12, "foo");
|
||||||
private static final ProfileLocation locB = ProfileLocation.create();
|
private static final ProfileLocation locB = ProfileLocation.create();
|
||||||
private static final ProfileLocation loc2 = ProfileLocation.create();
|
private static final ProfileLocation loc2 = ProfileLocation.create();
|
||||||
|
private static final ProfileLocation locWithLine = ProfileLocation.createWithLine();
|
||||||
private boolean doIt() {
|
private boolean doIt() {
|
||||||
locB.obtain(); // simulate a location moving by line number only
|
locB.obtain(); // simulate a location moving by line number only
|
||||||
return loc.obtain();
|
boolean result = loc.obtain();
|
||||||
|
locWithLine.obtain();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -29,6 +31,16 @@ class ProfileLocationTest {
|
|||||||
assertThat(locB.label()).isEqualTo("ProfileLocationTest.doIt");
|
assertThat(locB.label()).isEqualTo("ProfileLocationTest.doIt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_obtainWithLine() {
|
||||||
|
doIt();
|
||||||
|
|
||||||
|
// same hash even when the line number has changed
|
||||||
|
assertThat(locWithLine.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:17)");
|
||||||
|
assertThat(locWithLine.location()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt:17");
|
||||||
|
assertThat(locWithLine.label()).isEqualTo("ProfileLocationTest.doIt:17");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_add() {
|
void test_add() {
|
||||||
loc.add(100);
|
loc.add(100);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
ebean-version: 142
|
ebean-version: 143
|
||||||
@@ -49,8 +49,8 @@
|
|||||||
<ebean-migration.version>13.7.0</ebean-migration.version>
|
<ebean-migration.version>13.7.0</ebean-migration.version>
|
||||||
<ebean-test-containers.version>6.3</ebean-test-containers.version>
|
<ebean-test-containers.version>6.3</ebean-test-containers.version>
|
||||||
<ebean-datasource.version>8.5</ebean-datasource.version>
|
<ebean-datasource.version>8.5</ebean-datasource.version>
|
||||||
<ebean-agent.version>13.13.0</ebean-agent.version>
|
<ebean-agent.version>13.13.1</ebean-agent.version>
|
||||||
<ebean-maven-plugin.version>13.13.0</ebean-maven-plugin.version>
|
<ebean-maven-plugin.version>13.13.1</ebean-maven-plugin.version>
|
||||||
<surefire.useModulePath>false</surefire.useModulePath>
|
<surefire.useModulePath>false</surefire.useModulePath>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
ebean-version: 142
|
ebean-version: 143
|
||||||
Reference in new issue
Block a user