1 /* $Id: Profiler.java 203 2010-10-11 08:59:47Z dchokshi $ */
\r
2 package dol.helper.profiler;
\r
4 import java.util.HashMap;
\r
5 import java.util.Iterator;
\r
6 import java.util.Vector;
\r
8 import dol.datamodel.XmlTag;
\r
9 import dol.datamodel.pn.Channel;
\r
10 import dol.datamodel.pn.Port;
\r
11 import dol.datamodel.pn.Process;
\r
12 import dol.datamodel.pn.ProcessNetwork;
\r
13 import dol.datamodel.pn.ProfilingConfiguration;
\r
17 * DOL profiler main class. Reads in profile data and generates the
\r
18 * profiling information.
\r
20 public class Profiler {
\r
29 * @param name Name of the trace file
\r
30 * @param pn The process network need to be annotated
\r
32 public void profilePN(String name, ProcessNetwork pn) {
\r
33 ProfileParser profileParser = new ProfileParser(name);
\r
34 profileParser.parseProfile();
\r
36 HashMap<String, ChannelProfile> channelProfiles =
\r
37 profileParser.getChannelProfiles();
\r
38 Iterator<String> iterator = channelProfiles.keySet().iterator();
\r
40 while (iterator.hasNext()) {
\r
41 ChannelProfile profile = channelProfiles.get(iterator.next());
\r
42 Channel channel = pn.getChannel(profile.getName());
\r
43 ProfilingConfiguration c = channel.getProfilingCfg(
\r
44 _xt.getProfilingTotalReadData());
\r
46 //no profiling present, add new one
\r
47 c = new ProfilingConfiguration(
\r
48 _xt.getProfilingTotalReadData());
\r
49 c.setValue(Long.toString(profile.getTotalReadData()));
\r
50 channel.getProfilingList().add(c);
\r
52 // profiling already present, extend existing one
\r
53 Long curr = Long.decode(c.getValue());
\r
54 curr += profile.getTotalReadData();
\r
55 c.setValue(Long.toString(curr));
\r
58 c = channel.getProfilingCfg(_xt.getProfilingNumOfReads());
\r
60 c = new ProfilingConfiguration(
\r
61 _xt.getProfilingNumOfReads());
\r
62 c.setValue(Integer.toString(profile.getNumOfReads()));
\r
63 channel.getProfilingList().add(c);
\r
65 Long curr = Long.decode(c.getValue());
\r
66 curr += profile.getNumOfReads();
\r
67 c.setValue(Long.toString(curr));
\r
70 c = channel.getProfilingCfg(_xt.getProfilingNumOfWrites());
\r
72 c = new ProfilingConfiguration(
\r
73 _xt.getProfilingNumOfWrites());
\r
74 c.setValue(Integer.toString(profile.getNumOfWrites()));
\r
75 channel.getProfilingList().add(c);
\r
77 Long curr = Long.decode(c.getValue());
\r
78 curr += profile.getNumOfWrites();
\r
79 c.setValue( Long.toString(curr) );
\r
83 HashMap<String, ProcessProfile> processProfiles =
\r
84 profileParser.getProcessProfiles();
\r
85 iterator = processProfiles.keySet().iterator();
\r
87 while (iterator.hasNext()) {
\r
88 ProcessProfile profile = processProfiles.get(iterator.next());
\r
89 Process process = pn.getProcess(profile.getName());
\r
90 ProfilingConfiguration c = process.getProfilingCfg(
\r
91 _xt.getProfilingNumOfFires());
\r
94 c = new ProfilingConfiguration(
\r
95 _xt.getProfilingNumOfFires());
\r
96 c.setValue(Integer.toString(profile.getNumOfFires()));
\r
97 process.getProfilingList().add(c);
\r
99 int curr = Integer.valueOf(c.getValue());
\r
100 curr += profile.getNumOfFires();
\r
101 c.setValue(Integer.toString(curr));
\r
104 HashMap<String, PortProfile> portProfiles =
\r
105 profile.getPortProfiles();
\r
106 Iterator<String> iteratorB = portProfiles.keySet().iterator();
\r
108 while (iteratorB.hasNext()) {
\r
109 PortProfile portProfile =
\r
110 portProfiles.get(iteratorB.next());
\r
111 String portName = getPNPortName(portProfile.getName(), profileParser, pn);
\r
112 c = new ProfilingConfiguration(portName + ".accesses");
\r
113 c.setValue(portProfile.getAccesses().toString());
\r
114 process.getProfilingList().add(c);
\r
115 c = new ProfilingConfiguration(portName + ".tokensize");
\r
116 c.setValue(portProfile.getTokenSize().toString());
\r
117 process.getProfilingList().add(c);
\r
118 c = new ProfilingConfiguration(portName + ".initialAccesses");
\r
119 c.setValue(Integer.toString(portProfile.getInitialAccesses()));
\r
120 process.getProfilingList().add(c);
\r
121 c = new ProfilingConfiguration(portName + ".initialtokensize");
\r
122 c.setValue(portProfile.getInitialTokenSize().toString());
\r
123 process.getProfilingList().add(c);
\r
131 protected String getPNPortName(String profilePortName,
\r
132 ProfileParser parser, ProcessNetwork pn) {
\r
133 Vector<Port> ports = pn.getChannel(parser.
\r
134 getChannel(profilePortName)).getPortList();
\r
135 for (int i = 0; i < ports.size(); i++) {
\r
136 if (parser.getPortType(profilePortName).equals("INPUT") &&
\r
137 ports.elementAt(i).isOutPort()) {
\r
138 return ports.elementAt(i).getPeerPort().getName();
\r
139 } else if (parser.getPortType(profilePortName).equals("OUTPUT") &&
\r
140 ports.elementAt(i).isInPort()) {
\r
141 return ports.elementAt(i).getPeerPort().getName();
\r
150 * @param args command line arguments. args[0] is the filename of
\r
151 * the profile file. args[1] is the filename of the process network
\r
154 public static void main(String[] args) {
\r
155 //check command line parameters
\r
156 if (args.length != 2) {
\r
157 System.out.println("Usage: Profiler <trace> <pn>");
\r
158 System.out.println();
\r
162 ProfileParser profileParser = new ProfileParser(args[0]);
\r
165 profileParser.parseProfile();
\r
167 //print the results
\r
168 System.out.println("----- Channel Analyzer Report -----");
\r
169 System.out.println("<channel name> <maximum fill level> "
\r
170 + "<total amount of transferred data> "
\r
171 + "<num of reads> <num of writes>");
\r
173 HashMap<String, ChannelProfile> channelProfiles =
\r
174 profileParser.getChannelProfiles();
\r
175 Iterator<String> iterator = channelProfiles.keySet().iterator();
\r
177 while (iterator.hasNext()) {
\r
178 ChannelProfile profile = channelProfiles.get(iterator.next());
\r
179 System.out.println( "<" + profile.getName() +
\r
181 + profile.getMaxFillLevel() + " "
\r
182 + profile.getTotalReadData() + " "
\r
183 + profile.getNumOfReads() + " "
\r
184 + profile.getNumOfWrites());
\r
186 System.out.println();
\r
188 System.out.println("----- Processnetwork Report -----");
\r
189 System.out.println("<process name> <num of activations>");
\r
191 HashMap<String, ProcessProfile> processProfiles =
\r
192 profileParser.getProcessProfiles();
\r
193 iterator = processProfiles.keySet().iterator();
\r
194 while (iterator.hasNext()) {
\r
195 ProcessProfile profile = processProfiles.get(iterator.next());
\r
196 System.out.println( "<" + profile.getName()
\r
197 + "> " + profile.getNumOfFires());
\r
199 System.out.println();
\r
203 PNXmlParser parserPN = new PNXmlParser();
\r
204 ProcessNetwork pn = parserPN.doParse(args[1]);
\r
205 Profiler p = new Profiler();
\r
206 p.profilePN(args[0], pn);
\r
207 pn.accept(new PNXmlVisitor("processnetwork.xml"));
\r
211 protected XmlTag _xt = XmlTag.getInstance();
\r