我有以下的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);
}
}
这会在控制台上输出结果。我该怎样将结果写入文件呢?Btrace不允许创建新对象。
(显然的解决方法是重定向到文件。另一个选择是使用VisualVM btrace插件,然后输出将进入visualVM窗口。不确定它是否能够处理非常大的输出,比如500Mb左右。)
谢谢。
C#
/仅限Windows,并且质量很差)如何实际用于解决最初问题。更重要的是,与仅将命令行输出重定向到文件(例如“btrace ... > btrace.log”)相比,有哪些优势? - IInspectable