Skip to content

Commit f3ca326

Browse files
committed
fix NPE
1 parent be61490 commit f3ca326

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

vjtop/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.vip.vjtools</groupId>
66
<artifactId>vjtop</artifactId>
7-
<version>1.0.4-SNAPSHOT</version>
7+
<version>1.0.4</version>
88
<name>vjtop</name>
99
<description>Linux top-like JVM info and busy threads monitoring tools</description>
1010

vjtop/src/main/java/com/vip/vjtools/vjtop/VMDetailView.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,10 @@ private void printTopMemoryThreads(DetailMode mode) throws IOException {
382382
continue;
383383
}
384384

385+
Long threadDelta = threadMemoryDeltaBytesMap.get(tid);
386+
long allocationRate = threadDelta == null ? 0 : (threadDelta * 1000) / vmInfo.upTimeMills.delta;
385387
System.out.printf(dataFormat, tid, threadName, Utils.leftStr(info.getThreadState().toString(), 10),
386-
Utils.toFixLengthSizeUnit((threadMemoryDeltaBytesMap.get(tid) * 1000) / vmInfo.upTimeMills.delta),
388+
Utils.toFixLengthSizeUnit(allocationRate),
387389
getThreadMemoryUtilization(threadMemoryDeltaBytesMap.get(tid), totalDeltaBytes),
388390
Utils.toFixLengthSizeUnit(threadMemoryTotalBytesMap.get(tid)),
389391
getThreadMemoryUtilization(threadMemoryTotalBytesMap.get(tid), totalBytes));
@@ -481,12 +483,10 @@ public void cleanupThreadsHistory() {
481483
}
482484

483485
private static double getThreadMemoryUtilization(Long threadBytes, long totalBytes) {
484-
if (threadBytes == null) {
485-
return 0;
486-
}
487-
if (totalBytes == 0) {
486+
if (threadBytes == null || totalBytes == 0) {
488487
return 0;
489488
}
489+
490490
return (threadBytes * 100d) / totalBytes;// 这里因为最后单位是百分比%,所以bytes除以totalBytes以后要乘以100,才可以再加上单位%
491491
}
492492

0 commit comments

Comments
 (0)