问题
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:
- Compile the below class as a jar.
- Place the jar in jMeter's lib/ext folder.
- Open your test plan, navigate through the menu's to add a Listener as normal, selecting "SubResult Distributed Response Graph"
- 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