1 /* $Id: WorkloadAnnotator.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.helper.profiler;
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;
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;
16 public class WorkloadAnnotator {
22 public static void main(String[] args) {
23 String logFile = "workload.txt";
24 String pnFileIn = "processnetwork.xml";
25 String pnFileOut = "processnetwork.xml";
28 if (args.length > 2) {
32 } else if (args.length == 2) {
35 } else if (args.length == 1) {
39 PNXmlParser parserPN = new PNXmlParser();
40 ProcessNetwork pn = parserPN.doParse(pnFileIn);
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());
48 } catch (Exception e) {
55 * @param workloadFileName
59 public static void annotateProcessNetwork(String workloadFileName,
60 ProcessNetwork pn) throws IOException {
61 for (Process p : pn.getProcessList()) {
62 Vector<ProfilingConfiguration> v = p.getProfilingList();
64 p.setProfilingList(new Vector<ProfilingConfiguration>());
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();
75 } else if (line.startsWith("bced_")) {
76 process = line.substring("bced_".length()).trim();
79 } else if (line.startsWith("workload_upper_")) {
80 process = line.substring("workload_upper_".length()).
82 name = "WORKLOAD_UPPER";
84 } else if (line.startsWith("workload_lower_")) {
85 process = line.substring("workload_lower_".length()).
87 name = "WORKLOAD_LOWER";
92 process = process.substring(0, process.length() - 1).trim();
95 value = in.readLine().trim();
97 ProfilingConfiguration pc = new ProfilingConfiguration(name);
99 pn.getProcess(process).getProfilingList().add(pc);