【问题标题】:How to edit summary.csv file after jmeter load runjmeter加载运行后如何编辑summary.csv文件
【发布时间】:2016-12-21 09:37:17
【问题描述】:

运行我的负载测试后,Jmeter 将结果生成到“summary.csv”。
此文件中的一些网址如下所示:

1482255989405,3359,POST ...users/G0356GM7QOITIMGA/...
1482255989479,3310,POST ...users/HRC50JG3T524N9RN/...
1482255989488,3354,POST ...users/54QEGZB54BEWOCJJ/...

其中“...users/G0356GM7QOITIMGA/...” - 它的 URL 列。
之后,我尝试使用以下命令生成 jmeter-report:

jmeter -g summary.csv -o report

但是,此操作会引发内存不足异常(由于许多不同的 URL)。
所以我决定编辑 tearDown 线程组 中的 summary.csv 并使用 BeanShell Sampler 将所有 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();
    }

结果:
summary.csv screen

似乎 Jmeter 在 tearDown 线程组 结束工作后追加了一些行。
如何在仅使用 jmeter 脚本进行测试运行后编辑 summary.csv 文件?
PS:我只需要在summary.csv中收集结果

【问题讨论】:

  • 提示:格式很重要。请花 1 分钟时间正确缩进您的源代码。您希望我们花时间为您提供帮助……所以请尽可能简单直接地完成。
  • 感谢您的评论。我已经格式化了脚本。

标签: java csv jmeter performance-testing beanshell


【解决方案1】:

有一个 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

您可以通过至少 2 种方式覆盖该值:

  1. 将下一行添加到 user.properties 文件:

    jmeter.save.saveservice.autoflush=true
    
  2. 通过-J 命令行参数将其传递给JMeter,例如:

    jmeter -Jjmeter.save.saveservice.autoflush=true -n -t ....
    

请参阅Apache JMeter Properties Customization Guide 文章,了解有关 JMeter 属性及其使用方式的全面信息

【讨论】:

  • 感谢您的回答。这对我有帮助。我还有一个问题: - 是否可以禁用“BeanShell Sampler”登录到 summary.csv? Topic for this question
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2016-03-22
  • 2022-12-11
  • 2014-12-14
  • 1970-01-01
相关资源
最近更新 更多