summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2020-09-26 00:20:28 +0200
committerHåkon Hallingstad <hakon@verizonmedia.com>2020-09-26 00:20:28 +0200
commite38ba64f8253746739674720035d11bdcda5e155 (patch)
treee6128876cd7dbf3e0edcccfb22a5cfc48c3e4b49 /zkfacade
parent3097883d260238fdd883034f9448c4d63e08e3fc (diff)
Dump stack trace once per thread
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LockInfo.java34
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java22
2 files changed, 29 insertions, 27 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LockInfo.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LockInfo.java
index e959dae2a93..e9c238a40b9 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LockInfo.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/LockInfo.java
@@ -15,8 +15,7 @@ import java.util.Optional;
*/
public class LockInfo {
- private final Thread thread;
- private final String lockPath;
+ private final ThreadLockInfo threadLockInfo;
private final Instant acquireInstant;
private final Duration timeout;
@@ -24,8 +23,8 @@ public class LockInfo {
private volatile Optional<Instant> terminalStateInstant = Optional.empty();
private volatile Optional<String> stackTrace = Optional.empty();
- public static LockInfo invokingAcquire(Thread thread, String lockPath, Duration timeout) {
- return new LockInfo(thread, lockPath, timeout);
+ public static LockInfo invokingAcquire(ThreadLockInfo threadLockInfo, Duration timeout) {
+ return new LockInfo(threadLockInfo, timeout);
}
public enum LockState {
@@ -40,15 +39,14 @@ public class LockInfo {
private volatile LockState lockState = LockState.ACQUIRING;
- private LockInfo(Thread thread, String lockPath, Duration timeout) {
- this.thread = thread;
- this.lockPath = lockPath;
+ private LockInfo(ThreadLockInfo threadLockInfo, Duration timeout) {
+ this.threadLockInfo = threadLockInfo;
this.acquireInstant = Instant.now();
this.timeout = timeout;
}
- public String getThreadName() { return thread.getName(); }
- public String getLockPath() { return lockPath; }
+ public String getThreadName() { return threadLockInfo.getThreadName(); }
+ public String getLockPath() { return threadLockInfo.getLockPath(); }
public Instant getTimeAcquiredWasInvoked() { return acquireInstant; }
public Duration getAcquireTimeout() { return timeout; }
public LockState getLockState() { return lockState; }
@@ -78,23 +76,7 @@ public class LockInfo {
// This method is public. If invoked concurrently, the this.stackTrace may be updated twice,
// which is fine.
- var stackTrace = new StringBuilder();
-
- StackTraceElement[] elements = thread.getStackTrace();
- // first stack frame is "java.lang.Thread(Thread.java:1606)" or "jdk.internal.misc.Unsafe(Unsafe.java:-2)"!?
- for (int i = 0; i < elements.length; ++i) {
- var element = elements[i];
- stackTrace.append(element.getClassName())
- .append('.')
- .append(element.getMethodName())
- .append('(')
- .append(element.getFileName())
- .append(':')
- .append(element.getLineNumber())
- .append(")\n");
- }
-
- this.stackTrace = Optional.of(stackTrace.toString());
+ this.stackTrace = Optional.of(threadLockInfo.getStackTrace());
}
void acquireFailed() { setTerminalState(LockState.ACQUIRE_FAILED); }
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
index 1e46a153164..b796cb9af43 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
@@ -75,13 +75,33 @@ public class ThreadLockInfo {
public String getThreadName() { return thread.getName(); }
public String getLockPath() { return lockPath; }
+
+ public String getStackTrace() {
+ var stackTrace = new StringBuilder();
+
+ StackTraceElement[] elements = thread.getStackTrace();
+ for (int i = 0; i < elements.length; ++i) {
+ var element = elements[i];
+ stackTrace.append(element.getClassName())
+ .append('.')
+ .append(element.getMethodName())
+ .append('(')
+ .append(element.getFileName())
+ .append(':')
+ .append(element.getLineNumber())
+ .append(")\n");
+ }
+
+ return stackTrace.toString();
+ }
+
public List<LockInfo> getLockInfos() { return List.copyOf(lockInfos); }
/** Mutable method (see class doc) */
public void invokingAcquire(Duration timeout) {
lockCountersForPath.invokeAcquireCount.incrementAndGet();
lockCountersForPath.inCriticalRegionCount.incrementAndGet();
- lockInfos.add(LockInfo.invokingAcquire(thread, lockPath, timeout));
+ lockInfos.add(LockInfo.invokingAcquire(this, timeout));
}
/** Mutable method (see class doc) */