+/* $Id: WorkloadAnnotator.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.helper.profiler;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Vector;
+
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.datamodel.pn.ProfilingConfiguration;
+import dol.parser.xml.pnschema.PNXmlParser;
+import dol.visitor.xml.PNXmlVisitor;
+
+public class WorkloadAnnotator {
+
+ /**
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ String logFile = "workload.txt";
+ String pnFileIn = "processnetwork.xml";
+ String pnFileOut = "processnetwork.xml";
+
+ try {
+ if (args.length > 2) {
+ pnFileIn = args[0];
+ logFile = args[1];
+ pnFileOut = args[1];
+ } else if (args.length == 2) {
+ pnFileIn = args[0];
+ logFile = args[1];
+ } else if (args.length == 1) {
+ pnFileIn = args[0];
+ }
+
+ PNXmlParser parserPN = new PNXmlParser();
+ ProcessNetwork pn = parserPN.doParse(pnFileIn);
+
+ WorkloadAnnotator.annotateProcessNetwork(logFile, pn);
+ StringBuffer b = new StringBuffer();
+ pn.accept(new PNXmlVisitor(b));
+ FileWriter out = new FileWriter(pnFileOut);
+ out.write(b.toString());
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @param workloadFileName
+ * @param pn
+ * @throws IOException
+ */
+ public static void annotateProcessNetwork(String workloadFileName,
+ ProcessNetwork pn) throws IOException {
+ for (Process p : pn.getProcessList()) {
+ Vector<ProfilingConfiguration> v = p.getProfilingList();
+ if (v == null) {
+ p.setProfilingList(new Vector<ProfilingConfiguration>());
+ }
+ }
+
+ BufferedReader in = new BufferedReader(new FileReader(workloadFileName));
+ String line, process, name, value;
+ while ((line = in.readLine()) != null) {
+ if (line.startsWith("wced_")) {
+ process = line.substring("wced_".length()).trim();
+ name = "WCET";
+
+ } else if (line.startsWith("bced_")) {
+ process = line.substring("bced_".length()).trim();
+ name = "BCET";
+
+ } else if (line.startsWith("workload_upper_")) {
+ process = line.substring("workload_upper_".length()).
+ trim();
+ name = "WORKLOAD_UPPER";
+
+ } else if (line.startsWith("workload_lower_")) {
+ process = line.substring("workload_lower_".length()).
+ trim();
+ name = "WORKLOAD_LOWER";
+
+ } else {
+ continue;
+ }
+ process = process.substring(0, process.length() - 1).trim();
+
+ in.readLine();
+ value = in.readLine().trim();
+
+ ProfilingConfiguration pc = new ProfilingConfiguration(name);
+ pc.setValue(value);
+ pn.getProcess(process).getProfilingList().add(pc);
+ }
+ }
+}