X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fhelper%2Fprofiler%2FPNProfileSummarizer.java;fp=dol%2Fsrc%2Fdol%2Fhelper%2Fprofiler%2FPNProfileSummarizer.java;h=66b1d58657ced5889439dcdc25a798c78423dffe;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/helper/profiler/PNProfileSummarizer.java b/dol/src/dol/helper/profiler/PNProfileSummarizer.java new file mode 100644 index 0000000..66b1d58 --- /dev/null +++ b/dol/src/dol/helper/profiler/PNProfileSummarizer.java @@ -0,0 +1,105 @@ +/* $Id: PNProfileSummarizer.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.helper.profiler; + +import java.util.HashMap; +import java.util.StringTokenizer; + +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; + +/** + * Class to post-process profiling info in a process network XML file. + */ +public class PNProfileSummarizer { + /** + * Add up all WCED, BCED, and ACED numbers for each process in the + * given process network file. The computed numbers are back-annotated + * to a new file with the suffix _summary. + * + * @param filename filename of annotated process network XML file + */ + public static void sumDemands(String filename) { + HashMap configs = + new HashMap(); + + //load process network specification from XML + PNXmlParser parserPn = new PNXmlParser(); + ProcessNetwork pn = parserPn.doParse(filename); + + for (Process process : pn.getProcessList()) { + //System.out.println(process.getName()); + for (ProfilingConfiguration cfg : + process.getProfilingList()) { + StringTokenizer tokenizer = + new StringTokenizer(cfg.getName(), " "); + //System.out.println(cfg.getName()); + if (tokenizer.countTokens() < 2) { + continue; + } + + String demandId = tokenizer.nextToken(); + String processorName = tokenizer.nextToken(); + String key = process.getName() + " " + demandId + " " + + processorName + " sum"; + if (configs.get(key) == null) { + ProfilingConfiguration config = + new ProfilingConfiguration(demandId + " " + + processorName + " sum"); + config.setValue("0"); + configs.put(key, config); + } + ProfilingConfiguration currentCfg = configs.get(key); + /* + System.out.print(currentCfg.getName() + ": " + + currentCfg.getValue() + " / " + + cfg.getName() + ": " + + cfg.getValue()); + */ + currentCfg.setValue( + Long.toString(Long.parseLong( + currentCfg.getValue()) + + Long.parseLong(cfg.getValue()))); + /* + System.out.println(currentCfg.getName() + ": " + + currentCfg.getValue()); + */ + } + } + + for(String key : configs.keySet()) { + ProfilingConfiguration value = configs.get(key); + String process = key.substring(0, key.indexOf(" ")); + pn.getProcess(process).getProfilingList().add(value); + } + + System.out.println("Write process network XML file"); + StringBuffer buffer = new StringBuffer(); + pn.accept(new PNXmlVisitor(buffer)); + try { + java.io.BufferedWriter writer = + new java.io.BufferedWriter( + new java.io.FileWriter( + filename.replaceAll(".xml", "_summary.xml"))); + writer.write(buffer.toString()); + writer.close(); + } catch (java.io.IOException e) { + System.out.println("Caught an exception while " + + "creating XML file: " + e.getMessage()); + e.printStackTrace(System.out); + } + System.out.println(" -- Process network XML file [Finished]"); + } + + + /** + * Run summarize operations on annotated process network. + * + * @param args filename of annotated process network XML file + */ + public static void main(String args[]) throws Exception { + PNProfileSummarizer.sumDemands(args[0]); + } +}