{"id":587,"date":"2013-06-09T15:11:46","date_gmt":"2013-06-09T07:11:46","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=587"},"modified":"2013-09-27T22:36:37","modified_gmt":"2013-09-27T14:36:37","slug":"jmeter-ant%e4%b8%ba%e6%89%a7%e8%a1%8c%e7%bb%93%e6%9e%9c%e6%96%87%e4%bb%b6%e6%b7%bb%e5%8a%a0%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=587","title":{"rendered":"jmeter-ant\u4e3a\u6267\u884c\u7ed3\u679c\u6587\u4ef6\u6dfb\u52a0\u65f6\u95f4"},"content":{"rendered":"<p>jmeter\u53ef\u4ee5\u4f7f\u7528ant\u81ea\u52a8\u5316\u8fd0\u884c\uff0c\u8fd0\u884c\u7ed3\u679c\u53ef\u4ee5\u901a\u8fc7html\u6587\u4ef6\u5c55\u793a\u51fa\u6765\uff0c\u5e76\u4e14\u53ef\u4ee5\u751f\u6210\u65e5\u5fd7jtl\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u5c31\u662f\u6211\u4eec\u7684jmx\u6587\u4ef6\u540d\u3002\u4f46\u662f\u5982\u679c\u60f3\u77e5\u9053\u8fd0\u884c\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\uff0c\u5c31\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5199\u4e86\u4e2ajava\u811a\u672c\uff0c\u89e3\u6790jtl\u6587\u4ef6\uff0c\u53d6\u51fa\u5176\u4e2d\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\u6233\uff0c\u8f6c\u5316\u4e3a\u65e5\u671f\u683c\u5f0f\uff0c\u7136\u540e\u7ed9jtl\u548chtml\u6587\u4ef6\u91cd\u547d\u540d\u3002\u7528\u5230\u4e86dom4j jar\u5305\u3002<!--more--><\/p>\n<pre><code>package com.yeetrack.jmeterAnt;\n\nimport java.io.File;\nimport java.io.InputStream;\nimport java.text.SimpleDateFormat;\nimport java.util.ArrayList;\nimport java.util.Date;\nimport java.util.Iterator;\nimport java.util.List;\n\nimport org.dom4j.Document;\nimport org.dom4j.Element;\nimport org.dom4j.io.SAXReader;\n\n\/**\n* @author youthflies\n* \u5904\u7406jmeter jtl\u6587\u4ef6\uff0c\u89e3\u6790\u91cc\u9762\u7684\u65f6\u95f4\u6233\uff0c\u4e3ajtl\u6587\u4ef6\u548chtml\u6587\u4ef6\u52a0\u4e0a\u8fd0\u884c\u65f6\u95f4\n*\/\npublic class TimeStamp\n{\n\n    private static String resultPath;\n    private static List&lt;File&gt; fileList; \n    public static void main(String[] args)\n    {\n        \/\/\u83b7\u53d6jtl\u6587\u4ef6\u5217\u8868\n        resultPath=(new File(System.getProperty(\"user.dir\"))).getPath()+File.separator+\"results\";\n        fileList = new ArrayList&lt;File&gt;();\n\n        readAllFile(resultPath);\n\n        SAXReader reader = new SAXReader();\n        Document document = null;\n\n        \/\/\u5904\u7406jtl\u6587\u4ef6\n        for(File file : fileList)\n        {\n            \/\/\u8df3\u8fc7\u975ejtl\u6587\u4ef6\n            if(!file.getName().endsWith(\"jtl\"))\n                continue;\n\n            String starTest = null;\n            String endTest = null;\n            try\n            {\n                document = reader.read(file);\n                Element rootElement = document.getRootElement();\n                Iterator&lt;Element&gt; iterator = rootElement.elementIterator();\n                starTest = iterator.next().asXML();\n                while(iterator.hasNext())\n                {\n                    endTest = iterator.next().asXML();\n                }\n\n                int startIndex = starTest.indexOf(\"ts=\\\"\");\n                int endIndex = endTest.indexOf(\"ts=\\\"\");\n                String startTime = starTest.substring(startIndex+4, startIndex+17);\n                String endTime = endTest.substring(endIndex+4, endIndex+17);\n\n                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd-HH-mm-ss\");\n                String startDate = simpleDateFormat.format(Long.parseLong(startTime));\n                String endDate = simpleDateFormat.format(Long.parseLong(endTime));\n                System.out.println(startDate);\n\n                String oldName = file.getAbsolutePath();\n                int startSite = oldName.indexOf(file.getName());\n                String newName = oldName.substring(0, startSite)+startDate+\"~\"+endDate+\"--\"+file.getName();\n\n                \/\/\u91cd\u547d\u540djtl\u6587\u4ef6\n                file.renameTo(new File(newName));\n                \/\/\u91cd\u547d\u540d\u76f8\u5e94\u7684html\u6587\u4ef6\n                String htmlFileName = oldName.toLowerCase().replace(\"jtl\", \"html\");\n                File htmlFile = new File(htmlFileName);\n                int startHtmlSite = htmlFileName.indexOf(htmlFile.getName());\n\n                String newHtmlName = htmlFileName.substring(0, startHtmlSite)+startDate+\"~\"+endDate+\"--\"+file.getName();\n                htmlFile.renameTo(new File(newHtmlName));\n\n            } catch (Exception e)\n            {\n                \/\/ TODO: handle exception\n            }\n        }\n        System.out.println(\"\u6dfb\u52a0\u65f6\u95f4\u6233\u5b8c\u6bd5\");\n    }\n\n    private static void readAllFile(String path)\n    {\n        File dirFile = new File(path);\n        File[] resultFiles = dirFile.listFiles();\n        for(File file : resultFiles)\n        {\n            if(file.isDirectory())\n                readAllFile(file.getAbsolutePath());\n            else\n            {\n                if(!file.getName().contains(\"~\"))\n                fileList.add(file);\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<p>\u5c06\u4ee3\u7801\u5bfc\u6210\u53ef\u6267\u884cjar\u5305\uff0c\u653e\u5728libs\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p>\u786e\u8ba4\u4e0b\uff0cjmeter\u7684jtl\u6587\u4ef6\u662fxml\u6587\u4ef6\u683c\u5f0f\u7684\uff0cbuild.xml\u6587\u4ef6\uff0c\u586b\u4e0a\u8fd9\u4e00\u53e5<code>&lt;property name=\"jmeter.save.saveservice.output_format\" value=\"xml\"\/&gt;<\/code><\/p>\n<pre><code>&lt;target name=\"test\" &gt;\n&lt;basename property=\"jmx.filename\" file=\"${jmxfile}\" suffix=\".jmx\"\/&gt;\n&lt;echo message=\"---------- Processing ${jmxfile} -----------\"\/&gt;\n&lt;echo message=\"resultlogdir===${resultBase}\/temp\/${results.jtl}\"\/&gt;\n&lt;jmeter jmeterhome=\"${jmeter-home}\" resultlogdir=\"${resultBase}\/temp\/${results.jtl}\" runremote=\"${runremote}\" resultlog=\"${report.datestamp}${jmx.filename}.jtl\"\n        testplan=\"${jmxs.dir}\/${jmx.filename}.jmx\"&gt;\n    &lt;property name=\"jmeter.save.saveservice.output_format\" value=\"xml\"\/&gt;\n    &lt;!--&lt;property name=\"jmeter.save.saveservice.response_data\" value=\"true\"\/&gt;--&gt;\n    &lt;jvmarg value=\"-Xincgc\"\/&gt;\n    &lt;jvmarg value=\"-Xms2048m\"\/&gt;\n    &lt;jvmarg value=\"-Xmx2048m\"\/&gt;  \n<\/code><\/pre>\n<p>build.xml\u4e2d\u6267\u884c\u6211\u4eec\u7684jar\u5305:<\/p>\n<pre><code>&lt;target name=\"timestamp\" depends=\"copy-images\"&gt;\n&lt;java classname=\"com.baidu.jmeterAnt.TimeStamp\"&gt;\n&lt;classpath&gt;\n    &lt;path location=\"libs\/timestamp.jar\"&gt;&lt;\/path&gt;\n&lt;\/classpath&gt;\n&lt;\/java &gt;\n&lt;\/target&gt; \n<\/code><\/pre>\n<p>Ok,\u8fd9\u6837ant\u6267\u884c\u51fa\u6765\u7684\u6587\u4ef6\u540d\uff0c<code>2013-06-08-20-40-48~2013-06-08-20-40-48--baidu-10.jtl<\/code>, <code>2013-06-08-21-16-38~2013-06-08-21-16-39--itebeta-10.html<\/code>\u3002\u65b9\u4fbf\u77e5\u6653\u8fd0\u884c\u65f6\u95f4\uff0c\u76d1\u63a7\u670d\u52a1\u5668\u72b6\u6001\u3002<\/p>\n<p><a title=\"jenkins+ant+jmeter\u81ea\u52a8\u5316\u6027\u80fd\u6d4b\u8bd5\u5e73\u53f0\" href=\"https:\/\/www.yeetrack.com\/?p=558\">jenkins+ant+jmeter\u81ea\u52a8\u5316\u6027\u80fd\u6d4b\u8bd5\u5e73\u53f0<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>jmeter\u53ef\u4ee5\u4f7f\u7528ant\u81ea\u52a8\u5316\u8fd0\u884c\uff0c\u8fd0\u884c\u7ed3\u679c\u53ef\u4ee5\u901a\u8fc7html\u6587\u4ef6\u5c55\u793a\u51fa\u6765\uff0c\u5e76\u4e14\u53ef\u4ee5\u751f\u6210\u65e5\u5fd7jtl\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u5c31\u662f\u6211\u4eec\u7684jmx\u6587\u4ef6\u540d\u3002\u4f46\u662f\u5982\u679c\u60f3\u77e5\u9053\u8fd0\u884c\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\uff0c\u5c31\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5199\u4e86\u4e2ajava\u811a\u672c\uff0c&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[8,7,42,41],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-coding","tag-java","tag-7","tag-42","tag-41"],"views":4363,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=587"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":589,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions\/589"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}