mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1237 - ENH: Add ProfileLocation - support for relating performance metrics for queries and transactions back to source line of code
This commit is contained in:
1 parent
82f5c21d26
commit
b9ae76d465
23 files changed
+359
-11
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.ProfileLocation;
|
||||
|
||||
/**
|
||||
* Fixed / given location. Used internally for find by id and find all.
|
||||
*/
|
||||
class BasicProfileLocation implements ProfileLocation {
|
||||
|
||||
private final String location;
|
||||
|
||||
BasicProfileLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "location: " + location;
|
||||
}
|
||||
|
||||
public String obtain() {
|
||||
return location;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.ProfileLocation;
|
||||
|
||||
/**
|
||||
* Default profile location that uses stack trace.
|
||||
*/
|
||||
class DProfileLocation implements ProfileLocation {
|
||||
|
||||
private static final String IO_EBEAN = "io.ebean";
|
||||
|
||||
private static final String UNKNOWN = "unknown";
|
||||
|
||||
private String location;
|
||||
|
||||
private final int lineNumber;
|
||||
|
||||
DProfileLocation() {
|
||||
this.lineNumber = 0;
|
||||
}
|
||||
|
||||
DProfileLocation(int lineNumber) {
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "location: " + location;
|
||||
}
|
||||
|
||||
public String obtain() {
|
||||
// atomic assignment so happy with this
|
||||
if (location == null) {
|
||||
location = create();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
private String create() {
|
||||
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
||||
for (int i = 3; i < trace.length; i++) {
|
||||
if (!trace[i].getClassName().startsWith(IO_EBEAN)) {
|
||||
return withLineNumber(trace[i].toString());
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
private String withLineNumber(String traceLine) {
|
||||
if (lineNumber == 0 || traceLine.contains(":")) {
|
||||
return traceLine;
|
||||
} else {
|
||||
return traceLine.substring(0, traceLine.length() - 1) + ":" + lineNumber + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.service.SpiProfileLocationFactory;
|
||||
|
||||
/**
|
||||
* Default implementation of the profile location factory.
|
||||
*/
|
||||
public class DProfileLocationFactory implements SpiProfileLocationFactory {
|
||||
|
||||
@Override
|
||||
public ProfileLocation create() {
|
||||
return new DProfileLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileLocation create(int lineNumber) {
|
||||
return new DProfileLocation(lineNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileLocation create(String location) {
|
||||
return new BasicProfileLocation(location);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user