在离线模式下将 Jprofiler 控制器与 weblogic 进程一起使用
Using Jprofiler Controller with weblogic process in offline mode
我正在尝试根据 demos\api\samples\offline\
示例使用控制器 Java API 以离线模式在 Weblogic 上分析应用程序 运行ning。
我的问题是没有创建 .jps 文件,尽管 Controller.saveSnapshot()
退出时没有错误。
我创建了一个会话配置,当我附加到 GUI 中的进程时它运行良好。
我将 config.xml 文件从 home
复制到工作目录。
我在 server start
中使用以下行更新了我的服务的 JVM 参数:
-agentpath:/home/alex/jprofiler10/bin/linux-x64/libjprofilerti.so=offline,id=116,config=/workdir/config_bak.xml
我创建了一个 Java 程序,它开始 CPU 分析然后结束 CPU 分析并尝试保存分析结果。
Controller.startCPURecording(真);
performProfiledTask();
Controller.stopCPURecording();
字符串 fName = "test.jps";
System.out.println("saving snapshot: "+fName);
Controller.saveSnapshot(新文件(fName));
System.out.println("saved snapshot: "+fName);
程序执行无误,但未创建快照文件。
我尝试使用 sudo 权限 运行 它,结果相同。
编辑:
也许我不明白什么,但在我看来,如果控制器 运行 仅在与分析代码相同的进程中,JProfiler 离线工作。
当它在 different\child 进程中 运行 时,文件未被创建。
例如,我希望创建文件的以下代码并没有这样做。
分析过程:
import java.io.File;
import java.io.IOException;
import com.jprofiler.api.controller.Controller;
//turn on profiling and run a child process with offline profiling enabled in agentpath
public class PerfDemo {
public static void main(String[] args) throws IOException {
System.out.println("Started profiling");
// On startup, JProfiler does not record any data. The various recording subsystems have to be
// switched on programatically.
Controller.startCPURecording(true);
try {
exec(CpuIntensiveProcess.class);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception: "+ex.getStackTrace());
}
// You can switch off recording at any point. Recording can be switched on again.
Controller.stopCPURecording();
saveSnapshot("snapshot.jps");
}
private static void saveSnapshot(String fileName){
System.out.println("saving snapshot: "+fileName);
Controller.saveSnapshot(new File(fileName));
}
//execute a new process with offline profiling enabled in agentpath
public static int exec(Class klass) throws IOException, InterruptedException{
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getName();
ProcessBuilder builder = new ProcessBuilder(
javaBin, "-cp", classpath, "-agentpath:\"c:\\Progra~1\\jprofiler10\\bin\\windows-x64\\jprofilerti.dll\"=offline,id=110,config=config.xml", className );
System.out.println("starting process");
Process process = builder.inheritIO().start();
process.waitFor();
System.out.println("process finished");
return process.exitValue();
}
}
分析过程:
import static java.lang.Math.*;
import java.io.IOException;
public class CpuIntensiveProcess {
public static void main(String[] args) throws IOException {
for (int i=0;i<50000000;i++) {
double d = tan(atan(tan(atan(tan(atan(tan(atan(tan(atan(123456789.123456789))))))))));
double h =d+1;
}
}
}
运行时批处理:
@echo off
SET CLASSPATH=.;jprofiler-controller-10.1.4.jar;agent.jar;
"c:\Program Files\Java\jdk-10.0.1\bin\javac.exe" -cp %CLASSPATH% *.java
java -cp %CLASSPATH% PerfDemo
REM If I run in this configuration, the profiling is of the PerfDemo process and not of the CpuIntensiveProcess process
REM SET AGENTPATH=-agentpath:"c:\Progra~1\jprofiler10\bin\windows-x64\jprofilerti.dll"=offline,id=110,config=config.xml
REM java -cp %CLASSPATH% %AGENTPATH% PerfDemo
set "CURR_DIR=%cd%"
pushd "c:\Program Files\jprofiler10\bin"
jpexport %CURR_DIR%/snapshot.jps -outputdir=%CURR_DIR% HotSpots out.csv
popd
type out.csv
当我 运行 批处理时,没有创建 .jps 文件。
当我 运行 使用 agentpath 的 PerfDemo
进程时,会创建 jps 文件,但分析的是同一进程,而不是其他进程。
输出:
C:\dev\docs\bak\sample_other_process_profiling>profile.bat
Started profiling
Starting child process...
JProfiler> Protocol version 59
JProfiler> Java 9+ detected.
JProfiler> JVMTI version 1.1 detected.
JProfiler> Offline profiling mode.
JProfiler> 64-bit library
JProfiler> Using config file config.xml (id: 110)
JProfiler> Listening on port: 8849.
JProfiler> Enabling native methods instrumentation.
JProfiler> Can retransform classes.
JProfiler> Can retransform any class.
JProfiler> Native library initialized
JProfiler> VM initialized
JProfiler> Retransforming 7 base class files.
JProfiler> Base classes instrumented.
JProfiler> Using instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
Child process finished
Saving snapshot: snapshot.jps
Controller.saveSnapshot finished, snapshot should exist on the disk: snapshot.jps
The snapshot file C:\dev\docs\bak\sample_other_process_profiling\snapshot.jps does not exist.
The system cannot find the file specified.
控制器 class 仅在加载分析代理的 JVM 中起作用,通常通过使用 -agentpath:
VM 参数启动 JVM。
在您的情况下,您在未加载分析代理的进程中调用控制器 class,因此调用无效。此外,这些调用对子进程没有任何影响。
您必须将对控制器的调用 class 移动到子进程中才能使其正常工作。
我正在尝试根据 demos\api\samples\offline\
示例使用控制器 Java API 以离线模式在 Weblogic 上分析应用程序 运行ning。
我的问题是没有创建 .jps 文件,尽管 Controller.saveSnapshot()
退出时没有错误。
我创建了一个会话配置,当我附加到 GUI 中的进程时它运行良好。
我将 config.xml 文件从
home
复制到工作目录。我在
server start
中使用以下行更新了我的服务的 JVM 参数:-agentpath:/home/alex/jprofiler10/bin/linux-x64/libjprofilerti.so=offline,id=116,config=/workdir/config_bak.xml
我创建了一个 Java 程序,它开始 CPU 分析然后结束 CPU 分析并尝试保存分析结果。
Controller.startCPURecording(真);
performProfiledTask();
Controller.stopCPURecording();字符串 fName = "test.jps"; System.out.println("saving snapshot: "+fName); Controller.saveSnapshot(新文件(fName));
System.out.println("saved snapshot: "+fName);
程序执行无误,但未创建快照文件。
我尝试使用 sudo 权限 运行 它,结果相同。
编辑:
也许我不明白什么,但在我看来,如果控制器 运行 仅在与分析代码相同的进程中,JProfiler 离线工作。
当它在 different\child 进程中 运行 时,文件未被创建。
例如,我希望创建文件的以下代码并没有这样做。
分析过程:
import java.io.File;
import java.io.IOException;
import com.jprofiler.api.controller.Controller;
//turn on profiling and run a child process with offline profiling enabled in agentpath
public class PerfDemo {
public static void main(String[] args) throws IOException {
System.out.println("Started profiling");
// On startup, JProfiler does not record any data. The various recording subsystems have to be
// switched on programatically.
Controller.startCPURecording(true);
try {
exec(CpuIntensiveProcess.class);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception: "+ex.getStackTrace());
}
// You can switch off recording at any point. Recording can be switched on again.
Controller.stopCPURecording();
saveSnapshot("snapshot.jps");
}
private static void saveSnapshot(String fileName){
System.out.println("saving snapshot: "+fileName);
Controller.saveSnapshot(new File(fileName));
}
//execute a new process with offline profiling enabled in agentpath
public static int exec(Class klass) throws IOException, InterruptedException{
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getName();
ProcessBuilder builder = new ProcessBuilder(
javaBin, "-cp", classpath, "-agentpath:\"c:\\Progra~1\\jprofiler10\\bin\\windows-x64\\jprofilerti.dll\"=offline,id=110,config=config.xml", className );
System.out.println("starting process");
Process process = builder.inheritIO().start();
process.waitFor();
System.out.println("process finished");
return process.exitValue();
}
}
分析过程:
import static java.lang.Math.*;
import java.io.IOException;
public class CpuIntensiveProcess {
public static void main(String[] args) throws IOException {
for (int i=0;i<50000000;i++) {
double d = tan(atan(tan(atan(tan(atan(tan(atan(tan(atan(123456789.123456789))))))))));
double h =d+1;
}
}
}
运行时批处理:
@echo off
SET CLASSPATH=.;jprofiler-controller-10.1.4.jar;agent.jar;
"c:\Program Files\Java\jdk-10.0.1\bin\javac.exe" -cp %CLASSPATH% *.java
java -cp %CLASSPATH% PerfDemo
REM If I run in this configuration, the profiling is of the PerfDemo process and not of the CpuIntensiveProcess process
REM SET AGENTPATH=-agentpath:"c:\Progra~1\jprofiler10\bin\windows-x64\jprofilerti.dll"=offline,id=110,config=config.xml
REM java -cp %CLASSPATH% %AGENTPATH% PerfDemo
set "CURR_DIR=%cd%"
pushd "c:\Program Files\jprofiler10\bin"
jpexport %CURR_DIR%/snapshot.jps -outputdir=%CURR_DIR% HotSpots out.csv
popd
type out.csv
当我 运行 批处理时,没有创建 .jps 文件。
当我 运行 使用 agentpath 的 PerfDemo
进程时,会创建 jps 文件,但分析的是同一进程,而不是其他进程。
输出:
C:\dev\docs\bak\sample_other_process_profiling>profile.bat
Started profiling
Starting child process...
JProfiler> Protocol version 59
JProfiler> Java 9+ detected.
JProfiler> JVMTI version 1.1 detected.
JProfiler> Offline profiling mode.
JProfiler> 64-bit library
JProfiler> Using config file config.xml (id: 110)
JProfiler> Listening on port: 8849.
JProfiler> Enabling native methods instrumentation.
JProfiler> Can retransform classes.
JProfiler> Can retransform any class.
JProfiler> Native library initialized
JProfiler> VM initialized
JProfiler> Retransforming 7 base class files.
JProfiler> Base classes instrumented.
JProfiler> Using instrumentation
JProfiler> Time measurement: elapsed time
JProfiler> CPU profiling enabled
Child process finished
Saving snapshot: snapshot.jps
Controller.saveSnapshot finished, snapshot should exist on the disk: snapshot.jps
The snapshot file C:\dev\docs\bak\sample_other_process_profiling\snapshot.jps does not exist.
The system cannot find the file specified.
控制器 class 仅在加载分析代理的 JVM 中起作用,通常通过使用 -agentpath:
VM 参数启动 JVM。
在您的情况下,您在未加载分析代理的进程中调用控制器 class,因此调用无效。此外,这些调用对子进程没有任何影响。
您必须将对控制器的调用 class 移动到子进程中才能使其正常工作。