Jmeter Graph Listener for SampleResult.subResult

限于喜欢 提交于 2020-01-06 16:20:36

问题


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.


回答1:


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.




回答2:


The only option I know is Hits Per Second graph, it plots results and subresults, but only from Transaction Controllers, not embedded resources. You may ask authors to implement a new graph...



来源:https://stackoverflow.com/questions/8272926/jmeter-graph-listener-for-sampleresult-subresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!