dol: initial dol commit
[jump.git] / dol / src / dol / helper / profiler / WorkloadAnnotator.java
1 /* $Id: WorkloadAnnotator.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.helper.profiler;
3
4 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import java.io.FileWriter;
7 import java.io.IOException;
8 import java.util.Vector;
9
10 import dol.datamodel.pn.Process;
11 import dol.datamodel.pn.ProcessNetwork;
12 import dol.datamodel.pn.ProfilingConfiguration;
13 import dol.parser.xml.pnschema.PNXmlParser;
14 import dol.visitor.xml.PNXmlVisitor;
15
16 public class WorkloadAnnotator {
17
18     /**
19      * 
20      * @param args
21      */
22     public static void main(String[] args) {
23         String logFile = "workload.txt";
24         String pnFileIn = "processnetwork.xml";
25         String pnFileOut = "processnetwork.xml";
26
27         try {
28             if (args.length > 2) {
29                 pnFileIn = args[0];
30                 logFile = args[1];
31                 pnFileOut = args[1];
32             } else if (args.length == 2) {
33                 pnFileIn = args[0];
34                 logFile = args[1];
35             } else if (args.length == 1) {
36                 pnFileIn = args[0];
37             }
38
39             PNXmlParser parserPN = new PNXmlParser();
40             ProcessNetwork pn = parserPN.doParse(pnFileIn);
41
42             WorkloadAnnotator.annotateProcessNetwork(logFile, pn);
43             StringBuffer b = new StringBuffer();
44             pn.accept(new PNXmlVisitor(b));
45             FileWriter out = new FileWriter(pnFileOut);
46             out.write(b.toString());
47             out.close();
48         } catch (Exception e) {
49             e.printStackTrace();
50         }
51     }
52
53     /**
54      * 
55      * @param workloadFileName
56      * @param pn
57      * @throws IOException
58      */
59     public static void annotateProcessNetwork(String workloadFileName,
60             ProcessNetwork pn) throws IOException {
61         for (Process p : pn.getProcessList()) {
62             Vector<ProfilingConfiguration> v = p.getProfilingList();
63             if (v == null) {
64                 p.setProfilingList(new Vector<ProfilingConfiguration>());
65             }
66         }
67
68         BufferedReader in = new BufferedReader(new FileReader(workloadFileName));
69         String line, process, name, value;
70         while ((line = in.readLine()) != null) {
71             if (line.startsWith("wced_")) {
72                 process = line.substring("wced_".length()).trim();
73                 name = "WCET";
74
75             } else if (line.startsWith("bced_")) {
76                 process = line.substring("bced_".length()).trim();
77                 name = "BCET";
78
79             } else if (line.startsWith("workload_upper_")) {
80                 process = line.substring("workload_upper_".length()).
81                         trim();
82                 name = "WORKLOAD_UPPER";
83
84             } else if (line.startsWith("workload_lower_")) {
85                 process = line.substring("workload_lower_".length()).
86                         trim();
87                 name = "WORKLOAD_LOWER";
88
89             } else {
90                 continue;
91             }
92             process = process.substring(0, process.length() - 1).trim();
93
94             in.readLine();
95             value = in.readLine().trim();
96
97             ProfilingConfiguration pc = new ProfilingConfiguration(name);
98             pc.setValue(value);
99             pn.getProcess(process).getProfilingList().add(pc);
100         }
101     }
102 }