mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
增加memory 可读性
This commit is contained in:
@@ -3,6 +3,7 @@ package com.taobao.arthas.core.command.monitor200;
|
||||
import com.taobao.arthas.core.command.Constants;
|
||||
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
|
||||
import com.taobao.arthas.core.shell.command.CommandProcess;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
import com.taobao.arthas.core.util.affect.RowAffect;
|
||||
import com.taobao.middleware.cli.annotations.Description;
|
||||
import com.taobao.middleware.cli.annotations.Name;
|
||||
@@ -12,15 +13,7 @@ import com.taobao.text.ui.Element;
|
||||
import com.taobao.text.ui.TableElement;
|
||||
import com.taobao.text.util.RenderUtil;
|
||||
|
||||
import java.lang.management.ClassLoadingMXBean;
|
||||
import java.lang.management.CompilationMXBean;
|
||||
import java.lang.management.GarbageCollectorMXBean;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
import java.lang.management.MemoryManagerMXBean;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.lang.management.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
@@ -180,24 +173,27 @@ public class JvmCommand extends AnnotatedCommand {
|
||||
}
|
||||
|
||||
private Element drawMemoryTable(TableElement table) {
|
||||
MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
|
||||
table.row("HEAP-MEMORY-USAGE\n[committed/init/max/used]",
|
||||
memoryMXBean.getHeapMemoryUsage().getCommitted()
|
||||
+ "/" + memoryMXBean.getHeapMemoryUsage().getInit()
|
||||
+ "/" + memoryMXBean.getHeapMemoryUsage().getMax()
|
||||
+ "/" + memoryMXBean.getHeapMemoryUsage().getUsed()
|
||||
formatMemoryByte(heapMemoryUsage.getCommitted())
|
||||
+ "/" + formatMemoryByte(heapMemoryUsage.getInit())
|
||||
+ "/" + formatMemoryByte(heapMemoryUsage.getMax())
|
||||
+ "/" + formatMemoryByte(heapMemoryUsage.getUsed())
|
||||
);
|
||||
|
||||
MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
|
||||
table.row("NO-HEAP-MEMORY-USAGE\n[committed/init/max/used]",
|
||||
memoryMXBean.getNonHeapMemoryUsage().getCommitted()
|
||||
+ "/" + memoryMXBean.getNonHeapMemoryUsage().getInit()
|
||||
+ "/" + memoryMXBean.getNonHeapMemoryUsage().getMax()
|
||||
+ "/" + memoryMXBean.getNonHeapMemoryUsage().getUsed()
|
||||
formatMemoryByte(nonHeapMemoryUsage.getCommitted())
|
||||
+ "/" + formatMemoryByte(nonHeapMemoryUsage.getInit())
|
||||
+ "/" + formatMemoryByte(nonHeapMemoryUsage.getMax())
|
||||
+ "/" + formatMemoryByte(nonHeapMemoryUsage.getUsed())
|
||||
);
|
||||
|
||||
table.row("PENDING-FINALIZE-COUNT", "" + memoryMXBean.getObjectPendingFinalizationCount());
|
||||
return table;
|
||||
}
|
||||
|
||||
private String formatMemoryByte(long bytes){
|
||||
return String.format("%s(%s)",bytes, StringUtils.humanReadableByteCount(bytes));
|
||||
}
|
||||
|
||||
private Element drawOperatingSystemMXBeanTable(TableElement table) {
|
||||
table.row("OS", operatingSystemMXBean.getName()).row("ARCH", operatingSystemMXBean.getArch())
|
||||
|
||||
@@ -20,6 +20,8 @@ public abstract class StringUtils {
|
||||
private static final String TOP_PATH = "..";
|
||||
private static final String CURRENT_PATH = ".";
|
||||
private static final char EXTENSION_SEPARATOR = '.';
|
||||
public static final int UNIT = 1024;
|
||||
public static final String STRING_UNITS = "KMGTPE";
|
||||
|
||||
|
||||
/**
|
||||
@@ -872,4 +874,16 @@ public abstract class StringUtils {
|
||||
if (clazz == null || clazz.getClassLoader() == null) return "null";
|
||||
return Integer.toHexString(clazz.getClassLoader().hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* format byte size to human readable format
|
||||
* @param bytes byets
|
||||
* @return human readable format
|
||||
*/
|
||||
public static String humanReadableByteCount(long bytes) {
|
||||
if (bytes < UNIT) return bytes + " B";
|
||||
int exp = (int) (Math.log(bytes) / Math.log(UNIT));
|
||||
String pre = STRING_UNITS.charAt(exp-1) + "i";
|
||||
return String.format("%.2f %sB", bytes / Math.pow(UNIT, exp), pre);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,9 +70,9 @@ $ jvm
|
||||
PS Old Gen
|
||||
|
||||
|
||||
MEMORY HEAP-MEMORY-USAGE 186646528/134217728/1908932608/31245568
|
||||
MEMORY HEAP-MEMORY-USAGE 1073741824(1.00 GiB)/1073741824(1.00 GiB)/5242880000(4.88 GiB)/278637584(265.73 MiB)
|
||||
[committed/init/max/used]
|
||||
NO-HEAP-MEMORY-USAGE 35520512/2555904/-1/34584616
|
||||
NO-HEAP-MEMORY-USAGE 172597248(164.60 MiB)/2555904(2.44 MiB)/1862270976(1.73 GiB)/166521144(158.81 MiB)
|
||||
[committed/init/max/used]
|
||||
PENDING-FINALIZE-COUNT 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user