mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external build: profiling mode support
This commit is contained in:
@@ -770,11 +770,16 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
cmdLine.addParameter("-D"+ GlobalOptions.COMPILE_PARALLEL_OPTION +"=" + Boolean.toString(config.PARALLEL_COMPILATION));
|
||||
|
||||
boolean isProfilingMode = false;
|
||||
final String additionalOptions = config.COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS;
|
||||
if (!StringUtil.isEmpty(additionalOptions)) {
|
||||
final StringTokenizer tokenizer = new StringTokenizer(additionalOptions, " ", false);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
cmdLine.addParameter(tokenizer.nextToken());
|
||||
final String option = tokenizer.nextToken();
|
||||
if ("-Dprofiling.mode=true".equals(option)) {
|
||||
isProfilingMode = true;
|
||||
}
|
||||
cmdLine.addParameter(option);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,9 +808,17 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
}
|
||||
|
||||
final File workDirectory = getBuildSystemDirectory();
|
||||
workDirectory.mkdirs();
|
||||
ensureLogConfigExists(workDirectory);
|
||||
|
||||
final List<String> cp = ClasspathBootstrap.getBuildProcessApplicationClasspath();
|
||||
cp.add(compilerPath);
|
||||
cp.addAll(myClasspathManager.getCompileServerPluginsClasspath(project));
|
||||
if (isProfilingMode) {
|
||||
cp.add(new File(workDirectory, "yjp-controller-api-redist.jar").getPath());
|
||||
cmdLine.addParameter("-agentlib:yjpagent=disablej2ee,disablealloc,sessionname=ExternalBuild");
|
||||
}
|
||||
|
||||
cmdLine.addParameter("-classpath");
|
||||
cmdLine.addParameter(classpathToString(cp));
|
||||
@@ -815,10 +828,6 @@ public class BuildManager implements ApplicationComponent{
|
||||
cmdLine.addParameter(Integer.toString(port));
|
||||
cmdLine.addParameter(sessionId.toString());
|
||||
|
||||
final File workDirectory = getBuildSystemDirectory();
|
||||
workDirectory.mkdirs();
|
||||
ensureLogConfigExists(workDirectory);
|
||||
|
||||
cmdLine.addParameter(FileUtil.toSystemIndependentName(workDirectory.getPath()));
|
||||
|
||||
cmdLine.setWorkDirectory(workDirectory);
|
||||
|
||||
@@ -91,6 +91,11 @@ final class BuildSession implements Runnable, CanceledStatus {
|
||||
final Ref<Boolean> hasErrors = new Ref<Boolean>(false);
|
||||
final Ref<Boolean> doneSomething = new Ref<Boolean>(false);
|
||||
try {
|
||||
ProfilingHelper profilingHelper = null;
|
||||
if (Utils.IS_PROFILING_MODE) {
|
||||
profilingHelper = new ProfilingHelper();
|
||||
}
|
||||
|
||||
runBuild(new MessageHandler() {
|
||||
public void processMessage(BuildMessage buildMessage) {
|
||||
final CmdlineRemoteProto.Message.BuilderMessage response;
|
||||
@@ -132,6 +137,10 @@ final class BuildSession implements Runnable, CanceledStatus {
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (profilingHelper != null) {
|
||||
profilingHelper.stopProfiling();
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.info(e);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.jetbrains.jps.cmdline;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 12/6/12
|
||||
*/
|
||||
class ProfilingHelper {
|
||||
|
||||
private final Class<?> myControllerClass;
|
||||
private final Object myController;
|
||||
|
||||
ProfilingHelper() throws Exception {
|
||||
myControllerClass = Class.forName("com.yourkit.api.Controller");
|
||||
myController = myControllerClass.newInstance();
|
||||
}
|
||||
|
||||
public void startProfiling() {
|
||||
try {
|
||||
final Method startMethod = myControllerClass.getDeclaredMethod("startCPUProfiling", long.class, String.class);
|
||||
if (startMethod != null) {
|
||||
startMethod.invoke(myController, 4L/*ProfilingModes.CPU_SAMPLING*/, null);
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot find method 'startCPUProfiling' in class " + myControllerClass.getName());
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopProfiling() {
|
||||
try {
|
||||
final Method captureMethod = myControllerClass.getDeclaredMethod("captureSnapshot", long.class);
|
||||
if (captureMethod != null) {
|
||||
final String path = (String)captureMethod.invoke(myController, 0L/*ProfilingModes.SNAPSHOT_WITHOUT_HEAP*/);
|
||||
System.err.println("CPU Snapshot captured: " + path);
|
||||
final Method stopMethod = myControllerClass.getDeclaredMethod("stopCPUProfiling");
|
||||
if (stopMethod != null) {
|
||||
stopMethod.invoke(myController);
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot find method 'stopCPUProfiling' in class " + myControllerClass.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.err.println("Cannot find method 'captureSnapshot' in class " + myControllerClass.getName());
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ public class Utils {
|
||||
public static final Key<Boolean> ERRORS_DETECTED_KEY = Key.create("_errors_detected_");
|
||||
private static volatile File ourSystemRoot = new File(System.getProperty("user.home"), ".idea-build");
|
||||
public static final boolean IS_TEST_MODE = Boolean.parseBoolean(System.getProperty("test.mode", "false"));
|
||||
public static final boolean IS_PROFILING_MODE = Boolean.parseBoolean(System.getProperty("profiling.mode", "false"));
|
||||
|
||||
private Utils() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user