[memory-agent] Add ability to specify path to memory agent library and force debugger to use it instead of bundled one

This commit is contained in:
Vitaliy.Bibaev
2019-01-31 18:33:08 +03:00
parent ccfae984f9
commit 42f80e2e10
2 changed files with 21 additions and 5 deletions
@@ -32,12 +32,12 @@ public class MemoryAgentUtil {
ParametersList parametersList = parameters.getVMParametersList();
if (parametersList.getParameters().stream().anyMatch(x -> x.contains("memory_agent"))) return;
File extractedAgent = null;
boolean isInDebugMode = Registry.is("debugger.memory.agent.debug");
File agentFile = null;
String errorMessage = null;
long start = System.currentTimeMillis();
try {
extractedAgent = ApplicationManager.getApplication()
.executeOnPooledThread(() -> new AgentExtractor().extract()).get(1, TimeUnit.SECONDS);
agentFile = getAgentFile(isInDebugMode);
}
catch (InterruptedException e) {
errorMessage = "Interrupted";
@@ -49,7 +49,7 @@ public class MemoryAgentUtil {
catch (TimeoutException e) {
errorMessage = "Timeout";
}
if (errorMessage != null || extractedAgent == null) {
if (errorMessage != null || agentFile == null) {
LOG.warn("Could not extract agent: " + errorMessage);
return;
}
@@ -57,7 +57,7 @@ public class MemoryAgentUtil {
LOG.info("Memory agent extracting took " + (System.currentTimeMillis() - start) + " ms");
String path = JavaExecutionUtil.handleSpacesInAgentPath(agentFile.getAbsolutePath(), "debugger-memory-agent", null);
String args = "";
if (Registry.is("debugger.memory.agent.debug")) {
if (isInDebugMode) {
args = "5";// Enable debug messages
}
path += "=" + args;
@@ -99,4 +99,16 @@ public class MemoryAgentUtil {
}
});
}
private static File getAgentFile(boolean isInDebugMode) throws InterruptedException, ExecutionException, TimeoutException {
if (isInDebugMode) {
String debugAgentPath = Registry.get("debugger.memory.agent.debug.path").asString();
if (!debugAgentPath.isEmpty()) {
return new File(debugAgentPath);
}
}
return ApplicationManager.getApplication()
.executeOnPooledThread(() -> new AgentExtractor().extract()).get(1, TimeUnit.SECONDS);
}
}
@@ -356,6 +356,8 @@ debugger.enable.memory.agent=false
debugger.enable.memory.agent.description=Allow to start java debug sessions with attached debugger memory agent
debugger.memory.agent.debug=false
debugger.memory.agent.debug.description=Enable debug logging to stdout from memory agent
debugger.memory.agent.debug.path=
debugger.memory.agent.debug.path.description=Force debugger to use specified memory agent library instead of bundled one (only for debugging purpose). Will be used only if debugger.memory.agent.debug checked
debugger.tree.states.depth=100
debugger.new.threads.view=false
debugger.breakpoints.caller.filter=true
@@ -379,6 +381,8 @@ execution.java.always.debug=false
execution.java.always.debug.description=Always run java processes with the debug agent
execution.dump.threads.using.attach=true
execution.dump.threads.using.attach.description=Use Java attach API to dump threads
debugger.save.and.compare=false
debugger.save.and.compare.description=Enable "Save & Compare" feature in the debugger
index.run.configuration.jre=false
index.run.configuration.jre.restartRequired=true