欢迎访问『www.cnblogs.com/blog-ice』

jp@gc Thread Group
1.BeanShell Sampler
String threads = "${__BeanShell(ctx.getThreadGroup().getNumThreads())}";
vars.put("threads", threads);
//log.info("-----------get---------threadsCount={}", threads);
//log.info("-----------get---------threadIndex=${__threadNum}");

2.BeanShell PostProcessor
${__setProperty(threads,${threads},)};
//log.info("-----set prop----${__P(threads)}");

3.tearDown Thread Group
BeanShell Sampler
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

// Set Env Var "JMETER_HOME=xxx"
// Set Aggregate Report path = "jtl path"
// Config Global Var for Thread Num
// Generate report Path = "root/yyyy-MM-dd/HH-mm-ss---threads/*.html"
String root = "E:\\\\xxx\\\\result\\\\";
String jtl = root + "Aggregate-Report-tem.jtl";


LocalDateTime now = LocalDateTime.now();
String today = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
String todayTime = DateTimeFormatter.ofPattern("HH-mm-ss").format(now);
String threads = "${__property(threads,,)}";

log.info("===>" + today + " " + todayTime+ " " + threads);


log.info("root={}", root);
String reportPath = root + today + "\\\\" + todayTime + "---" + threads + "\\\\";
File dir = new File(root + today);
if (!dir.exists()) {
dir.mkdir();
new File(reportPath).mkdir();
}
log.info("reportPath={}", reportPath);

String jmeterHome = System.getenv("JMETER_HOME");
String jmeterBat = jmeterHome + "\\\\bin\\\\jmeter.bat";
Object[] params = {jmeterBat, jtl, reportPath};
String cmd = String.format("%s -g %s -o %s", params);

log.info("cmd={}", cmd);
log.info("Html Report Path is : [{}]", reportPath);

try {
Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
log.error("----------->" + e.getMessage());
}

log.info("-----------> end" );

posted on 2022-01-03 12:34  仙路尽头谁为峰  阅读(119)  评论(0编辑  收藏  举报
这里是自由发挥的天堂