Skip to content

Commit df20f56

Browse files
authored
Merge pull request #148 from IBM/142-treat-any-thread-with-a-truncated-stack-as-interesting
#142 treat any thread with a truncated stack as interesting
2 parents d64300a + 7c859c3 commit df20f56

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/javacore_analyser/java_thread.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
from javacore_analyser.abstract_snapshot_collection import AbstractSnapshotCollection
66
from javacore_analyser.properties import Properties
7+
from javacore_analyser.stack_trace import StackTrace
78

89

910
class Thread(AbstractSnapshotCollection):
@@ -21,6 +22,7 @@ def is_interesting(self):
2122
if self.get_avg_mem() // (1024 * 1024) > 0: return True # memory in megabytes
2223
if len(self.get_blocker_threads()) > 0: return True
2324
if len(self.get_blocking_threads()) > 0: return True
25+
if self.has_tall_stacks(): return True
2426
return False
2527

2628
def get_hash(self):
@@ -144,3 +146,9 @@ def get_blocker_threads(self):
144146

145147
def get_id(self):
146148
return self.get_hash()
149+
150+
def has_tall_stacks(self):
151+
for snapshot in self.thread_snapshots:
152+
if snapshot.stack_trace and snapshot.stack_trace.get_java_stack_depth() > StackTrace.TRUNCATION_DEPTH:
153+
return True
154+
return False

src/javacore_analyser/stack_trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright IBM Corp. 2024 - 2024
2+
# Copyright IBM Corp. 2024 - 2025
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

@@ -10,6 +10,7 @@
1010
class StackTrace:
1111
java_stack_depth: int
1212
EMPTY_STACK = "No stack"
13+
TRUNCATION_DEPTH = 50 # as per https://github.ibm.com/IOT-ELM-Poznan/Wait2/issues/430
1314

1415
"""
1516
how many first lines of the stack need to be equal

test/test_java_thread.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from javacore_analyser.java_thread import Thread
1010
from javacore_analyser.javacore import Javacore
11+
from javacore_analyser.stack_trace import StackTrace
12+
from javacore_analyser.stack_trace_element import StackTraceElement
1113
from javacore_analyser.thread_snapshot import ThreadSnapshot
1214

1315

@@ -129,3 +131,28 @@ def test_is_interesting(self):
129131
thread_snapshot1.blocker = thread_snapshot2
130132
self.assertTrue(thread.is_interesting(), "This thread is blocked, so should be interesting")
131133

134+
thread = Thread()
135+
thread_snapshot = ThreadSnapshot()
136+
stack_trace = StackTrace()
137+
for i in range(51):
138+
stack_trace_element = StackTraceElement()
139+
stack_trace.stack_trace_elements.append(stack_trace_element)
140+
thread.thread_snapshots.append(thread_snapshot)
141+
thread_snapshot.stack_trace = stack_trace
142+
self.assertTrue(thread.is_interesting(), "This thread has a tall stack, so should be interesting")
143+
144+
def test_has_tall_stacks(self):
145+
thread = Thread()
146+
thread_snapshot = ThreadSnapshot()
147+
stack_trace = StackTrace()
148+
assert(not thread.has_tall_stacks())
149+
for i in range(50):
150+
stack_trace_element = StackTraceElement()
151+
stack_trace.stack_trace_elements.append(stack_trace_element)
152+
thread.thread_snapshots.append(thread_snapshot)
153+
thread_snapshot.stack_trace = stack_trace
154+
assert (not thread.has_tall_stacks())
155+
stack_trace.stack_trace_elements.append(StackTraceElement())
156+
assert (thread.has_tall_stacks())
157+
158+

0 commit comments

Comments
 (0)