在BTrace文档中提到BTrace在空闲时几乎没有开销.这是否意味着BTrace仅具有开销,并且仅在满足某些探测并且正在处理时?
此外,在处理Probe时,需要一些CPU来进行处理.但它是否会对JVM内存或任何其他可能影响原始JVM进程处理的事情产生影响?
我有跟随btrace脚本.我想记录特定类中函数的进入和退出.
..
package com.sun.btrace.samples;
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.*;
@BTrace class Profiling {
@Property
Profiler swingProfiler = BTraceUtils.Profiling.newProfiler();
@OnMethod(
clazz="com.pkg.classname",
method="/.*/")
void entry(@ProbeMethodName(fqn=true) String probeMethod) {
BTraceUtils.print("Entry" );
BTraceUtils.println(BTraceUtils.timestamp() );
BTraceUtils.println(probeMethod);
}
@OnMethod(
clazz="com.pkg.classname",
location=@Location(value=Kind.RETURN)
)
void exit(@ProbeMethodName(fqn=true) String probeMethod, @Duration long duration) {
BTraceUtils.print("Exit:" );
BTraceUtils.println(BTraceUtils.timestamp() );
BTraceUtils.println(probeMethod);
}
}
Run Code Online (Sandbox Code Playgroud)
这在控制台上提供了outout.我怎么能把结果写到文件?Btrace不允许创建新对象.
(显而易见的解决方法是重定向到文件.另一种选择是使用VisualVM btrace插件 - 然后输出到visualVM窗口.请注意它是否处理非常大的输出500Mb左右.)
谢谢
我正在尝试衡量 JVM 代理对性能的影响,以确保它不会使我们尝试运行的测试无效(并且可能会从 prod 中获取一些样本)。此案例是一组将在自动负载测试期间运行的 BTrace 脚本,但该问题可能对任何代理都是通用的。
为了运行基准测试,我建立了一个小型 JMH 项目并将代理附加为:
java -javaagent:/home/ssube/btrace/build/btrace-agent.jar=scriptdir=/home/ssube/btrace/scripts/,port=0 -jar benchmarks.jar
Run Code Online (Sandbox Code Playgroud)
这样做会导致每次 JMH fork JVM 时出现以下错误:
# Run progress: 0.00% complete, ETA 00:02:00
# Fork: 1 of 1
Exception in thread "main" java.lang.IllegalArgumentException: org.openjdk.jmh.runner.options.CommandLineOptions; local class incompatible: stream classdesc serialVersionUID = 8906142321598115825, local class serialVersionUID = 7529911323947566771
at org.openjdk.jmh.runner.ForkedMain.main(ForkedMain.java:72)
<binary link had failed, forked VM corrupted the stream? Use EXTRA verbose to print exception>
<forked VM failed with exit code 1>
<stdout last='10 lines'>
</stdout>
<stderr last='10 …Run Code Online (Sandbox Code Playgroud) 所以我向 btrace 介绍自己,但目前我没有从中得到任何输出。使用此脚本:
包 com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class AllLines {
@OnMethod(
clazz="/.*/",
location=@Location(value=Kind.LINE, line=-1)
)
public static void online(@ProbeClassName String pcn, @ProbeMethodName String pmn, int line) {
print(Strings.strcat(pcn, "."));
print(Strings.strcat(pmn, ":"));
println(line);
}
}
Run Code Online (Sandbox Code Playgroud)
这直接来自示例目录,只是出于绝望而更改了“clazz =“/。*/”,以打印出一些东西。没运气。
我指向 btrace 的 pid 是一个简单的 java 程序,我开发的只是为了测试目的,它在循环中调用某个方法。我正在通过 Eclipse 运行它。
任何想法我可能会错过什么?谢谢!
更新:打开调试模式,发现它挂在“调试:检查端口可用性:2020”。有任何想法吗 ?
查看方法“methodExit”。参数“@Duration long time”中包含哪些时间单位?
package com.sun.btrace.samples;
import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import java.awt.EventQueue;
import java.awt.AWTEvent;
import java.awt.event.FocusEvent;
@BTrace
public class AllMethods {
@OnMethod(
clazz="java.awt.EventQueue",
method="dispatchEvent",
location=@Location(Kind.RETURN))
public static void methodExit(@Duration long time, @ProbeMethodName String pmn) {
println(pmn + " " + (time / 1000000));
}
}
Run Code Online (Sandbox Code Playgroud)