IBM 的 Java 诊断,第 4 部分: 使用分析模块扩展 IBM Dump Analyzer for Java
2010-04-01 00:00:00 来源:WEB开发网实现 IAnalyze 的分析程序
在 Eclipse 中创建实现 IAnalyze 接口的分析模块时,要使用 New Class 向导(右键单击在 设置 一节 中创建的包并选择 New > Class)。在出现的向导中,输入以下信息:
Name:DWAnalyze
Superclass:使用 Browse 按钮添加 com.ibm.dtfj.analyzer.base.AnalyzerBase
Interfaces:使用 Add 按钮添加 com.ibm.dtfj.analyzer.ext.IAnalyze
单击 Finish 即可使用 stub 方法创建 DWAnalyze 分析程序类。
要继续该示例,输入清单 1 所示的代码。这个简单的示例可以确定被分析的转储是否是在多处理器机器上创建的。
清单 1. 实现 IAnalyze 的分析程序
package mypackage;
import com.ibm.dtfj.analyzer.base.AnalyzerBase;
import com.ibm.dtfj.analyzer.ext.IAnalyze;
import com.ibm.dtfj.image.DTFJException;
import com.ibm.dtfj.image.Image;
import com.ibm.util.SimpleVector;
/**
* This is the basic design required to implement an IAnalyze Interface
*/
public class DWAnalyze extends AnalyzerBase implements IAnalyze {
private static String description = "Check the number of processors";
/*
* This rule checks if the processor count is greater than 1
*/
private static String[] multiProcessorRules = {
"processorCount > 1 TRUE"
};
/**
* An analyzer to report if the dump was produced on a multiprocessor machine
*/
public DWAnalyze() {
defineRule("isMultiProcessor",multiProcessorRules);
}
/* (non-Javadoc)
* @see com.ibm.dtfj.analyzer.base.AnalyzerBase#getShortDescription()
*/
public String getShortDescription() {
return description;
}
/* (non-Javadoc)
* @see com.ibm.dtfj.analyzer.ext.IAnalyze#doAnalysis()
*/
public String[] doAnalysis() {
return checkProcessors(getContext().getCurrentImage());
}
/**
* This function uses the getProcessorCount() function from the Image class
* and then adds an entry into the ret[] array for parsing through the analysisRules[]
* array. The format for passing through the analysisRules needs to be of the type
* name=value
*/
private String[] checkProcessors(Image image) {
ret = null;
try {
int procNum = image.getProcessorCount();
ret = new String[1];
ret[0] = "processorCount=" + procNum;
} catch (DTFJException e) {
handleError("No processor information",e);
}
return ret;
}
}
更多精彩
赞助商链接