Skip to content

Commit de57ab2

Browse files
fvoznikagvisor-bot
authored andcommitted
Improvements to stuck task tool
Use function names as line ID (path+line may include registers that make it non-unique). Sort larger stacks at the top. This is useful to spot unique stacks that are likely the ones causing the deadlock. PiperOrigin-RevId: 810562912
1 parent 5117ddc commit de57ab2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tools/stucktasks/BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ package(
88
go_binary(
99
name = "stucktasks",
1010
srcs = ["stucktasks.go"],
11-
deps = [
12-
"//runsc/flag",
13-
],
11+
deps = ["//runsc/flag"],
1412
)

tools/stucktasks/stucktasks.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func analyzeStackDump(scanner *bufio.Scanner, out io.Writer, stuckIds map[uint]s
134134
sorted = append(sorted, c)
135135
}
136136
sort.Slice(sorted, func(i, j int) bool {
137-
// Reverse sort
137+
// Sort with the most occurring stacks first, then start with the longest stacks (likely
138+
// to be the more relevant for deadlocks).
139+
if sorted[i].count == sorted[j].count {
140+
return len(sorted[i].stack.lines) > len(sorted[j].stack.lines)
141+
}
138142
return sorted[i].count > sorted[j].count
139143
})
140144

@@ -210,7 +214,13 @@ func parseBlock(block []string) (*stack, error) {
210214

211215
var signature string
212216
for i, line := range block[1:] {
213-
if i%2 == 1 {
217+
// Only look at function names. Skip odd lines that contain file names.
218+
if i%2 == 0 {
219+
// Use the full function name, but ignore argument values.
220+
idx := strings.LastIndex(line, "(")
221+
if idx != -1 {
222+
line = line[:idx]
223+
}
214224
signature += line + "\n"
215225
}
216226
}

0 commit comments

Comments
 (0)