1 /* $Id: PNProfileSummarizer.java 1 2010-02-24 13:03:05Z haidw $ */
\r
2 package dol.helper.profiler;
\r
4 import java.util.HashMap;
\r
5 import java.util.StringTokenizer;
\r
7 import dol.datamodel.pn.Process;
\r
8 import dol.datamodel.pn.ProcessNetwork;
\r
9 import dol.datamodel.pn.ProfilingConfiguration;
\r
10 import dol.parser.xml.pnschema.PNXmlParser;
\r
11 import dol.visitor.xml.PNXmlVisitor;
\r
14 * Class to post-process profiling info in a process network XML file.
\r
16 public class PNProfileSummarizer {
\r
18 * Add up all WCED, BCED, and ACED numbers for each process in the
\r
19 * given process network file. The computed numbers are back-annotated
\r
20 * to a new file with the suffix _summary.
\r
22 * @param filename filename of annotated process network XML file
\r
24 public static void sumDemands(String filename) {
\r
25 HashMap<String, ProfilingConfiguration> configs =
\r
26 new HashMap<String, ProfilingConfiguration>();
\r
28 //load process network specification from XML
\r
29 PNXmlParser parserPn = new PNXmlParser();
\r
30 ProcessNetwork pn = parserPn.doParse(filename);
\r
32 for (Process process : pn.getProcessList()) {
\r
33 //System.out.println(process.getName());
\r
34 for (ProfilingConfiguration cfg :
\r
35 process.getProfilingList()) {
\r
36 StringTokenizer tokenizer =
\r
37 new StringTokenizer(cfg.getName(), " ");
\r
38 //System.out.println(cfg.getName());
\r
39 if (tokenizer.countTokens() < 2) {
\r
43 String demandId = tokenizer.nextToken();
\r
44 String processorName = tokenizer.nextToken();
\r
45 String key = process.getName() + " " + demandId + " "
\r
46 + processorName + " sum";
\r
47 if (configs.get(key) == null) {
\r
48 ProfilingConfiguration config =
\r
49 new ProfilingConfiguration(demandId + " "
\r
50 + processorName + " sum");
\r
51 config.setValue("0");
\r
52 configs.put(key, config);
\r
54 ProfilingConfiguration currentCfg = configs.get(key);
\r
56 System.out.print(currentCfg.getName() + ": "
\r
57 + currentCfg.getValue() + " / "
\r
58 + cfg.getName() + ": "
\r
61 currentCfg.setValue(
\r
62 Long.toString(Long.parseLong(
\r
63 currentCfg.getValue())
\r
64 + Long.parseLong(cfg.getValue())));
\r
66 System.out.println(currentCfg.getName() + ": "
\r
67 + currentCfg.getValue());
\r
72 for(String key : configs.keySet()) {
\r
73 ProfilingConfiguration value = configs.get(key);
\r
74 String process = key.substring(0, key.indexOf(" "));
\r
75 pn.getProcess(process).getProfilingList().add(value);
\r
78 System.out.println("Write process network XML file");
\r
79 StringBuffer buffer = new StringBuffer();
\r
80 pn.accept(new PNXmlVisitor(buffer));
\r
82 java.io.BufferedWriter writer =
\r
83 new java.io.BufferedWriter(
\r
84 new java.io.FileWriter(
\r
85 filename.replaceAll(".xml", "_summary.xml")));
\r
86 writer.write(buffer.toString());
\r
88 } catch (java.io.IOException e) {
\r
89 System.out.println("Caught an exception while "
\r
90 + "creating XML file: " + e.getMessage());
\r
91 e.printStackTrace(System.out);
\r
93 System.out.println(" -- Process network XML file [Finished]");
\r
98 * Run summarize operations on annotated process network.
\r
100 * @param args filename of annotated process network XML file
\r
102 public static void main(String args[]) throws Exception {
\r
103 PNProfileSummarizer.sumDemands(args[0]);
\r