Skip to content

Instantly share code, notes, and snippets.

@olivergondza
Last active August 29, 2015 14:15
Show Gist options
  • Save olivergondza/0b388180cf89831ec2be to your computer and use it in GitHub Desktop.
Save olivergondza/0b388180cf89831ec2be to your computer and use it in GitHub Desktop.
Dumpling query to group threads by locks involved - not sure it is of any use
waitingTo = [:]
waitingOn = [:]
acquired = [:]
D.runtime.threads.each {
it.acquiredLocks.each { al ->
if (acquired[al]) {
acquired[al] << it;
} else {
acquired[al] = [it];
}
}
if (it.waitingOnLock) {
if (waitingOn[it.waitingOnLock]) {
waitingOn[it.waitingOnLock] << it;
} else {
waitingOn[it.waitingOnLock] = [it];
}
}
if (it.waitingToLock) {
if (waitingTo[it.waitingToLock]) {
waitingTo[it.waitingToLock] << it;
} else {
waitingTo[it.waitingToLock] = [it];
}
}
}
acquired.remove(null);
waitingTo.remove(null);
waitingOn.remove(null);
acquired = acquired.sort { l, r -> waitingTo[r.key]?.size() <=> waitingTo[l.key]?.size() }
acquired.each { lock, threads ->
println lock;
threads.each { t ->
println "\tAcquired ${t.header}";
}
waitingTo[lock].each { t ->
println "\tBlocked ${t.header}";
waitingTo.remove(lock);
}
waitingOn[lock].each { t ->
println "\tWaiting on ${t.header}";
waitingOn.remove(lock);
}
}
waitingTo.each { lock, threads ->
// all should be consumed in acquired listing
assert threads.empty
}
waitingOn = waitingOn.sort { l, r -> r.value.size() <=> l.value.size() }
waitingOn.each { lock, threads ->
println lock;
threads.each { t ->
println "\tWaiting on ${t.header}";
}
}
return null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment