Java 如何在jmeter加载运行后编辑summary.csv文件
运行负载测试后,Jmeter将结果生成到“summary.csv”上。Java 如何在jmeter加载运行后编辑summary.csv文件,java,csv,jmeter,performance-testing,beanshell,Java,Csv,Jmeter,Performance Testing,Beanshell,运行负载测试后,Jmeter将结果生成到“summary.csv”上。 此文件中的某些URL如下所示: 1482255989405,3359,POST ...users/G0356GM7QOITIMGA/... 1482255989479,3310,POST ...users/HRC50JG3T524N9RN/... 1482255989488,3354,POST ...users/54QEGZB54BEWOCJJ/... 其中“…users/G0356GM7QOITIMGA/…”-其URL列
此文件中的某些URL如下所示:
1482255989405,3359,POST ...users/G0356GM7QOITIMGA/...
1482255989479,3310,POST ...users/HRC50JG3T524N9RN/...
1482255989488,3354,POST ...users/54QEGZB54BEWOCJJ/...
其中“…users/G0356GM7QOITIMGA/…”-其URL列。之后,我尝试使用以下命令生成jmeter报告:
jmeter -g summary.csv -o report
但是,此操作会抛出内存不足异常(因为有许多不同的URL)。因此,我决定编辑拆卸线程组中的summary.csv,并使用BeanShell采样器将所有ID替换为“someID”字符串:
import java.io.*;
import org.apache.jmeter.services.FileServer;
try {
String sep = System.getProperty("line.separator");
String summaryFileDirPath = FileServer.getFileServer().getBaseDir() + File.separator;
String summaryFilePath = summaryFileDirPath + "summary.csv";
log.info("read " + summaryFilePath);
File file = new File(summaryFilePath);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
String text = "";
while ((line = reader.readLine()) != null) {
text += line + sep;
}
reader.close();
log.info(summaryFilePath);
file.delete();
FileWriter writer = new FileWriter(summaryFileDirPath + "summary.csv", false);
writer.write(text.replaceAll("users/[A-Z0-9]*/", "users/EUCI/"));
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
结果:似乎Jmeter在拆卸线程组结束工作后追加了一些行。
仅使用jmeter脚本在测试运行后如何编辑summary.csv文件?
备注:我只需要在summary.csv中收集结果。这里有一个JMeter属性-
JMeter.save.saveservice.autoflush
,很可能您遇到了它的默认值false
# AutoFlush on each line written in XML or CSV output
# Setting this to true will result in less test results data loss in case of Crash
# but with impact on performances, particularly for intensive tests (low or no pauses)
# Since JMeter 2.10, this is false by default
#jmeter.save.saveservice.autoflush=false
您至少可以通过两种方式替代该值:
-J
命令行参数将其传递给JMeter,如下所示:
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t ....
有关JMeter属性及其使用方法的全面信息,请参阅文章。提示:格式化问题。请花1分钟来正确缩进源代码。你想让我们花时间帮助你。。。因此,请您尽可能简单明了地回答。谢谢您的评论。我已经格式化了脚本。谢谢你的回答。这对我有帮助。我还有一个问题:-是否可以禁用“BeanShell Sampler”登录summary.csv?
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t ....