Skip to content

Commit

Permalink
Add threads dump for troubleshooting purposes
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed May 13, 2024
1 parent 6e91285 commit 8992ebd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
21 changes: 3 additions & 18 deletions modules/nextflow/src/main/groovy/nextflow/cli/Launcher.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import nextflow.util.LoggerHelper
import nextflow.util.ProxyConfig
import nextflow.util.SpuriousDeps
import org.eclipse.jgit.api.errors.GitAPIException

import static nextflow.util.SysHelper.dumpThreads

/**
* Main application entry point. It parses the command line and
* launch the pipeline execution.
Expand Down Expand Up @@ -553,24 +556,6 @@ class Launcher {

}

/**
* Dump th stack trace of current running threads
* @return
*/
private String dumpThreads() {

def buffer = new StringBuffer()
Map<Thread, StackTraceElement[]> m = Thread.getAllStackTraces();
for(Map.Entry<Thread, StackTraceElement[]> e : m.entrySet()) {
buffer.append('\n').append(e.getKey().toString()).append('\n')
for (StackTraceElement s : e.getValue()) {
buffer.append(" " + s).append('\n')
}
}

return buffer.toString()
}

/**
* set up environment and system properties. It checks the following
* environment variables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import nextflow.executor.GridTaskHandler
import nextflow.util.Duration
import nextflow.util.Threads
import nextflow.util.Throttle
import static nextflow.util.SysHelper.dumpThreads

/**
* Monitors the queued tasks waiting for their termination
*
Expand Down Expand Up @@ -449,10 +451,15 @@ class TaskPollingMonitor implements TaskMonitor {
// dump this line every two minutes
Throttle.after(dumpInterval) {
dumpRunningQueue()
dumpCurrentThreads()
}
}
}

protected dumpCurrentThreads() {
log.trace "Current runnign threads:\n${dumpThreads()}"
}

protected void dumpRunningQueue() {

try {
Expand Down
17 changes: 17 additions & 0 deletions modules/nf-commons/src/main/nextflow/util/SysHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,21 @@ class SysHelper {
return os.getArch()
}

/**
* Dump th stack trace of current running threads
* @return
*/
static String dumpThreads() {

def buffer = new StringBuffer()
Map<Thread, StackTraceElement[]> m = Thread.getAllStackTraces();
for(Map.Entry<Thread, StackTraceElement[]> e : m.entrySet()) {
buffer.append('\n').append(e.getKey().toString()).append('\n')
for (StackTraceElement s : e.getValue()) {
buffer.append(" " + s).append('\n')
}
}

return buffer.toString()
}
}

0 comments on commit 8992ebd

Please sign in to comment.