Skip to content

Commit

Permalink
fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Aug 16, 2018
1 parent be61490 commit f3ca326
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vjtop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.vip.vjtools</groupId>
<artifactId>vjtop</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.4</version>
<name>vjtop</name>
<description>Linux top-like JVM info and busy threads monitoring tools</description>

Expand Down
10 changes: 5 additions & 5 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/VMDetailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ private void printTopMemoryThreads(DetailMode mode) throws IOException {
continue;
}

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

private static double getThreadMemoryUtilization(Long threadBytes, long totalBytes) {
if (threadBytes == null) {
return 0;
}
if (totalBytes == 0) {
if (threadBytes == null || totalBytes == 0) {
return 0;
}

return (threadBytes * 100d) / totalBytes;// 这里因为最后单位是百分比%,所以bytes除以totalBytes以后要乘以100,才可以再加上单位%
}

Expand Down

0 comments on commit f3ca326

Please sign in to comment.