Permalink
Browse files

tiny memory allocation improvements

Contributed by  Benoit Wiart (b.wiart at ubik-ingenierie.com).
this closes #229 on github

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1761608 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
pmouawad committed Sep 20, 2016
1 parent bdfdf37 commit 4b9a73aa41f720bb5b0449ba767f00de263ea820
@@ -237,11 +237,11 @@ private static StringBuilder doubleToSb(DecimalFormat dfDouble, StringBuilder sb
private static String format(String name, SummariserRunningSample summariserRunningSample, String type) { private static String format(String name, SummariserRunningSample summariserRunningSample, String type) {
DecimalFormat dfDouble = new DecimalFormat("#0.0"); // $NON-NLS-1$ DecimalFormat dfDouble = new DecimalFormat("#0.0"); // $NON-NLS-1$
StringBuilder tmp = new StringBuilder(20); // for intermediate use StringBuilder tmp = new StringBuilder(20); // for intermediate use
StringBuilder sb = new StringBuilder(100); // output line buffer StringBuilder sb = new StringBuilder(140); // output line buffer
sb.append(name); sb.append(name);
sb.append(" "); sb.append(' ');
sb.append(type); sb.append(type);
sb.append(" "); sb.append(' ');
sb.append(longToSb(tmp, summariserRunningSample.getNumSamples(), 6)); sb.append(longToSb(tmp, summariserRunningSample.getNumSamples(), 6));
sb.append(" in "); sb.append(" in ");
long elapsed = summariserRunningSample.getElapsed(); long elapsed = summariserRunningSample.getElapsed();
@@ -263,7 +263,7 @@ private static String format(String name, SummariserRunningSample summariserRunn
sb.append(longToSb(tmp, summariserRunningSample.getErrorCount(), 5)); sb.append(longToSb(tmp, summariserRunningSample.getErrorCount(), 5));
sb.append(" ("); sb.append(" (");
sb.append(summariserRunningSample.getErrorPercentageString()); sb.append(summariserRunningSample.getErrorPercentageString());
sb.append(")"); sb.append(')');
if ("+".equals(type)) { if ("+".equals(type)) {
ThreadCounts tc = JMeterContextService.getThreadCounts(); ThreadCounts tc = JMeterContextService.getThreadCounts();
sb.append(" Active: "); sb.append(" Active: ");
@@ -91,7 +91,7 @@ private String join(String[] strings) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0;i<strings.length;i++){ for (int i=0;i<strings.length;i++){
if (i>0) { if (i>0) {
sb.append(" "); sb.append(' ');
} }
sb.append(strings[i]); sb.append(strings[i]);
} }
@@ -116,15 +116,15 @@ private static void printDetails(java.io.PrintStream ps, String s, Throwable t,
StringBuilder sb = new StringBuilder(80); StringBuilder sb = new StringBuilder(80);
sb.append("Log: "); sb.append("Log: ");
sb.append(tn); sb.append(tn);
if (c.length()>0){ if (c.length()>0) {
sb.append(" "); sb.append(' ');
sb.append(c); sb.append(c);
} else { } else {
sb.append(DEFAULT_SEPARATOR); sb.append(DEFAULT_SEPARATOR);
} }
sb.append(s); sb.append(s);
if (t != null) { if (t != null) {
sb.append(" "); sb.append(' ');
ps.print(sb.toString()); ps.print(sb.toString());
t.printStackTrace(ps); t.printStackTrace(ps);
} else { } else {
@@ -148,7 +148,7 @@ static synchronized void logDetails(Logger l, String s, String prio, Throwable t
StringBuilder sb = new StringBuilder(40); StringBuilder sb = new StringBuilder(40);
sb.append(tn); sb.append(tn);
if (c.length()>0){ if (c.length()>0){
sb.append(" "); sb.append(' ');
sb.append(c); sb.append(c);
} else { } else {
sb.append(DEFAULT_SEPARATOR); sb.append(DEFAULT_SEPARATOR);
@@ -286,11 +286,11 @@ public synchronized void setParameters(Collection<CompoundVariable> parameters)
sb.append("setParameters(");//$NON-NLS-1$ sb.append("setParameters(");//$NON-NLS-1$
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
if (i > 0) { if (i > 0) {
sb.append(","); sb.append(',');
} }
sb.append(((CompoundVariable) values[i]).getRawParameters()); sb.append(((CompoundVariable) values[i]).getRawParameters());
} }
sb.append(")");//$NON-NLS-1$ sb.append(')');//$NON-NLS-1$
log.info(sb.toString()); log.info(sb.toString());
// N.B. setParameters is called before the test proper is started, // N.B. setParameters is called before the test proper is started,
@@ -168,9 +168,8 @@ private JOrphanUtils() {
} }
private static final String SPACES = " "; private static final char[] SPACES_CHARS = " ".toCharArray();
private static final int SPACES_LEN = SPACES_CHARS.length;
private static final int SPACES_LEN = SPACES.length();
/** /**
* Right aligns some text in a StringBuilder N.B. modifies the input buffer * Right aligns some text in a StringBuilder N.B. modifies the input buffer
@@ -189,7 +188,7 @@ public static StringBuilder rightAlign(StringBuilder in, int len) {
if (pfx > SPACES_LEN) { if (pfx > SPACES_LEN) {
pfx = SPACES_LEN; pfx = SPACES_LEN;
} }
in.insert(0, SPACES.substring(0, pfx)); in.insert(0, SPACES_CHARS, 0, pfx);
return in; return in;
} }
@@ -210,7 +209,7 @@ public static StringBuilder leftAlign(StringBuilder in, int len) {
if (sfx > SPACES_LEN) { if (sfx > SPACES_LEN) {
sfx = SPACES_LEN; sfx = SPACES_LEN;
} }
in.append(SPACES.substring(0, sfx)); in.append(SPACES_CHARS, 0, sfx);
return in; return in;
} }
@@ -427,7 +426,7 @@ public static String baToHexString(byte[] ba) {
for (byte b : ba) { for (byte b : ba) {
int j = b & 0xff; int j = b & 0xff;
if (j < 16) { if (j < 16) {
sb.append("0"); // $NON-NLS-1$ add zero padding sb.append('0'); // $NON-NLS-1$ add zero padding
} }
sb.append(Integer.toHexString(j)); sb.append(Integer.toHexString(j));
} }
@@ -449,7 +448,7 @@ public static String baToHexString(byte[] ba, char separator) {
} }
int j = ba[i] & 0xff; int j = ba[i] & 0xff;
if (j < 16) { if (j < 16) {
sb.append("0"); // $NON-NLS-1$ add zero padding sb.append('0'); // $NON-NLS-1$ add zero padding
} }
sb.append(Integer.toHexString(j)); sb.append(Integer.toHexString(j));
} }
@@ -33,7 +33,7 @@
public class Cookie extends AbstractTestElement implements Serializable { public class Cookie extends AbstractTestElement implements Serializable {
private static final long serialVersionUID = 240L; private static final long serialVersionUID = 240L;
private static final String TAB = "\t"; private static final char TAB = '\t';
private static final String VALUE = "Cookie.value"; //$NON-NLS-1$ private static final String VALUE = "Cookie.value"; //$NON-NLS-1$
@@ -164,7 +164,7 @@ public void onUrlDeclaration(
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (Iterator<URL> iterator = urlCollection.iterator(); iterator.hasNext();) { for (Iterator<URL> iterator = urlCollection.iterator(); iterator.hasNext();) {
URL urlString = iterator.next(); URL urlString = iterator.next();
builder.append(urlString).append(","); builder.append(urlString).append(',');
} }
LOG.debug("Parsed:"+baseUrl+", got:"+builder.toString()); LOG.debug("Parsed:"+baseUrl+", got:"+builder.toString());
} }
@@ -359,18 +359,18 @@ private static String getAttributeValue(NamedNodeMap att, String attName) {
private static String printNode(Node node) { private static String printNode(Node node) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("<"); // $NON-NLS-1$ buf.append('<'); // $NON-NLS-1$
buf.append(node.getNodeName()); buf.append(node.getNodeName());
NamedNodeMap atts = node.getAttributes(); NamedNodeMap atts = node.getAttributes();
for (int x = 0; x < atts.getLength(); x++) { for (int x = 0; x < atts.getLength(); x++) {
buf.append(" "); // $NON-NLS-1$ buf.append(' '); // $NON-NLS-1$
buf.append(atts.item(x).getNodeName()); buf.append(atts.item(x).getNodeName());
buf.append("=\""); // $NON-NLS-1$ buf.append("=\""); // $NON-NLS-1$
buf.append(atts.item(x).getNodeValue()); buf.append(atts.item(x).getNodeValue());
buf.append("\""); // $NON-NLS-1$ buf.append("\""); // $NON-NLS-1$
} }
buf.append(">"); // $NON-NLS-1$ buf.append('>'); // $NON-NLS-1$
return buf.toString(); return buf.toString();
} }
@@ -715,9 +715,9 @@ public String toString() {
if (hasProxy) { if (hasProxy) {
sb.append(" via "); sb.append(" via ");
sb.append(proxyUser); sb.append(proxyUser);
sb.append("@"); sb.append('@');
sb.append(proxyHost); sb.append(proxyHost);
sb.append(":"); sb.append(':');
sb.append(proxyPort); sb.append(proxyPort);
} }
return sb.toString(); return sb.toString();
@@ -977,13 +977,13 @@ private String getResponseHeaders(HttpResponse response, HttpContext localContex
private void writeResponseHeader(StringBuilder headerBuffer, Header responseHeader) { private void writeResponseHeader(StringBuilder headerBuffer, Header responseHeader) {
if(responseHeader instanceof BufferedHeader) { if(responseHeader instanceof BufferedHeader) {
CharArrayBuffer buffer = ((BufferedHeader)responseHeader).getBuffer(); CharArrayBuffer buffer = ((BufferedHeader)responseHeader).getBuffer();
headerBuffer.append(buffer.buffer(), 0, buffer.length()).append("\n"); // $NON-NLS-1$; headerBuffer.append(buffer.buffer(), 0, buffer.length()).append('\n'); // $NON-NLS-1$;
} }
else { else {
headerBuffer.append(responseHeader.getName()) headerBuffer.append(responseHeader.getName())
.append(": ") // $NON-NLS-1$ .append(": ") // $NON-NLS-1$
.append(responseHeader.getValue()) .append(responseHeader.getValue())
.append("\n"); // $NON-NLS-1$ .append('\n'); // $NON-NLS-1$
} }
} }
@@ -147,20 +147,20 @@ public String getSamplerData() {
if (u != null) { if (u != null) {
sb.append(' '); sb.append(' ');
sb.append(u.toString()); sb.append(u.toString());
sb.append("\n"); sb.append('\n');
// Include request body if it is a post or put or patch // Include request body if it is a post or put or patch
if (!METHODS_WITHOUT_BODY.contains(method)) { if (!METHODS_WITHOUT_BODY.contains(method)) {
sb.append("\n"+method+" data:\n"); sb.append("\n").append(method).append(" data:\n");
sb.append(queryString); sb.append(queryString);
sb.append("\n"); sb.append('\n');
} }
if (cookies.length()>0){ if (cookies.length()>0){
sb.append("\nCookie Data:\n"); sb.append("\nCookie Data:\n");
sb.append(cookies); sb.append(cookies);
} else { } else {
sb.append("\n[no cookies]"); sb.append("\n[no cookies]");
} }
sb.append("\n"); sb.append('\n');
} }
final String sampData = super.getSamplerData(); final String sampData = super.getSamplerData();
if (sampData != null){ if (sampData != null){
@@ -952,7 +952,7 @@ public URL getUrl() throws MalformedURLException {
} else { } else {
// HTTP URLs must be absolute, allow file to be relative // HTTP URLs must be absolute, allow file to be relative
if (!path.startsWith("/")) { // $NON-NLS-1$ if (!path.startsWith("/")) { // $NON-NLS-1$
pathAndQuery.append("/"); // $NON-NLS-1$ pathAndQuery.append('/'); // $NON-NLS-1$
} }
} }
pathAndQuery.append(path); pathAndQuery.append(path);
@@ -344,4 +344,16 @@ public void testIsBlank() {
assertTrue(JOrphanUtils.isBlank(" ")); assertTrue(JOrphanUtils.isBlank(" "));
assertFalse(JOrphanUtils.isBlank(" zdazd dzd ")); assertFalse(JOrphanUtils.isBlank(" zdazd dzd "));
} }
@Test
public void testRightAlign() {
StringBuilder in = new StringBuilder("AZE");
assertEquals(" AZE", JOrphanUtils.rightAlign(in, 6).toString());
in = new StringBuilder("AZERTY");
assertEquals("AZERTY", JOrphanUtils.rightAlign(in, 6).toString());
in = new StringBuilder("baulpismuth");
assertEquals("baulpismuth", JOrphanUtils.rightAlign(in, 6).toString());
in = new StringBuilder("A");
assertEquals(" A", JOrphanUtils.rightAlign(in, 8).toString());
}
} }
View
@@ -159,6 +159,7 @@ Summary
<li><bug>60085</bug>Remove cache for prepared statements, as it didn't work with the current jdbc pool implementation and current jdbc drivers should support caching of prepared statements themselves.</li> <li><bug>60085</bug>Remove cache for prepared statements, as it didn't work with the current jdbc pool implementation and current jdbc drivers should support caching of prepared statements themselves.</li>
<li><bug>60137</bug>In Distributed testing when using StrippedXXXX modes strip response also on error</li> <li><bug>60137</bug>In Distributed testing when using StrippedXXXX modes strip response also on error</li>
<li><bug>60106</bug>Settings defaults : Switch "jmeter.save.saveservice.connect_time" to true (after 3.0)</li> <li><bug>60106</bug>Settings defaults : Switch "jmeter.save.saveservice.connect_time" to true (after 3.0)</li>
<li><pr>229</pr> tiny memory allocation improvements. Contributed by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
</ul> </ul>
<ch_section>Non-functional changes</ch_section> <ch_section>Non-functional changes</ch_section>

0 comments on commit 4b9a73a

Please sign in to comment.