到目前为止,我找到的最好的匹配方法是从命令行使用ruby-prof,并尝试从那里猜测图形读数。
require 'ruby-prof'
# Profile the code
RubyProf.start
...
[code to profile]
...
result = RubyProf.stop
# Print a flat profile to text
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
这种方法的主要问题是,您必须修改代码才能看到分析,而且可读性不是很好。
我也尝试过
我想要分析一个小应用程序执行的某个部分。有没有一种方法可以从要分析的应用程序中触发VisualVM中的数据收集?换句话说,是否可以将代码添加到已分析的应用程序中,以便一旦命中此代码,VisualVM中的分析将自动启动?
meaninglessCode();
// How to start data collection?
com.sun.tools.visualvm.....startSampling();
//
codeToBeProfiled();
// How to stop data collection?
com.sun.tools.visualvm.....stopSampl