--- /dev/null
+package org.tizen.common;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.FileWriter;\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+import java.text.MessageFormat;\r
+import java.text.ParseException;\r
+import java.util.ArrayList;\r
+\r
+public class LogConverter\r
+{\r
+ protected static final String PATTERN = "[{0}][PERFORM_E] {1}({2}) - [Category: {3} Variable: {4}] at {5} {6} [{7}(ms)]";\r
+\r
+ protected static final MessageFormat FORMAT = new MessageFormat( PATTERN );\r
+ \r
+ protected class TestCase {\r
+ protected String className;\r
+ protected String name;\r
+ protected String time;\r
+ \r
+ public TestCase(String className, String name, String time)\r
+ {\r
+ super();\r
+ this.className = className;\r
+ this.name = name;\r
+ this.time = time;\r
+ }\r
+\r
+\r
+\r
+ @Override\r
+ public String toString()\r
+ {\r
+ return "<testcase classname=\"" + className + "\" name=\"" + name + "\" time=\"" + time + "\" />";\r
+ }\r
+ }\r
+\r
+ public static\r
+ void\r
+ main(\r
+ final String[] args\r
+ ) throws IOException\r
+ {\r
+ if ( args.length < 2 )\r
+ {\r
+ return ;\r
+ }\r
+ \r
+ final File from = new File( args[0] );\r
+ if ( !from.exists() || from.isDirectory() || !from.canRead() )\r
+ {\r
+ return ;\r
+ }\r
+ \r
+ final File to = new File( args[1] );\r
+ if ( from.isDirectory() || !from.canWrite() )\r
+ {\r
+ return ;\r
+ }\r
+ \r
+ final LogConverter instance = new LogConverter();\r
+ instance.convert( new FileReader( from ), new FileWriter( to ) );\r
+ \r
+ }\r
+ \r
+ protected\r
+ String[]\r
+ parse(\r
+ final String line\r
+ )\r
+ {\r
+ try\r
+ {\r
+ final Object[] args = FORMAT.parse( line );\r
+ if ( args.length < 8 )\r
+ {\r
+ return null;\r
+ }\r
+ final String category = (String) args[3];\r
+ final String variable = (String) args[4];\r
+ final String time = (String) args[7];\r
+ return new String[] { category, variable, time };\r
+ }\r
+ catch ( ParseException e )\r
+ {\r
+ return null;\r
+ }\r
+ \r
+ }\r
+ \r
+ protected\r
+ void\r
+ convert(\r
+ final Reader reader,\r
+ final Writer writer\r
+ )\r
+ throws IOException\r
+ {\r
+ final BufferedReader lineReader = new BufferedReader( reader );\r
+ String line = null;\r
+ final ArrayList<TestCase> testCases = new ArrayList<TestCase>();\r
+ long time = 0;\r
+ while ( null != ( line = lineReader.readLine() ) )\r
+ {\r
+ final String[] args = parse( line );\r
+ if ( null == args )\r
+ {\r
+ continue;\r
+ }\r
+ testCases.add( new TestCase( args[0], args[1], args[2] ) );\r
+ try\r
+ {\r
+ time += Integer.parseInt( args[2] );\r
+ }\r
+ catch( final NumberFormatException e )\r
+ {\r
+ }\r
+ }\r
+ \r
+ writer.append( "<testsuite errors=\"\" failures\"\" name=\"IDE Performance\" skips=\"\" tests=\"" + testCases.size() + "\" time=\"" + time + "\">\n" );\r
+ try\r
+ {\r
+ for ( final TestCase testCase : testCases )\r
+ {\r
+ writer.append( "\t" + testCase.toString() + "\n" );\r
+ }\r
+ }\r
+ finally\r
+ {\r
+ writer.append( "</testsuite>" );\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package org.tizen.common;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.Test;\r
+\r
+public class LogConverterTest\r
+{\r
+\r
+ @Test\r
+ public void test_parse()\r
+ {\r
+ final Object[][] TEST_CASES = new Object[][] {\r
+ new Object[] { "[2013.10.10 15:00:18][PERFORM_E] TizenLaunchDelegate.java(804) - [Category: native.launch Variable: .install] at 2013-10-10 15:00:18.223 [2917(ms)]", new String[] { "native.launch", ".install", "2917" } }\r
+ };\r
+ \r
+ final LogConverter target = new LogConverter();\r
+ for ( final Object[] TEST_CASE : TEST_CASES )\r
+ {\r
+ final String input = (String) TEST_CASE[0];\r
+ final String[] expect = (String[]) TEST_CASE[1];\r
+ final String[] result = target.parse( input );\r
+ \r
+ assertArrayEquals( expect, result );\r
+ }\r
+ }\r
+\r
+}\r