jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1436725 - in /jmeter/trunk: src/core/org/apache/jmeter/save/CSVSaveService.java xdocs/changes.xml xdocs/usermanual/listeners.xml
Date Tue, 22 Jan 2013 01:59:13 GMT
Author: sebb
Date: Tue Jan 22 01:59:13 2013
New Revision: 1436725

URL: http://svn.apache.org/viewvc?rev=1436725&view=rev
Log:
CSVSaveService does not handle date parsing very well
Bugzilla Id: 54459

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/listeners.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java?rev=1436725&r1=1436724&r2=1436725&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/save/CSVSaveService.java Tue Jan 22 01:59:13 2013
@@ -99,9 +99,15 @@ public final class CSVSaveService {
     static private final SampleSaveConfiguration _saveConfig = SampleSaveConfiguration
             .staticConfig();
 
-    // Date format to try if the time format does not parse as milliseconds
-    // (this is the suggested value in jmeter.properties)
-    private static final String DEFAULT_DATE_FORMAT_STRING = "MM/dd/yy HH:mm:ss"; // $NON-NLS-1$
+    // Date formats to try if the time format does not parse as milliseconds
+    private static final String DATE_FORMAT_STRINGS[] = {
+        "yyyy/MM/dd HH:mm:ss.SSSS",  // $NON-NLS-1$
+        "yyyy/MM/dd HH:mm:ss",  // $NON-NLS-1$
+        "yyyy-MM-dd HH:mm:ss.SSSS",  // $NON-NLS-1$
+        "yyyy-MM-dd HH:mm:ss",  // $NON-NLS-1$
+
+        "MM/dd/yy HH:mm:ss"  // $NON-NLS-1$ (for compatibility, this is the original default)
+        };
 
     private static final String LINE_SEP = System.getProperty("line.separator"); // $NON-NLS-1$
 
@@ -199,17 +205,29 @@ public final class CSVSaveService {
                 text = parts[i++];
                 if (saveConfig.printMilliseconds()) {
                     try {
-                        timeStamp = Long.parseLong(text);
-                    } catch (NumberFormatException e) {// see if this works
+                        timeStamp = Long.parseLong(text); // see if this works
+                    } catch (NumberFormatException e) { // it did not, let's try some other
formats
                         log.warn(e.toString());
-                        // method is only ever called from one thread at a time
-                        // so it's OK to use a static DateFormat
-                        SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT_STRING);
-                        Date stamp = dateFormat.parse(text);
-                        timeStamp = stamp.getTime();
-                        log.warn("Setting date format to: "
-                                + DEFAULT_DATE_FORMAT_STRING);
-                        saveConfig.setFormatter(dateFormat);
+                        boolean foundMatch = false;
+                        for(String fmt : DATE_FORMAT_STRINGS) {
+                            SimpleDateFormat dateFormat = new SimpleDateFormat(fmt);
+                            dateFormat.setLenient(false);
+                            try {
+                                Date stamp = dateFormat.parse(text);
+                                timeStamp = stamp.getTime();
+                                // method is only ever called from one thread at a time
+                                // so it's OK to use a static DateFormat
+                                log.warn("Setting date format to: " + fmt);
+                                saveConfig.setFormatter(dateFormat);
+                                foundMatch = true;
+                                break;
+                            } catch (ParseException e1) {
+                                log.info(text+" did not match "+fmt);
+                            }
+                        }
+                        if (!foundMatch) {
+                            throw new ParseException("No date-time format found matching
"+text,-1);
+                        }
                     }
                 } else if (saveConfig.formatter() != null) {
                     Date stamp = saveConfig.formatter().parse(text);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1436725&r1=1436724&r2=1436725&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Jan 22 01:59:13 2013
@@ -75,6 +75,7 @@ Earlier changes are detailed in the <a h
 <h4>HTTP Proxy Server does not force user to select the type of Sampler in HTTP Sampler
Settings, this allows easier switch between implementations as Sampler do not have this information
set anymore</h4>
 <h4>SamplerCreator interface to meet new requirements for plug-in providers</h4>
 <h4>It is now possible to create binary sampler for x-www-form-urlencoded POST request
by modifying proxy.binary.types property to add application/x-www-form-urlencoded </h4>
+<h4>Improved timestamp format auto-detection when reading CSV files</h4>
 
 <!--  =================== Known bugs =================== -->
 
@@ -172,6 +173,7 @@ and right angle bracket (&gt;) in search
 <li><bugzilla>54166</bugzilla> - ViewResultsTree could not render the HTML
response: handle failure to parse HTML</li>
 <li><bugzilla>54287</bugzilla> - Incorrect Timestamp in Response Time Graph
when using a date with time in Date format field</li>
 <li><bugzilla>54451</bugzilla> - Response Time Graph reports wrong times
when the are many samples for same time</li>
+<li><bugzilla>54459</bugzilla> - CSVSaveService does not handle date parsing
very well</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>

Modified: jmeter/trunk/xdocs/usermanual/listeners.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/listeners.xml?rev=1436725&r1=1436724&r2=1436725&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/listeners.xml (original)
+++ jmeter/trunk/xdocs/usermanual/listeners.xml Tue Jan 22 01:59:13 2013
@@ -152,7 +152,7 @@ The full set of properties that affect r
 # Timestamp format
 # legitimate values: none, ms, or a format suitable for SimpleDateFormat
 #jmeter.save.saveservice.timestamp_format=ms
-#jmeter.save.saveservice.timestamp_format=MM/dd/yy HH:mm:ss
+#jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
 
 # Put the start time stamp in logs instead of the end
 sampleresult.timestamp.start=true
@@ -195,9 +195,19 @@ sampleresult.timestamp.start=true
 The date format to be used for the timestamp_format is described in <a
 HREF="http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html">
 <b>SimpleDateFormat</b></a>.
-Bear in mind that choosing a date format other than "ms" is likely to
-make it impossible for JMeter to interpret the value when it is read
-in later for viewing purposes.</p>
+The timestamp format is used for both writing and reading files.
+If the format is set to "ms", and the column does not parse as a long integer,
+JMeter (2.9+) will try the following formats:
+<ul>
+<li>yyyy/MM/dd HH:mm:ss.SSSS</li>
+<li>yyyy/MM/dd HH:mm:ss</li>
+<li>yyyy-MM-dd HH:mm:ss.SSSS</li>
+<li>yyyy-MM-dd HH:mm:ss</li>
+<li>MM/dd/yy HH:mm:ss (this is for compatibility with previous versions; it is not
recommended as a format)</li>
+</ul> 
+Matching is now also strict (non-lenient).
+JMeter 2.8 and earlier used lenient mode which could result in timestamps with incorrect
dates 
+(times were usually correct).</p>
 <subsection name="&sect-num;.1.1 Sample Variables" anchor="sample_variables">
 <p>
 Versions of JMeter after 2.3.1 allow one to use the <b>sample_variables</b> 



Mime
View raw message