Skip to content

Commit 99bf38c

Browse files
Attempt to collect thread dump.
1 parent 2a53ed6 commit 99bf38c

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

dd-java-agent/instrumentation/java-concurrent/java-concurrent-21/src/previewTest/groovy/StructuredConcurrencyTest.groovy

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ class StructuredConcurrencyTest extends AgentTestRunner {
2020
scheduler = Executors.newSingleThreadScheduledExecutor()
2121

2222
threadDumpTask = scheduler.schedule({
23-
println "=== Thread Dump Triggered at ${new Date()} ==="
24-
Thread.getAllStackTraces().each { thread, stack ->
25-
println "Thread: ${thread.name}, daemon: ${thread.daemon}"
26-
stack.each { println "\tat ${it}" }
23+
File reportDir = new File("build/reports")
24+
25+
// Ensure the directory exists
26+
if (!reportDir.exists()) {
27+
reportDir.mkdirs()
28+
}
29+
30+
// Define the file path
31+
File reportFile = new File(reportDir, String.format("thread-dump-%d.log", System.currentTimeMillis()))
32+
33+
// Write to the file
34+
try (FileWriter writer = new FileWriter(reportFile)) {
35+
writer.write("=== Thread Dump Triggered at ${new Date()} ===\n")
36+
Thread.getAllStackTraces().each { thread, stack ->
37+
writer.write("Thread: ${thread.name}, daemon: ${thread.daemon}\n")
38+
stack.each { writer.write("\tat ${it}\n") }
39+
}
40+
writer.write("==============================================\n")
2741
}
28-
println "==============================================="
2942
}, 7, TimeUnit.MINUTES)
3043
}
3144

@@ -46,12 +59,12 @@ class StructuredConcurrencyTest extends AgentTestRunner {
4659
when:
4760
runUnderTrace("parent") {
4861
def task = taskScope.fork(new Callable<Boolean>() {
49-
@Trace(operationName = "child")
50-
@Override
51-
Boolean call() throws Exception {
52-
return true
53-
}
54-
})
62+
@Trace(operationName = "child")
63+
@Override
64+
Boolean call() throws Exception {
65+
return true
66+
}
67+
})
5568
taskScope.joinUntil(now() + 10) // Wait for 10 seconds at maximum
5669
result = task.get()
5770
}

dd-java-agent/instrumentation/lettuce-4/src/test/groovy/Lettuce4ClientTestBase.groovy

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,37 @@ abstract class Lettuce4ClientTestBase extends VersionedNamingTestBase {
6161
embeddedDbUri = "redis://" + dbAddr
6262

6363
redisServer = RedisServer.newRedisServer()
64-
// bind to localhost to avoid firewall popup
65-
.setting("bind " + HOST)
66-
// set max memory to avoid problems in CI
67-
.setting("maxmemory 128M")
68-
.port(port).build()
64+
// bind to localhost to avoid firewall popup
65+
.setting("bind " + HOST)
66+
// set max memory to avoid problems in CI
67+
.setting("maxmemory 128M")
68+
.port(port).build()
6969
}
7070

7171
def setup() {
7272
scheduler = Executors.newSingleThreadScheduledExecutor()
7373

7474
threadDumpTask = scheduler.schedule({
75-
println "=== Thread Dump Triggered at ${new Date()} ==="
76-
Thread.getAllStackTraces().each { thread, stack ->
77-
println "Thread: ${thread.name}, daemon: ${thread.daemon}"
78-
stack.each { println "\tat ${it}" }
75+
File reportDir = new File("build/reports")
76+
77+
// Ensure the directory exists
78+
if (!reportDir.exists()) {
79+
reportDir.mkdirs()
7980
}
80-
println "==============================================="
81-
}, 7, TimeUnit.MINUTES)
8281

82+
// Define the file path
83+
File reportFile = new File(reportDir, String.format("thread-dump-%d.log", System.currentTimeMillis()))
84+
85+
// Write to the file
86+
try (FileWriter writer = new FileWriter(reportFile)) {
87+
writer.write("=== Thread Dump Triggered at ${new Date()} ===\n")
88+
Thread.getAllStackTraces().each { thread, stack ->
89+
writer.write("Thread: ${thread.name}, daemon: ${thread.daemon}\n")
90+
stack.each { writer.write("\tat ${it}\n") }
91+
}
92+
writer.write("==============================================\n")
93+
}
94+
}, 7, TimeUnit.MINUTES)
8395

8496
redisServer.start()
8597

0 commit comments

Comments
 (0)