Skip to content

Commit

Permalink
Merge pull request jenkinsci#8 from AntonGoley/master
Browse files Browse the repository at this point in the history
New Jmeter parser for Jmeter Summariser logs
  • Loading branch information
manolo committed Jun 20, 2012
2 parents e9b4882 + caebae8 commit 4c3caef
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 32 deletions.
44 changes: 43 additions & 1 deletion src/main/java/hudson/plugins/performance/HttpSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public class HttpSample implements Comparable<HttpSample> {

private String httpCode = "";

// Summarizer fields
private long summarizerMin;

private long summarizerMax;

private float summarizerErrors;

private long summarizerSamples;


public long getDuration() {
return duration;
}
Expand All @@ -35,6 +45,22 @@ public String getHttpCode() {
return httpCode;
}

public long getSummarizerSamples() {
return summarizerSamples;
}

public long getSummarizerMin() {
return summarizerMin;
}

public long getSummarizerMax() {
return summarizerMax;
}

public float getSummarizerErrors() {
return summarizerErrors;
}

public boolean isFailed() {
return !isSuccessful();
}
Expand Down Expand Up @@ -62,7 +88,23 @@ public void setUri(String uri) {
public void setHttpCode(String httpCode) {
this.httpCode = httpCode;
}


public void setSummarizerSamples(long summarizerSamples) {
this.summarizerSamples = summarizerSamples;
}

public void setSummarizerMin(long summarizerMin) {
this.summarizerMin = summarizerMin;
}

public void setSummarizerMax(long summarizerMax) {
this.summarizerMax = summarizerMax;
}

public void setSummarizerErrors(float summarizerErrors) {
this.summarizerErrors= summarizerErrors;
}

public int compareTo(HttpSample o) {
return (int) (getDuration() - o.getDuration());
}
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/hudson/plugins/performance/JmeterSummarizerParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package hudson.plugins.performance;

import hudson.Extension;
import hudson.util.IOException2;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import org.kohsuke.stapler.DataBoundConstructor;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileNotFoundException;

/**
* Created by IntelliJ IDEA.
* User: Agoley
* Date: 06.02.2012
* Time: 12:45:24
* To change this template use File | Settings | File Templates.
*/
public class JmeterSummarizerParser extends PerformanceReportParser{


@Extension
public static class DescriptorImpl extends PerformanceReportParserDescriptor {
@Override
public String getDisplayName() {
return "JmeterSummarizer";
}
}

@DataBoundConstructor
public JmeterSummarizerParser(String glob) {
super(glob);
}

@Override
public String getDefaultGlobPattern() {
return "**/*.log";
}


public Collection<PerformanceReport> parse(AbstractBuild<?, ?> build,
Collection<File> reports, TaskListener listener) {
List<PerformanceReport> result = new ArrayList<PerformanceReport>();

PrintStream logger = listener.getLogger();
for (File f : reports) {
try {
final PerformanceReport r = new PerformanceReport();
r.setReportFileName(f.getName());
logger.println("Performance: Parsing JMeterSummarizer report file " + f.getName());

Scanner s = new Scanner(f);
Map<String, HttpSample> map = new HashMap<String, HttpSample>();
String key;
String line;
while ( s.hasNextLine() ) {
line=s.nextLine().replaceAll("="," ");

if (!line.contains ("+")) {
Scanner scanner= new Scanner(line);
HttpSample sample = new HttpSample();

//set Date !!!! stub. not Ffrom log
sample.setDate(new Date (Long.valueOf("1296876799179")));

scanner.findInLine("jmeter.reporters.Summariser:");
key=scanner.next();

// set SamplesCount
scanner.findInLine(key);
sample.setSummarizerSamples(scanner.nextLong());
// set response time
scanner.findInLine("Avg:");
sample.setDuration(scanner.nextLong());
sample.setSuccessful(true);
// set MIN
scanner.findInLine("Min:");
sample.setSummarizerMin(scanner.nextLong());
// set MAX
scanner.findInLine("Max:");
sample.setSummarizerMax(scanner.nextLong());
// set errors count
scanner.findInLine("Err:");
scanner.nextInt();
sample.setSummarizerErrors( Float.valueOf(scanner.next().replaceAll("[()%]","")));
//sample.setSummarizerErrors(Long.valueOf(scanner.next()));

sample.setUri(key);
map.put(key,sample);
}
}
for (String method:map.keySet()) {
r.addSample(map.get(method));
}

result.add(r);

}catch (FileNotFoundException e) {
logger.println("File not found" + e.getMessage());
}catch (SAXException e) {
logger.println(e.getMessage());
}
}

return result;

}

}
138 changes: 138 additions & 0 deletions src/main/java/hudson/plugins/performance/PerformanceProjectAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hudson.util.ShiftedCategoryAxis;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;


import java.awt.BasicStroke;
import java.awt.Color;
import java.io.File;
Expand All @@ -30,12 +31,16 @@
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.Stapler;



public final class PerformanceProjectAction implements Action {

Expand All @@ -44,6 +49,7 @@ public final class PerformanceProjectAction implements Action {

private static final String PLUGIN_NAME = "performance";


private static final long serialVersionUID = 1L;

/** Logger. */
Expand Down Expand Up @@ -167,6 +173,45 @@ protected static JFreeChart createRespondingTimeChart(CategoryDataset dataset) {
return chart;
}


protected static JFreeChart createSummarizerChart (CategoryDataset dataset, String yAxis, String chartTitle) {

final JFreeChart chart = ChartFactory.createBarChart(
chartTitle, // chart title
null, // unused
yAxis, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
true // urls
);

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = chart.getCategoryPlot();

plot.setBackgroundPaint(Color.WHITE);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);

CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
renderer.setBaseStroke(new BasicStroke(4.0f));
renderer.setItemMargin(0);
renderer.setMaximumBarWidth(0.05);


return chart;
}


public void doErrorsGraph(StaplerRequest request, StaplerResponse response)
throws IOException {
PerformanceReportPosition performanceReportPosition = new PerformanceReportPosition();
Expand Down Expand Up @@ -263,6 +308,75 @@ public void doRespondingTimeGraph(StaplerRequest request,
createRespondingTimeChart(dataSetBuilderAverage.build()), 400, 200);
}


public void doSummarizerGraph(StaplerRequest request,
StaplerResponse response) throws IOException {

PerformanceReportPosition performanceReportPosition = new PerformanceReportPosition();
request.bindParameters(performanceReportPosition);
String performanceReportNameFile = performanceReportPosition.getPerformanceReportPosition();
if (performanceReportNameFile == null) {
if (getPerformanceReportList().size() == 1) {
performanceReportNameFile = getPerformanceReportList().get(0);
} else {
return;
}
}
if (ChartUtil.awtProblemCause != null) {
// not available. send out error message
//response.sendRedirect2(request.getContextPath() + "/images/headless.png");
return;
}
DataSetBuilder<NumberOnlyBuildLabel, String> dataSetBuilderSummarizer = new DataSetBuilder<NumberOnlyBuildLabel, String>();
DataSetBuilder<NumberOnlyBuildLabel, String> dataSetBuilderSummarizerErrors = new DataSetBuilder<NumberOnlyBuildLabel, String>();

List<?> builds = getProject().getBuilds();
List<Integer> buildsLimits = getFirstAndLastBuild(request, builds);

int nbBuildsToAnalyze = builds.size();
for (Iterator<?> iterator = builds.iterator(); iterator.hasNext();) {
AbstractBuild<?, ?> currentBuild = (AbstractBuild<?, ?>) iterator.next();
if (nbBuildsToAnalyze <= buildsLimits.get(1)
&& buildsLimits.get(0) <= nbBuildsToAnalyze) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(currentBuild);
PerformanceBuildAction performanceBuildAction = currentBuild.getAction(PerformanceBuildAction.class);
if (performanceBuildAction == null) {
continue;
}
PerformanceReport performanceReport = performanceBuildAction.getPerformanceReportMap().getPerformanceReport(
performanceReportNameFile);


if (performanceReport == null) {
nbBuildsToAnalyze--;
continue;
}

for (String key:performanceReport.getUriReportMap().keySet()) {
Long methodAvg=performanceReport.getUriReportMap().get(key).getHttpSampleList().get(0).getDuration();
float methodErrors= performanceReport.getUriReportMap().get(key).getHttpSampleList().get(0).getSummarizerErrors();
dataSetBuilderSummarizer.add(methodAvg, label, key);
dataSetBuilderSummarizerErrors.add(methodErrors, label, key);
};
}

nbBuildsToAnalyze--;
}


String summarizerReportType = performanceReportPosition.getSummarizerReportType();
if (summarizerReportType != null) {
ChartUtil.generateGraph(request, response,
createSummarizerChart(dataSetBuilderSummarizerErrors.build(),"%",Messages.ProjectAction_PercentageOfErrors()), 400, 200);
}
else {
ChartUtil.generateGraph(request, response,
createSummarizerChart(dataSetBuilderSummarizer.build(),"ms",Messages.ProjectAction_RespondingTime()), 400, 200);
}

}


/**
* <p>
* give a list of two Integer : the smallest build to use and the biggest.
Expand Down Expand Up @@ -356,9 +470,11 @@ public List<String> getPerformanceReportList() {
} else {
this.performanceReportList.add(entry.getName());
}

}

Collections.sort(performanceReportList);

return this.performanceReportList;
}

Expand Down Expand Up @@ -474,4 +590,26 @@ private DataSetBuilder getTrendReportData(final StaplerRequest request,
}
return dataSet;
}
public boolean ifSummarizerParserUsed(String filename) {

boolean b = false;
String fileExt="";

List<PerformanceReportParser> list = project.getPublishersList().get(PerformancePublisher.class).getParsers();

for ( int i=0; i < list.size(); i++) {
if (list.get(i).getDescriptor().getDisplayName()=="JmeterSummarizer") {
fileExt = list.get(i).glob;
String parts[] = fileExt.split("\\s*[;:,]+\\s*");
for (String path : parts) {
if (filename.endsWith(path.substring(5))) {
b=true;
}
}
}
}

return b;
}

}
Loading

0 comments on commit 4c3caef

Please sign in to comment.