+/* $Id: VSPLogFileProfiler.java 1 2010-02-24 13:03:05Z haidw $ */\r
+package dol.helper.profiler;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.util.StringTokenizer;\r
+\r
+import dol.datamodel.pn.Process;\r
+import dol.datamodel.pn.ProcessNetwork;\r
+import dol.datamodel.pn.ProfilingConfiguration;\r
+\r
+/**\r
+ * Class for parsing a file with profiling info and annotate it to a\r
+ * process network.\r
+ */\r
+public class VSPLogFileProfiler {\r
+\r
+ /**\r
+ * Parse the given file and annotate the data to the given process\r
+ * network.\r
+ *\r
+ * @param filename file with profiling info\r
+ * @param pn processnetwork to annotate\r
+ */\r
+ public static void annotateProcessNetwork(String filename,\r
+ ProcessNetwork pn) {\r
+ try {\r
+ BufferedReader reader = new BufferedReader(\r
+ new FileReader(filename));\r
+ String line;\r
+ while ((line = reader.readLine()) != null) {\r
+ StringTokenizer tokenizer =\r
+ new StringTokenizer(line, " ");\r
+ if (tokenizer.countTokens() == 2) {\r
+ continue;\r
+ }\r
+ else if (tokenizer.countTokens() <= 2) {\r
+ System.out.println("Warning: Each line in the log "\r
+ + "file should have the following form:"\r
+ + System.getProperty("line.separator")\r
+ + "processname config_name config_value"\r
+ + System.getProperty("line.separator")\r
+ + "Ignoring the non-conforming line:"\r
+ + System.getProperty("line.separator")\r
+ + line);\r
+ continue;\r
+ }\r
+ String processname = tokenizer.nextToken();\r
+ Process process = pn.getProcess(processname);\r
+ if (process == null) {\r
+ System.out.println("Warning: Could not find process "\r
+ + processname + " in processnetwork "\r
+ + pn.getName() + ". Ignore configuration "\r
+ + "statement in file " + filename + ".");\r
+ continue;\r
+ }\r
+ ProfilingConfiguration config =\r
+ new ProfilingConfiguration(tokenizer.nextToken());\r
+ String value = "";\r
+ while (tokenizer.hasMoreTokens()) {\r
+ value += tokenizer.nextToken() + " ";\r
+ }\r
+ config.setValue(value.trim());\r
+ config.setParentResource(process);\r
+ process.getProfilingList().add(config);\r
+ }\r
+ }\r
+ catch (IOException e) {\r
+ System.out.println(e);\r
+ }\r
+ }\r
+}\r