Optimize VerboseHandler by delaying construction of stack trace array until later

This commit is contained in:
Luck 2020-04-07 17:56:56 +01:00
parent 8cecfe5b7c
commit 83e9ac04b2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 9 additions and 9 deletions

View File

@ -80,7 +80,7 @@ public class VerboseHandler implements AutoCloseable {
return;
}
StackTraceElement[] trace = new Exception().getStackTrace();
Throwable trace = new Throwable();
String thread = Thread.currentThread().getName();
// add the check data to a queue to be processed later.
@ -105,7 +105,7 @@ public class VerboseHandler implements AutoCloseable {
return;
}
StackTraceElement[] trace = new Exception().getStackTrace();
Throwable trace = new Throwable();
String thread = Thread.currentThread().getName();
// add the check data to a queue to be processed later.

View File

@ -46,7 +46,7 @@ public class MetaCheckEvent extends VerboseEvent {
*/
private final String result;
public MetaCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread, String key, String result) {
public MetaCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, Throwable checkTrace, String checkThread, String key, String result) {
super(checkTarget, checkQueryOptions, checkTrace, checkThread);
this.origin = origin;
this.key = key;

View File

@ -47,7 +47,7 @@ public class PermissionCheckEvent extends VerboseEvent {
*/
private final TristateResult result;
public PermissionCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread, String permission, TristateResult result) {
public PermissionCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, Throwable checkTrace, String checkThread, String permission, TristateResult result) {
super(checkTarget, checkQueryOptions, checkTrace, checkThread);
this.origin = origin;
this.permission = permission;

View File

@ -54,16 +54,16 @@ public abstract class VerboseEvent implements VariableEvaluator {
private final QueryOptions checkQueryOptions;
/**
* The stack trace when the check took place
* The throwable created when the check took place
*/
private final StackTraceElement[] checkTrace;
private final Throwable checkTrace;
/**
* The name of the thread where the check took place
*/
private final String checkThread;
protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread) {
protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, Throwable checkTrace, String checkThread) {
this.checkTarget = checkTarget;
this.checkQueryOptions = checkQueryOptions;
this.checkTrace = checkTrace;
@ -79,7 +79,7 @@ public abstract class VerboseEvent implements VariableEvaluator {
}
public StackTraceElement[] getCheckTrace() {
return this.checkTrace;
return this.checkTrace.getStackTrace();
}
public String getCheckThread() {
@ -107,7 +107,7 @@ public abstract class VerboseEvent implements VariableEvaluator {
})
.add("trace", new JArray()
.consume(arr -> {
int overflow = tracePrinter.process(this.checkTrace, StackTracePrinter.elementToString(arr::add));
int overflow = tracePrinter.process(getCheckTrace(), StackTracePrinter.elementToString(arr::add));
if (overflow != 0) {
arr.add("... and " + overflow + " more");
}