1.本地安装UnderStand工具
2.用java代码调用cmd命令执行 并产生报告
3.UnderStand的cmd命令
und create -languages c++ c:\myDb.udb
und add c:\目录或者文件夹 c:\myDb.udb
und analyze -all c:\myDb.udb
报告:
und report c:\myDb.udb
4.代码如下:
/**
-
@author hxsi
-
@date 2021年06月16日 14:08
/
@Service
@Slf4j
public class UnderStandServiceExt extends OpenStackService {
/*- 环境里面underStand位置
/
@Value(value = “${testtool.underStand}”)
public String underStand;
/* - 文件保存位置
*/
@Value(value = “${testtool.pathJmx}”)
public String pathJmx;
/**
- UnderStand 测试工具
- @param path 测试文件地址
- @return true
*/
public String getUnderStand(String path) throws IOException {
String osName = System.getProperties().getProperty(CommonConstant.OS_NAME).toLowerCase();
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.Y_M_D);
String dateNowStr = sdf.format(new Date());
//报告保存位置
String underStandPath = null;
if (osName.contains(CommonConstant.WINDOWS)) {
underStandPath = pathJmx + dateNowStr + CommonConstant.SYMBOL +CommonConstant.UNDER_STAND + dateNowStr;
}else {
underStandPath = CommonConstant.HOME + dateNowStr + CommonConstant.SYMBOL + CommonConstant.UNDER_STAND + dateNowStr;
}
//判断文件是否存在
File fileJmx = null;
if (osName.contains(CommonConstant.WINDOWS)) {
fileJmx = new File(pathJmx + dateNowStr + CommonConstant.SYMBOL +CommonConstant.UNDER_STAND + dateNowStr);
}else {
fileJmx = new File(CommonConstant.HOME + dateNowStr + CommonConstant.SYMBOL + CommonConstant.UNDER_STAND + dateNowStr);
}
if (fileJmx.exists()){
//有文件就删除
Boolean result = FileUtil.delFiles(fileJmx);
if (!result){
log.error(“文件删除失败”);
return null;
}
}
File file = new File(underStandPath);
if(!file.exists()){
file.mkdirs();
}
file.createNewFile();
//执行cmd 命令
Runtime.getRuntime().exec(CommonConstant.CMD_EXE_START + CommonConstant.UND_CREATE + underStandPath + CommonConstant.SYMBOL + CommonConstant.MYDB_UDB,null,
new File(underStand));
Runtime.getRuntime().exec(CommonConstant.CMD_EXE_START + CommonConstant.UND_ADD + path + underStandPath + CommonConstant.SYMBOL + CommonConstant.MYDB_UDB,null,
new File(underStand));
Runtime.getRuntime().exec(CommonConstant.CMD_EXE_START + CommonConstant.UND_ANALYZE + underStandPath + CommonConstant.SYMBOL + CommonConstant.MYDB_UDB,null,
new File(underStand));
Runtime.getRuntime().exec(CommonConstant.CMD_EXE_START + CommonConstant.UND_REPORT + underStandPath + CommonConstant.SYMBOL + CommonConstant.MYDB_UDB,null,
new File(underStand));
return underStandPath;
}
}
- 环境里面underStand位置
里面的常量都在jmeter文章里面