X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fhelper%2Fprofiler%2FProfiler.java;fp=dol%2Fsrc%2Fdol%2Fhelper%2Fprofiler%2FProfiler.java;h=e24d45695e3b1c1648d5b734a8b85047fd0cf33c;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/helper/profiler/Profiler.java b/dol/src/dol/helper/profiler/Profiler.java new file mode 100644 index 0000000..e24d456 --- /dev/null +++ b/dol/src/dol/helper/profiler/Profiler.java @@ -0,0 +1,212 @@ +/* $Id: Profiler.java 203 2010-10-11 08:59:47Z dchokshi $ */ +package dol.helper.profiler; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + +import dol.datamodel.XmlTag; +import dol.datamodel.pn.Channel; +import dol.datamodel.pn.Port; +import dol.datamodel.pn.Process; +import dol.datamodel.pn.ProcessNetwork; +import dol.datamodel.pn.ProfilingConfiguration; + + +/** + * DOL profiler main class. Reads in profile data and generates the + * profiling information. + */ +public class Profiler { + + /** + * Constructor + */ + public Profiler() { + } + + /** + * @param name Name of the trace file + * @param pn The process network need to be annotated + */ + public void profilePN(String name, ProcessNetwork pn) { + ProfileParser profileParser = new ProfileParser(name); + profileParser.parseProfile(); + + HashMap channelProfiles = + profileParser.getChannelProfiles(); + Iterator iterator = channelProfiles.keySet().iterator(); + + while (iterator.hasNext()) { + ChannelProfile profile = channelProfiles.get(iterator.next()); + Channel channel = pn.getChannel(profile.getName()); + ProfilingConfiguration c = channel.getProfilingCfg( + _xt.getProfilingTotalReadData()); + if (c == null) { + //no profiling present, add new one + c = new ProfilingConfiguration( + _xt.getProfilingTotalReadData()); + c.setValue(Long.toString(profile.getTotalReadData())); + channel.getProfilingList().add(c); + } else { + // profiling already present, extend existing one + Long curr = Long.decode(c.getValue()); + curr += profile.getTotalReadData(); + c.setValue(Long.toString(curr)); + } + + c = channel.getProfilingCfg(_xt.getProfilingNumOfReads()); + if (c == null) { + c = new ProfilingConfiguration( + _xt.getProfilingNumOfReads()); + c.setValue(Integer.toString(profile.getNumOfReads())); + channel.getProfilingList().add(c); + } else { + Long curr = Long.decode(c.getValue()); + curr += profile.getNumOfReads(); + c.setValue(Long.toString(curr)); + } + + c = channel.getProfilingCfg(_xt.getProfilingNumOfWrites()); + if (c == null) { + c = new ProfilingConfiguration( + _xt.getProfilingNumOfWrites()); + c.setValue(Integer.toString(profile.getNumOfWrites())); + channel.getProfilingList().add(c); + } else { + Long curr = Long.decode(c.getValue()); + curr += profile.getNumOfWrites(); + c.setValue( Long.toString(curr) ); + } + } + + HashMap processProfiles = + profileParser.getProcessProfiles(); + iterator = processProfiles.keySet().iterator(); + + while (iterator.hasNext()) { + ProcessProfile profile = processProfiles.get(iterator.next()); + Process process = pn.getProcess(profile.getName()); + ProfilingConfiguration c = process.getProfilingCfg( + _xt.getProfilingNumOfFires()); + + if (c == null) { + c = new ProfilingConfiguration( + _xt.getProfilingNumOfFires()); + c.setValue(Integer.toString(profile.getNumOfFires())); + process.getProfilingList().add(c); + } else { + int curr = Integer.valueOf(c.getValue()); + curr += profile.getNumOfFires(); + c.setValue(Integer.toString(curr)); + } + + HashMap portProfiles = + profile.getPortProfiles(); + Iterator iteratorB = portProfiles.keySet().iterator(); + + while (iteratorB.hasNext()) { + PortProfile portProfile = + portProfiles.get(iteratorB.next()); + String portName = getPNPortName(portProfile.getName(), profileParser, pn); + c = new ProfilingConfiguration(portName + ".accesses"); + c.setValue(portProfile.getAccesses().toString()); + process.getProfilingList().add(c); + c = new ProfilingConfiguration(portName + ".tokensize"); + c.setValue(portProfile.getTokenSize().toString()); + process.getProfilingList().add(c); + c = new ProfilingConfiguration(portName + ".initialAccesses"); + c.setValue(Integer.toString(portProfile.getInitialAccesses())); + process.getProfilingList().add(c); + c = new ProfilingConfiguration(portName + ".initialtokensize"); + c.setValue(portProfile.getInitialTokenSize().toString()); + process.getProfilingList().add(c); + } + } + } + + /** + * + */ + protected String getPNPortName(String profilePortName, + ProfileParser parser, ProcessNetwork pn) { + Vector ports = pn.getChannel(parser. + getChannel(profilePortName)).getPortList(); + for (int i = 0; i < ports.size(); i++) { + if (parser.getPortType(profilePortName).equals("INPUT") && + ports.elementAt(i).isOutPort()) { + return ports.elementAt(i).getPeerPort().getName(); + } else if (parser.getPortType(profilePortName).equals("OUTPUT") && + ports.elementAt(i).isInPort()) { + return ports.elementAt(i).getPeerPort().getName(); + } + } + return null; + } + + /** + * Main function + * + * @param args command line arguments. args[0] is the filename of + * the profile file. args[1] is the filename of the process network + * XML file. + */ + public static void main(String[] args) { + //check command line parameters + if (args.length != 2) { + System.out.println("Usage: Profiler "); + System.out.println(); + return; + } + + ProfileParser profileParser = new ProfileParser(args[0]); + + //parse input file + profileParser.parseProfile(); + + //print the results + System.out.println("----- Channel Analyzer Report -----"); + System.out.println(" " + + " " + + " "); + + HashMap channelProfiles = + profileParser.getChannelProfiles(); + Iterator iterator = channelProfiles.keySet().iterator(); + + while (iterator.hasNext()) { + ChannelProfile profile = channelProfiles.get(iterator.next()); + System.out.println( "<" + profile.getName() + + "> " + + profile.getMaxFillLevel() + " " + + profile.getTotalReadData() + " " + + profile.getNumOfReads() + " " + + profile.getNumOfWrites()); + } + System.out.println(); + + System.out.println("----- Processnetwork Report -----"); + System.out.println(" "); + + HashMap processProfiles = + profileParser.getProcessProfiles(); + iterator = processProfiles.keySet().iterator(); + while (iterator.hasNext()) { + ProcessProfile profile = processProfiles.get(iterator.next()); + System.out.println( "<" + profile.getName() + + "> " + profile.getNumOfFires()); + } + System.out.println(); + + /* + //another test + PNXmlParser parserPN = new PNXmlParser(); + ProcessNetwork pn = parserPN.doParse(args[1]); + Profiler p = new Profiler(); + p.profilePN(args[0], pn); + pn.accept(new PNXmlVisitor("processnetwork.xml")); + */ + } + + protected XmlTag _xt = XmlTag.getInstance(); +}