use of com.shulie.instrument.simulator.module.model.profiler.ProfilerModel in project LinkAgent by shulieTech.
the class ProfilerModule method createProfilerModel.
private ProfilerModel createProfilerModel(String result, String action, String actionArg) {
ProfilerModel profilerModel = new ProfilerModel();
profilerModel.setAction(action);
profilerModel.setActionArg(actionArg);
profilerModel.setExecuteResult(result);
return profilerModel;
}
use of com.shulie.instrument.simulator.module.model.profiler.ProfilerModel in project LinkAgent by shulieTech.
the class ProfilerModule method profiler.
@Command(value = "profiler", description = "执行 async-profiler")
public CommandResponse<ProfilerModel> profiler(final Map<String, String> args) {
try {
final String action = getParameter(args, "action");
ProfilerAction profilerAction = ProfilerAction.valueOf(action);
if (ProfilerAction.actions.equals(profilerAction)) {
return CommandResponse.success(new ProfilerModel(actions()));
}
final String actionArg = getParameter(args, "actionArg");
final AsyncProfiler asyncProfiler = this.profilerInstance(action, actionArg);
if (ProfilerAction.execute.equals(profilerAction)) {
if (actionArg == null) {
return CommandResponse.failure("actionArg can not be empty.");
}
String result = execute(asyncProfiler, actionArg);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.start.equals(profilerAction)) {
// jfr录制,必须在start的时候就指定文件路径
final String file = getFile(args);
final String format = getParameter(args, "format", "svg");
String executeArgs = executeArgs(ProfilerAction.start, args);
String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
Long duration = getLongParameter(args, "duration");
if (duration != null) {
final String outputFile = outputFile(file, format);
profilerModel.setOutputFile(outputFile);
profilerModel.setDuration(duration);
// 延时执行stop
ExecutorServiceFactory.getFactory().schedule(new Runnable() {
@Override
public void run() {
// 在异步线程执行,profiler命令已经结束,不能输出到客户端
try {
logger.info("stopping profiler ...");
ProfilerModel model = processStop(asyncProfiler, args, file, format, action, actionArg);
logger.info("profiler output file: " + model.getOutputFile());
logger.info("stop profiler successfully.");
} catch (Throwable e) {
logger.error("stop profiler failure", e);
}
}
}, duration, TimeUnit.SECONDS);
}
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.stop.equals(profilerAction)) {
final String file = getFile(args);
final String format = getParameter(args, "format");
ProfilerModel profilerModel = processStop(asyncProfiler, args, file, format, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.resume.equals(profilerAction)) {
String executeArgs = executeArgs(ProfilerAction.resume, args);
String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.list.equals(profilerAction)) {
String result = asyncProfiler.execute("list");
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.version.equals(profilerAction)) {
String result = asyncProfiler.execute("version");
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.status.equals(profilerAction)) {
String result = asyncProfiler.execute("status");
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.dumpCollapsed.equals(profilerAction)) {
String actionArgs = actionArg;
if (actionArgs == null) {
actionArgs = "TOTAL";
}
actionArgs = actionArgs.toUpperCase();
if ("TOTAL".equals(actionArg) || "SAMPLES".equals(actionArgs)) {
String result = asyncProfiler.dumpCollapsed(Counter.valueOf(actionArgs));
ProfilerModel profilerModel = createProfilerModel(result, action, actionArgs);
return CommandResponse.success(profilerModel);
} else {
return CommandResponse.failure("ERROR: dumpCollapsed argument should be TOTAL or SAMPLES. ");
}
} else if (ProfilerAction.dumpFlat.equals(profilerAction)) {
int maxMethods = 0;
if (actionArg != null) {
maxMethods = Integer.valueOf(actionArg);
}
String result = asyncProfiler.dumpFlat(maxMethods);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.dumpTraces.equals(profilerAction)) {
int maxTraces = 0;
if (actionArg != null) {
maxTraces = Integer.valueOf(actionArg);
}
String result = asyncProfiler.dumpTraces(maxTraces);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
} else if (ProfilerAction.getSamples.equals(profilerAction)) {
String result = "" + asyncProfiler.getSamples() + "\n";
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
return CommandResponse.success(profilerModel);
}
return CommandResponse.failure("ERROR: unsupported action :" + profilerAction);
} catch (Throwable e) {
logger.error("AsyncProfiler error", e);
return CommandResponse.failure(e);
}
}
use of com.shulie.instrument.simulator.module.model.profiler.ProfilerModel in project LinkAgent by shulieTech.
the class ProfilerModule method processStop.
private ProfilerModel processStop(AsyncProfiler asyncProfiler, Map<String, String> args, String file, String format, String action, String actionArg) throws IOException {
String outputFile = outputFile(file, format);
String executeArgs = executeArgs(ProfilerAction.stop, args);
String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result, action, actionArg);
profilerModel.setOutputFile(outputFile);
return profilerModel;
}
Aggregations