本文介绍了用于SampleResult.subResult的Jmeter Graph Listener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将输出SamplerRequest对象的子结果的jmeter图形侦听器。我还没有找到一个,我非常渴望得到它。

解决方案

老问题,我知道。

不幸的是,没有JMeter图形侦听器将绘制附加到SampleResult的子结果的结果。刚刚面对同样的问题,我选择自己写。



步骤:


  1. 将下面的类作为jar编译。

  2. 将jar放入jMeter的lib / ext文件夹中。打开您的测试计划,浏览菜单以正常添加监听器,选择SubResult Distributed Response Graph。
  3. 运行您的测试计划。

类:

下面的类将提供一个响应时间分布图,它只能显示子结果。

  public class SubResultDistributedResponseTimeListener extends DistributionGraphVisualizer {

private static final Logger LOG = LoggingManager.getLoggerForClass();

@Override
public void add(final SampleResult res){
final List< SampleResult> subResults = Arrays.asList(res.getSubResults());
final SubResultDistributedResponseTimeListener inst = this;

(SampleResult r:subResults){
long time = r.getEndTime(){
public void run(){
) - r.getStartTime();
LOG.info(Adding result; start:+ r.getStartTime()+end:+ r.getEndTime()+duration:+ time);
SamplingStatCalculator model = inst.getCustomModel();
if(model!= null){
model.addSample(r);
inst.updateGui(model.getCurrentSample());
}
}
}
});

}

//我们需要这个,因为DistributionGraphVisualizer有一个私有字段'模型',其中
//处理更新屏幕。小心
//访问私有字段的SecurityManager问题。
public SamplingStatCalculator getCustomModel(){
try {
Field f = DistributionGraphVisualizer.class.getDeclaredField(model);
f.setAccessible(true);
return(SamplingStatCalculator)f.get(this);
} catch(NoSuchFieldException e){
e.printStackTrace();
} catch(SecurityException e){
e.printStackTrace();
} catch(IllegalArgumentException e){
e.printStackTrace();
} catch(IllegalAccessException e){
e.printStackTrace();
}
返回null;
}

@Override
public String getName(){
returnSubResult Distributed Response Graph;
}

@Override
public String getStaticLabel(){
return this.getName();
}

@Override
public String getLabelResource(){//将此侦听器名称添加到右键单击上下文菜单。
返回this.getName();
}

注意,这个丑陋的catch块是因为我必须在Java 1.5中编译。



我会让读者根据需要扩展不同的图形监听器。


I am looking for a jmeter graph listener that will output the subresults of a SamplerRequest object. I haven't found one yet and I'm very keen on getting it.

解决方案

Old question, I know.

Unfortunately, it appears that there are no JMeter graph listeners that will graph the results of sub results attached to a SampleResult. Having just been faced with the same problem, I chose to write my own.

Steps:

  1. Compile the below class as a jar.
  2. Place the jar in jMeter's lib/ext folder.
  3. Open your test plan, navigate through the menu's to add a Listener as normal, selecting "SubResult Distributed Response Graph"
  4. Run your test plan.

Classes:

The below class will provide a Response Time Distribution graph, that will only graph Sub Results.

public class SubResultDistributedResponseTimeListener extends DistributionGraphVisualizer {

private static final Logger LOG = LoggingManager.getLoggerForClass();

@Override
public void add(final SampleResult res) {
    final List<SampleResult> subResults = Arrays.asList(res.getSubResults());
    final SubResultDistributedResponseTimeListener inst = this;

    JMeterUtils.runSafe(new Runnable() {
        public void run() {
            for (SampleResult r : subResults) {
                long time = r.getEndTime() - r.getStartTime();
                LOG.info("Adding result; start: " + r.getStartTime() + " end: " + r.getEndTime() + " duration: " + time);
                SamplingStatCalculator model = inst.getCustomModel();
                if (model != null) {
                    model.addSample(r);
                    inst.updateGui(model.getCurrentSample());
                }
            }
        }
    });

}

// we need this because DistributionGraphVisualizer has a private field 'model' which
// deals with updating the screen. Watch out for SecurityManager problems with 
// accessing private fields.
public SamplingStatCalculator getCustomModel() {
    try {
        Field f = DistributionGraphVisualizer.class.getDeclaredField("model");
        f.setAccessible(true);
        return (SamplingStatCalculator) f.get(this);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }  catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}

@Override
public String getName() {
    return "SubResult Distributed Response Graph";
}

@Override
public String getStaticLabel() {
    return this.getName();
}

@Override
public String getLabelResource() { // add this Listeners name to the right click context menu.
    return this.getName();
}

NB, the horrendously ugly catch block was because I had to compile in Java 1.5.

I'll leave it to the reader to extend different graph listeners should they wish.

这篇关于用于SampleResult.subResult的Jmeter Graph Listener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 18:02