use of com.shulie.instrument.simulator.api.annotation.Command in project LinkAgent by shulieTech.
the class GcModule method info.
@Command(value = "info", description = "获取当前进程的 gc 信息")
public CommandResponse info(final Map<String, String> args) {
try {
List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
GcInfo gcInfo = new GcInfo();
for (GarbageCollectorMXBean gcMXBean : garbageCollectorMxBeans) {
String name = gcMXBean.getName();
if (youngGcNames.contains(name)) {
gcInfo.setYoungGcCount(gcMXBean.getCollectionCount());
gcInfo.setYoungGcTime(gcMXBean.getCollectionTime());
} else if (oldGcNames.contains(name)) {
gcInfo.setOldGcCount(gcMXBean.getCollectionCount());
gcInfo.setOldGcTime(gcMXBean.getCollectionTime());
}
}
return CommandResponse.success(gcInfo);
} catch (Throwable e) {
return CommandResponse.failure(e);
}
}
use of com.shulie.instrument.simulator.api.annotation.Command in project LinkAgent by shulieTech.
the class HeapDumpModule method heapdump.
@Command(value = "dump", description = "dump 内存")
public CommandResponse heapdump(final Map<String, String> args) {
try {
String dumpFile = args.get("file");
boolean live = ParameterUtils.getBoolean(args, "live", true);
if (dumpFile == null || dumpFile.isEmpty()) {
String date = sdf.get().format(new Date());
File file = File.createTempFile("heapdump-" + date + (live ? "-live" : ""), ".hprof");
dumpFile = file.getAbsolutePath();
file.delete();
}
if (JvmUtils.supportsVersion(JvmVersion.JAVA_7)) {
run(dumpFile, live);
return CommandResponse.success(dumpFile);
} else {
final String bashCommand = (new StringBuilder("nohup sh ").append(simulatorConfig.getSimulatorHome()).append("/bin/dump.sh ").append(dumpFile).append(" ").append(RuntimeUtils.getPid()).append(" ").append(live)).append(" ").append("&").toString();
execute(bashCommand);
if (new File(dumpFile + ".finished").exists()) {
new File(dumpFile + ".finished").delete();
return CommandResponse.success(dumpFile);
}
}
return CommandResponse.failure("heapdump execute failed. please retry it later!");
} catch (NoSuchMethodError e) {
return CommandResponse.failure("dumpheap is not supported in this jdk version");
} catch (NoClassDefFoundError e) {
return CommandResponse.failure("dumpheap is not supported in this jdk version");
} catch (Throwable e) {
return CommandResponse.failure(e);
}
}
Aggregations