Permalink
Browse files

Merge pull request #6 from NarcisDavins/master

Expand information shown by performance report map
  • Loading branch information...
2 parents 5549a83 + 493cfe4 commit d9f3672e0fe6f91371a8cf3ca1ef53a37d4e5bdb @manolo manolo committed Apr 11, 2012
@@ -29,9 +29,8 @@ public AbstractReport() {
public String errorPercentFormated() {
Stapler.getCurrentRequest().getLocale();
return percentFormat.format(errorPercent());
-
}
-
+
abstract public long getAverage();
public String getAverageFormated() {
@@ -59,4 +58,16 @@ public String getMaxFormated() {
abstract public long getMin();
abstract public int size();
+
+ abstract public String getHttpCode();
+
+ abstract public long getAverageDiff();
+
+ abstract public long getMedianDiff();
+
+ abstract public double getErrorPercentDiff();
+
+ abstract public String getLastBuildHttpCodeIfChanged();
+
+ abstract public int getSizeDiff();
}
@@ -16,6 +16,8 @@
private Date date;
private String uri;
+
+ private String httpCode = "";
public long getDuration() {
return duration;
@@ -28,6 +30,10 @@ public Date getDate() {
public String getUri() {
return uri;
}
+
+ public String getHttpCode() {
+ return httpCode;
+ }
public boolean isFailed() {
return !isSuccessful();
@@ -52,9 +58,12 @@ public void setDate(Date time) {
public void setUri(String uri) {
this.uri = uri;
}
-
+
+ public void setHttpCode(String httpCode) {
+ this.httpCode = httpCode;
+ }
+
public int compareTo(HttpSample o) {
return (int) (getDuration() - o.getDuration());
}
-
}
@@ -98,6 +98,8 @@ public void startElement(String uri, String localName, String qName,
? attributes.getValue("s") : attributes.getValue("success")));
sample.setUri(attributes.getValue("lb") != null
? attributes.getValue("lb") : attributes.getValue("label"));
+ sample.setHttpCode(attributes.getValue("rc") != null && attributes.getValue("rc").length() <= 3
+ ? attributes.getValue("rc") : "0" );
if (counter == 0) {
currentSample = sample;
}
@@ -31,6 +31,8 @@
* {@link UriReport}s keyed by their {@link UriReport#getStaplerUri()}.
*/
private final Map<String, UriReport> uriReportMap = new LinkedHashMap<String, UriReport>();
+
+ private PerformanceReport lastBuildReport;
public void addSample(HttpSample pHttpSample) throws SAXException {
String uri = pHttpSample.getUri();
@@ -110,6 +112,10 @@ public long getMedian() {
}
return result;
}
+
+ public String getHttpCode() {
+ return "";
+ }
public AbstractBuild<?, ?> getBuild() {
return buildAction.getBuild();
@@ -180,4 +186,49 @@ public int size() {
}
return size;
}
+
+ public void setLastBuildReport( PerformanceReport lastBuildReport ) {
+ Map<String, UriReport> lastBuildUriReportMap = lastBuildReport.getUriReportMap();
+ for (Map.Entry<String, UriReport> item : uriReportMap.entrySet()) {
+ UriReport lastBuildUri = lastBuildUriReportMap.get( item.getKey() );
+ if ( lastBuildUri != null ) {
+ item.getValue().addLastBuildUriReport( lastBuildUri );
+ } else {
+ }
+ }
+ this.lastBuildReport = lastBuildReport;
+ }
+
+ public long getAverageDiff() {
+ if ( lastBuildReport == null ) {
+ return 0;
+ }
+ return getAverage() - lastBuildReport.getAverage();
+ }
+
+ public long getMedianDiff() {
+ if ( lastBuildReport == null ) {
+ return 0;
+ }
+ return getMedian() - lastBuildReport.getMedian();
+ }
+
+ public double getErrorPercentDiff() {
+ if ( lastBuildReport == null ) {
+ return 0;
+ }
+ return errorPercent() - lastBuildReport.errorPercent();
+ }
+
+ public String getLastBuildHttpCodeIfChanged() {
+ return "";
+ }
+
+ public int getSizeDiff() {
+ if ( lastBuildReport == null ) {
+ return 0;
+ }
+ return size() - lastBuildReport.size();
+ }
+
}
@@ -41,7 +41,9 @@
*/
private Map<String, PerformanceReport> performanceReportMap = new LinkedHashMap<String, PerformanceReport>();
private static final String PERFORMANCE_REPORTS_DIRECTORY = "performance-reports";
-
+
+ private static AbstractBuild<?, ?> currentBuild = null;
+
/**
* Parses the reports and build a {@link PerformanceReportMap}.
*
@@ -208,8 +210,8 @@ public void addAll(Collection<PerformanceReport> parse) {
private void parseReports(AbstractBuild<?, ?> build, TaskListener listener, PerformanceReportCollector collector, final String filename) throws IOException {
File repo = new File(build.getRootDir(),
- PerformanceReportMap.getPerformanceReportDirRelativePath());
-
+ PerformanceReportMap.getPerformanceReportDirRelativePath());
+
// files directly under the directory are for JMeter, for compatibility reasons.
File[] files = repo.listFiles(new FileFilter() {
@@ -251,8 +253,45 @@ public boolean accept(File dir, String name) {
}
}
}
+
+ addPreviousBuildReports();
}
-
+
+ private void addPreviousBuildReports() {
+
+ // Avoid parsing all builds.
+ if ( PerformanceReportMap.currentBuild == null ) {
+ PerformanceReportMap.currentBuild = getBuild();
+ }else {
+ if( PerformanceReportMap.currentBuild != getBuild() ) {
+ PerformanceReportMap.currentBuild = null;
+ return;
+ }
+ }
+
+ AbstractBuild<?, ?> previousBuild = getBuild().getPreviousBuild();
+ if ( previousBuild == null ) {
+ return;
+ }
+
+ PerformanceBuildAction previousPerformanceAction = previousBuild.getAction(PerformanceBuildAction.class);
+ if ( previousPerformanceAction == null ) {
+ return;
+ }
+
+ PerformanceReportMap previousPerformanceReportMap = previousPerformanceAction.getPerformanceReportMap();
+ if (previousPerformanceReportMap == null) {
+ return;
+ }
+
+ for (Map.Entry<String, PerformanceReport> item : getPerformanceReportMap().entrySet()) {
+ PerformanceReport lastReport = previousPerformanceReportMap.getPerformanceReportMap().get( item.getKey() );
+ if ( lastReport != null ) {
+ item.getValue().setLastBuildReport( lastReport );
+ }
+ }
+ }
+
private interface PerformanceReportCollector {
public void addAll(Collection<PerformanceReport> parse);
@@ -21,7 +21,7 @@ public final String getId() {
* Returns all the registered {@link PerformanceReportParserDescriptor}s.
*/
public static DescriptorExtensionList<PerformanceReportParser, PerformanceReportParserDescriptor> all() {
- return Hudson.getInstance().getDescriptorList(PerformanceReportParser.class);
+ return Hudson.getInstance().<PerformanceReportParser, PerformanceReportParserDescriptor>getDescriptorList(PerformanceReportParser.class);
}
public static PerformanceReportParserDescriptor getById(String id) {
@@ -5,9 +5,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
/**
* A report about a particular tested URI.
@@ -34,6 +32,8 @@
* as a token in URL.
*/
private final String staplerUri;
+
+ private UriReport lastBuildUriReport;
private String uri;
@@ -84,6 +84,18 @@ public long get90Line() {
}
return result;
}
+
+ public String getHttpCode() {
+ String result = "";
+
+ for (HttpSample currentSample : httpSampleList) {
+ if ( !result.matches( ".*"+currentSample.getHttpCode()+".*" ) ) {
+ result += ( result.length() > 1 ) ? ","+currentSample.getHttpCode() : currentSample.getHttpCode();
+ }
+ }
+
+ return result;
+ }
public long getMedian() {
long result = 0;
@@ -134,6 +146,13 @@ public String getUri() {
return uri;
}
+ public String getShortUri() {
+ if ( uri.length() > 130 ) {
+ return uri.substring( 0, 129 );
+ }
+ return uri;
+ }
+
public boolean isFailed() {
return countErrors() != 0;
}
@@ -154,4 +173,48 @@ public String encodeUriReport() throws UnsupportedEncodingException {
return URLEncoder.encode(sb.toString(), "UTF-8");
}
+ public void addLastBuildUriReport( UriReport lastBuildUriReport ) {
+ this.lastBuildUriReport = lastBuildUriReport;
+ }
+
+ public long getAverageDiff() {
+ if ( lastBuildUriReport == null ) {
+ return 0;
+ }
+ return getAverage() - lastBuildUriReport.getAverage();
+ }
+
+ public long getMedianDiff() {
+ if ( lastBuildUriReport == null ) {
+ return 0;
+ }
+ return getMedian() - lastBuildUriReport.getMedian();
+ }
+
+ public double getErrorPercentDiff() {
+ if ( lastBuildUriReport == null ) {
+ return 0;
+ }
+ return errorPercent() - lastBuildUriReport.errorPercent();
+ }
+
+ public String getLastBuildHttpCodeIfChanged() {
+ if ( lastBuildUriReport == null ) {
+ return "";
+ }
+
+ if ( lastBuildUriReport.getHttpCode().equals(getHttpCode()) ) {
+ return "";
+ }
+
+ return lastBuildUriReport.getHttpCode();
+ }
+
+ public int getSizeDiff() {
+ if ( lastBuildUriReport == null ) {
+ return 0;
+ }
+ return size() - lastBuildUriReport.size();
+ }
+
}
@@ -12,7 +12,7 @@
<tr class="${h.ifThenElse(uriReport.failed,'red','')}">
<td class="left">
<a href="./uriReport/${uriReport.encodeUriReport()}">
- <st:out value="${uriReport.getUri()}" />
+ <st:out value="${uriReport.getShortUri()}" />
</a>
</td>
<jm:summaryTable it="${uriReport}" />
@@ -16,11 +16,13 @@
<h3>${%Performance samples}</h3>
<table class="sortable source" border="1">
<th>${%URI}</th>
+ <th>${%Http Code}</th>
<th>${%Time}</th>
<th>${%Duration} (ms)</th>
<j:forEach var="c" items="${it.httpSampleList}">
<tr class="${h.ifThenElse(c.failed,'red','')}">
<td class="left">${c.uri}</td>
+ <td>${c.httpCode}</td>
<td class="center">${c.date}</td>
<td>${c.duration} ms.</td>
</tr>
@@ -4,11 +4,17 @@
<tr>
<th>${%URI}</th>
<th>${%samples}</th>
+ <th>${%samples diff}</th>
<th>${%Average} (ms)</th>
+ <th>${%Average diff} (ms)</th>
<th>${%Median} (ms)</th>
+ <th>${%Median diff} (ms)</th>
<th>${%Line90} (ms)</th>
<th>${%Minimun} (ms)</th>
<th>${%Maximun} (ms)</th>
+ <th>${%Http Code}</th>
+ <th>${%Previous Http Code}</th>
<th>${%Errors} (%)</th>
+ <th>${%Errors diff} (%)</th>
</tr>
</j:jelly>
@@ -1,8 +1,12 @@
-Max=Máx
+Max=M\u00e1x
samples=Peticiones
+samples\ diff=Diferencia peticiones
Median=Mediana
-Line90=Línea 90%
+Median\ diff=Variaci\u00f3n de la mediana
+Line90=L\u00ednea 90%
Average=Media
+Average\ diff=Variaci\u00f3n de la media
URI=URI
Errors=Errores
-Min=Mín
+Errors\ diff=Variaci\u00f3n de errores
+Min=M\u00edn
@@ -2,10 +2,16 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:jm="/hudson/plugins/performance/tags">
<td>${it.size()}</td>
+ <td class="${h.ifThenElse(it.getSizeDiff()>=0,'green','red')}">${it.getSizeDiff()}</td>
<td>${it.getAverage()}</td>
+ <td class="${h.ifThenElse(it.getAverageDiff()>0,'red','green')}">${it.getAverageDiff()}</td>
<td>${it.getMedian()}</td>
+ <td class="${h.ifThenElse(it.getMedianDiff()>0,'red','green')}">${it.getMedianDiff()}</td>
<td>${it.get90Line()}</td>
<td>${it.getMin()}</td>
<td>${it.getMax()}</td>
+ <td>${it.getHttpCode()}</td>
+ <td>${it.getLastBuildHttpCodeIfChanged()}</td>
<td>${it.errorPercent()} %</td>
+ <td class="${h.ifThenElse(it.getErrorPercentDiff()>0,'red','green')}">${it.getErrorPercentDiff()} %</td>
</j:jelly>
Oops, something went wrong.

0 comments on commit d9f3672

Please sign in to comment.