dol: initial dol commit
[jump.git] / dol / src / dol / helper / profiler / VSPLogFileProfiler.java
1 /* $Id: VSPLogFileProfiler.java 1 2010-02-24 13:03:05Z haidw $ */\r
2 package dol.helper.profiler;\r
3 \r
4 import java.io.BufferedReader;\r
5 import java.io.FileReader;\r
6 import java.io.IOException;\r
7 import java.util.StringTokenizer;\r
8 \r
9 import dol.datamodel.pn.Process;\r
10 import dol.datamodel.pn.ProcessNetwork;\r
11 import dol.datamodel.pn.ProfilingConfiguration;\r
12 \r
13 /**\r
14  * Class for parsing a file with profiling info and annotate it to a\r
15  * process network.\r
16  */\r
17 public class VSPLogFileProfiler {\r
18 \r
19     /**\r
20      * Parse the given file and annotate the data to the given process\r
21      * network.\r
22      *\r
23      * @param filename file with profiling info\r
24      * @param pn processnetwork to annotate\r
25      */\r
26     public static void annotateProcessNetwork(String filename,\r
27                                               ProcessNetwork pn) {\r
28         try {\r
29             BufferedReader reader = new BufferedReader(\r
30                     new FileReader(filename));\r
31             String line;\r
32             while ((line = reader.readLine()) != null) {\r
33                 StringTokenizer tokenizer =\r
34                             new StringTokenizer(line, " ");\r
35                 if (tokenizer.countTokens() == 2) {\r
36                     continue;\r
37                 }\r
38                 else if (tokenizer.countTokens() <= 2) {\r
39                     System.out.println("Warning: Each line in the log "\r
40                             + "file should have the following form:"\r
41                             + System.getProperty("line.separator")\r
42                             + "processname config_name config_value"\r
43                             + System.getProperty("line.separator")\r
44                             + "Ignoring the non-conforming line:"\r
45                             + System.getProperty("line.separator")\r
46                             + line);\r
47                     continue;\r
48                 }\r
49                 String processname = tokenizer.nextToken();\r
50                 Process process = pn.getProcess(processname);\r
51                 if (process == null) {\r
52                     System.out.println("Warning: Could not find process "\r
53                             + processname + " in processnetwork "\r
54                             + pn.getName() + ". Ignore configuration "\r
55                             + "statement in file " + filename + ".");\r
56                     continue;\r
57                 }\r
58                 ProfilingConfiguration config =\r
59                         new ProfilingConfiguration(tokenizer.nextToken());\r
60                 String value = "";\r
61                 while (tokenizer.hasMoreTokens()) {\r
62                     value += tokenizer.nextToken() + " ";\r
63                 }\r
64                 config.setValue(value.trim());\r
65                 config.setParentResource(process);\r
66                 process.getProfilingList().add(config);\r
67             }\r
68         }\r
69         catch (IOException e) {\r
70             System.out.println(e);\r
71         }\r
72     }\r
73 }\r