Ax1an commented on a change in pull request #7243:
URL: https://github.com/apache/skywalking/pull/7243#discussion_r663875013
##########
File path:
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/thread/ThreadProvider.java
##########
@@ -31,12 +32,58 @@
}
public Thread getThreadMetrics() {
+ int newStateThreadCount = 0;
+ int runnableStateThreadCount = 0;
+ int blockedStateThreadCount = 0;
+ int waitingStateThreadCount = 0;
+ int timedWaitingStateThreadCount = 0;
+ int terminatedStateThreadCount = 0;
+
+ ThreadInfo[] threadInfos =
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 0);
+ if (threadInfos != null) {
+ for (ThreadInfo threadInfo : threadInfos) {
+ if (threadInfo != null) {
+ switch (threadInfo.getThreadState()) {
+ case NEW:
+ newStateThreadCount++;
+ break;
+ case RUNNABLE:
+ runnableStateThreadCount++;
+ break;
+ case BLOCKED:
+ blockedStateThreadCount++;
+ break;
+ case WAITING:
+ waitingStateThreadCount++;
+ break;
+ case TIMED_WAITING:
+ timedWaitingStateThreadCount++;
+ break;
+ case TERMINATED:
+ terminatedStateThreadCount++;
+ break;
+ default:
+ break;
+ }
+ } else {
+ terminatedStateThreadCount++;
+ }
Review comment:
The code as a whole looks good. However, there may be some inaccuracies
in this place. I found that `getAllThreadIds()` and `getThreadInfo` method both
return information about the active thread. However, when the thread is in the
NEW and TERMINATED state, the `isAlive()` method will return false, that is,
they are inactive. Therefore, in this way, we cannot correctly count the number
of threads in the NEW and TERMINATED state.
##########
File path:
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/thread/ThreadProvider.java
##########
@@ -31,12 +32,58 @@
}
public Thread getThreadMetrics() {
+ int newStateThreadCount = 0;
+ int runnableStateThreadCount = 0;
+ int blockedStateThreadCount = 0;
+ int waitingStateThreadCount = 0;
+ int timedWaitingStateThreadCount = 0;
+ int terminatedStateThreadCount = 0;
+
+ ThreadInfo[] threadInfos =
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 0);
+ if (threadInfos != null) {
+ for (ThreadInfo threadInfo : threadInfos) {
+ if (threadInfo != null) {
+ switch (threadInfo.getThreadState()) {
+ case NEW:
+ newStateThreadCount++;
+ break;
+ case RUNNABLE:
+ runnableStateThreadCount++;
+ break;
+ case BLOCKED:
+ blockedStateThreadCount++;
+ break;
+ case WAITING:
+ waitingStateThreadCount++;
+ break;
+ case TIMED_WAITING:
+ timedWaitingStateThreadCount++;
+ break;
+ case TERMINATED:
+ terminatedStateThreadCount++;
+ break;
+ default:
+ break;
+ }
+ } else {
+ terminatedStateThreadCount++;
+ }
Review comment:
The code as a whole looks good. However, there may be some inaccuracies
in this place. I found that `getAllThreadIds()` and `getThreadInfo()` method
both return information about the active thread. However, when the thread is in
the NEW and TERMINATED state, the `isAlive()` method will return false, that
is, they are inactive. Therefore, in this way, we cannot correctly count the
number of threads in the NEW and TERMINATED state.
##########
File path:
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/thread/ThreadProvider.java
##########
@@ -31,12 +32,58 @@
}
public Thread getThreadMetrics() {
+ int newStateThreadCount = 0;
+ int runnableStateThreadCount = 0;
+ int blockedStateThreadCount = 0;
+ int waitingStateThreadCount = 0;
+ int timedWaitingStateThreadCount = 0;
+ int terminatedStateThreadCount = 0;
+
+ ThreadInfo[] threadInfos =
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 0);
+ if (threadInfos != null) {
+ for (ThreadInfo threadInfo : threadInfos) {
+ if (threadInfo != null) {
+ switch (threadInfo.getThreadState()) {
+ case NEW:
+ newStateThreadCount++;
+ break;
+ case RUNNABLE:
+ runnableStateThreadCount++;
+ break;
+ case BLOCKED:
+ blockedStateThreadCount++;
+ break;
+ case WAITING:
+ waitingStateThreadCount++;
+ break;
+ case TIMED_WAITING:
+ timedWaitingStateThreadCount++;
+ break;
+ case TERMINATED:
+ terminatedStateThreadCount++;
+ break;
+ default:
+ break;
+ }
+ } else {
+ terminatedStateThreadCount++;
+ }
Review comment:
So we need to consider whether we want to remove them.
##########
File path:
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/thread/ThreadProvider.java
##########
@@ -31,12 +32,58 @@
}
public Thread getThreadMetrics() {
+ int newStateThreadCount = 0;
+ int runnableStateThreadCount = 0;
+ int blockedStateThreadCount = 0;
+ int waitingStateThreadCount = 0;
+ int timedWaitingStateThreadCount = 0;
+ int terminatedStateThreadCount = 0;
+
+ ThreadInfo[] threadInfos =
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 0);
+ if (threadInfos != null) {
+ for (ThreadInfo threadInfo : threadInfos) {
+ if (threadInfo != null) {
+ switch (threadInfo.getThreadState()) {
+ case NEW:
+ newStateThreadCount++;
+ break;
+ case RUNNABLE:
+ runnableStateThreadCount++;
+ break;
+ case BLOCKED:
+ blockedStateThreadCount++;
+ break;
+ case WAITING:
+ waitingStateThreadCount++;
+ break;
+ case TIMED_WAITING:
+ timedWaitingStateThreadCount++;
+ break;
+ case TERMINATED:
+ terminatedStateThreadCount++;
+ break;
+ default:
+ break;
+ }
+ } else {
+ terminatedStateThreadCount++;
+ }
Review comment:
If you remove the counting logic from the else code block, you may find
that the `Terminated State` is zero always.
##########
File path: docs/en/concepts-and-designs/scope-definitions.md
##########
@@ -104,9 +104,25 @@ This calculates the metrics data if the service instance
is a JVM and collects t
|---|---|---|---|
| name | The name of the service instance, such as `ip:port@Service Name`.
**Note**: Currently, the native agent uses `uuid@ipv4` as the instance name,
which does not assist in setting up a filter in aggregation. | | string|
| serviceName | The name of the service. | | string |
-| liveCount | The current number of live threads. | | int |
-| daemonCount | The current number of daemon threads. | | int |
-| peakCount | The current number of peak threads. | | int |
+| liveCount | The current number of live threads. | | long |
+| daemonCount | The current number of daemon threads. | | long |
+| peakCount | The current number of peak threads. | | long |
+| newStateThreadCount | The current number of threads in new state. | | long |
+| runnableStateThreadCount | The current number of threads in runnable state.
| | long |
+| blockedStateThreadCount | The current number of threads in blocked state. |
| long |
+| waitingStateThreadCount | The current number of threads in waiting state. |
| long |
+| timedWaitingStateThreadCount | The current number of threads in time-waiting
state. | | long |
+| terminatedStateThreadCount | The current number of threads in terminated
state. | | long |
Review comment:
```suggestion
| runnableStateThreadCount | The current number of threads in runnable
state. | | long |
| blockedStateThreadCount | The current number of threads in blocked state.
| | long |
| waitingStateThreadCount | The current number of threads in waiting state.
| | long |
| timedWaitingStateThreadCount | The current number of threads in
time-waiting state. | | long |
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]