Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2201.2.x] Add ability to get strand dump during code execution #36767

Merged

Conversation

Nadeeshan96
Copy link
Contributor

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

$title
Fixes #36210
Fixes #36733
Fixes #36284

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

To get the strand dump when a Ballerina program is running, the user needs to get the PID of the Ballerina program (possibly using jps) and then send the SIGTRAP signal to that process.

Eg:
kill -5 $PID
or
kill -s TRAP $PID

(Note: This feature is not supported in some operating systems (like Windows) where TRAP POSIX signal is not supported.)

Some example strand dumps

Ballerina Strand Dump [2022/06/27 12:35:00]
===========================================

Current no. of strand groups    :       2
Current no. of strands          :       8

group 4 [QUEUED]: [5]
        strand 2 "main" [nadeeshand.testPackageWithModules.0:main] [WAITING]:
                at      nadeeshand.testPackageWithModules.0.1.0:bar(main.bal:30)
                        nadeeshand.testPackageWithModules.0.1.0:foo(main.bal:17)
                        nadeeshand.testPackageWithModules.0.1.0:foobar(main.bal:13)
                        nadeeshand.testPackageWithModules.0.1.0:main(main.bal:9)

        strand 4 "w1" [nadeeshand.testPackageWithModules.utils.0:func3][3] [BLOCKED]:
                at      ballerina.lang.runtime.0.0.0:sleep(runtime.bal:61)
                        nadeeshand.testPackageWithModules.utils.0.1.0:sleep_and_wait_nested(utils.bal:35)
                        nadeeshand.testPackageWithModules.utils.0.1.0:sleep_and_wait(utils.bal:31)
                        nadeeshand.testPackageWithModules.utils.0.1.0:$lambda$_0(utils.bal:17)

        strand 5 "w2" [nadeeshand.testPackageWithModules.utils.0:func3][3] [BLOCKED ON WORKER MESSAGE RECEIVE]:
                at      nadeeshand.testPackageWithModules.utils.0.1.0:$lambda$_1(utils.bal:24)

        strand 7 "w1" [nadeeshand.testPackageWithModules.0:bar][2] [BLOCKED]:
                at      ballerina.lang.runtime.0.0.0:sleep(runtime.bal:61)
                        nadeeshand.testPackageWithModules.0.1.0:sleep_and_wait_nested(main.bal:38)
                        nadeeshand.testPackageWithModules.0.1.0:sleep_and_wait(main.bal:34)
                        nadeeshand.testPackageWithModules.0.1.0:$lambda$_0(main.bal:22)

        strand 8 "w2" [nadeeshand.testPackageWithModules.0:bar][2] [BLOCKED ON WORKER MESSAGE RECEIVE]:
                at      nadeeshand.testPackageWithModules.0.1.0:$lambda$_1(main.bal:27)

group 5 [QUEUED]: [3]
        strand 6 "futureResult2" [nadeeshand.testPackageWithModules.0:main][2] [WAITING]:
                at      nadeeshand.testPackageWithModules.anotherutils.0.1.0:func3(anotherutils.bal:28)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:func2(anotherutils.bal:12)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:func1(anotherutils.bal:8)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:entryfunc(anotherutils.bal:4)

        strand 9 "w1" [nadeeshand.testPackageWithModules.anotherutils.0:func3][6] [BLOCKED]:
                at      ballerina.lang.runtime.0.0.0:sleep(runtime.bal:61)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:sleep_and_wait_nested(anotherutils.bal:37)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:sleep_and_wait(anotherutils.bal:33)
                        nadeeshand.testPackageWithModules.anotherutils.0.1.0:$lambda$_0(anotherutils.bal:17)

        strand 10 "w2" [nadeeshand.testPackageWithModules.anotherutils.0:func3][6] [BLOCKED ON WORKER MESSAGE RECEIVE]:
                at      nadeeshand.testPackageWithModules.anotherutils.0.1.0:$lambda$_1(anotherutils.bal:24)

===========================================

Ballerina Strand Dump [2022/06/27 12:37:42]
===========================================

Current no. of strand groups    :       2
Current no. of strands          :       2

group 5 [RUNNABLE]: [1]
        strand 3 "w1" [$anon...0:foo][2] [RUNNABLE]

group 6 [QUEUED]: [1]
        strand 4 "w2" [$anon...0:foo][2] [WAITING FOR LOCK]:
                at      $anon...0.0.0:$lambda$_1(deadlock-like.bal:23)

===========================================
Ballerina Strand Dump [2022/06/27 12:38:47]
===========================================

Current no. of strand groups	:	4
Current no. of strands      	:	6

group 4 [QUEUED]: [1]
	strand 2 "main" [$anon...0:main] [WAITING]:
		at	$anon...0.0.0:main(largeloop.bal:31)

group 5 [RUNNABLE]: [3]
	strand 3 "futureResult" [$anon...0:main][2] [RUNNABLE]

	strand 6 "w1" [$anon...0:func][3] [RUNNABLE]

	strand 7 "w2" [$anon...0:func][3] [WAITING FOR LOCK]:
		at	ballerina.lang.__internal.0.0.0:next(int-range.bal:59)
		  	$anon...0.0.0:$lambda$_3(largeloop.bal:55)

group 6 [RUNNABLE]: [1]
	strand 4 "w1" [$anon...0:main][2] [RUNNABLE]

group 7 [RUNNABLE]: [1]
	strand 5 "w2" [$anon...0:main][2] [RUNNABLE]

===========================================

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@Nadeeshan96 Nadeeshan96 added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Jun 29, 2022
@codecov
Copy link

codecov bot commented Jun 29, 2022

Codecov Report

Merging #36767 (df61fb5) into 2201.2.x (b5eba40) will increase coverage by 0.01%.
The diff coverage is 89.75%.

@@              Coverage Diff               @@
##             2201.2.x   #36767      +/-   ##
==============================================
+ Coverage       74.36%   74.37%   +0.01%     
- Complexity      48916    48950      +34     
==============================================
  Files            3279     3280       +1     
  Lines          189394   189541     +147     
  Branches        24734    24744      +10     
==============================================
+ Hits           140846   140979     +133     
- Misses          40425    40434       +9     
- Partials         8123     8128       +5     
Impacted Files Coverage Δ
...llerinalang/compiler/bir/codegen/JvmConstants.java 100.00% <ø> (ø)
...compiler/bir/codegen/interop/InteropMethodGen.java 72.70% <0.00%> (ø)
.../ballerina/runtime/internal/scheduling/Strand.java 79.49% <73.91%> (-1.43%) ⬇️
...ballerina/runtime/internal/launch/LaunchUtils.java 86.36% <83.33%> (-0.48%) ⬇️
...llerina/runtime/internal/scheduling/Scheduler.java 73.17% <92.30%> (+0.50%) ⬆️
...erinalang/compiler/bir/codegen/JvmCodeGenUtil.java 92.74% <93.75%> (+<0.01%) ⬆️
...rina/runtime/internal/troubleshoot/StrandDump.java 100.00% <100.00%> (ø)
...inalang/compiler/bir/codegen/JvmTerminatorGen.java 87.18% <100.00%> (-0.02%) ⬇️
.../compiler/bir/codegen/methodgen/FrameClassGen.java 96.07% <100.00%> (+1.48%) ⬆️
.../compiler/bir/codegen/methodgen/MainMethodGen.java 97.30% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b83a9e...df61fb5. Read the comment docs.

Copy link
Contributor

@warunalakshitha warunalakshitha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants