EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcmsolver.transformations.pcm2lqn]

COVERAGE SUMMARY FOR SOURCE FILE [ResourceEnvironment2Lqn.java]

nameclass, %method, %block, %line, %
ResourceEnvironment2Lqn.java0%   (0/1)0%   (0/9)0%   (0/422)0%   (0/100)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ResourceEnvironment2Lqn0%   (0/1)0%   (0/9)0%   (0/422)0%   (0/100)
$SWITCH_TABLE$de$uka$ipd$sdq$pcm$resourceenvironment$SchedulingPolicy (): int [] 0%   (0/1)0%   (0/48)0%   (0/1)
<static initializer> 0%   (0/1)0%   (0/5)0%   (0/2)
ResourceEnvironment2Lqn (LqnBuilder, PCMSolverWorkflowRunConfiguration): void 0%   (0/1)0%   (0/9)0%   (0/4)
caseCommunicationLinkResourceSpecification (CommunicationLinkResourceSpecific... 0%   (0/1)0%   (0/167)0%   (0/38)
caseLinkingResource (LinkingResource): Object 0%   (0/1)0%   (0/7)0%   (0/3)
caseProcessingResourceSpecification (ProcessingResourceSpecification): Object 0%   (0/1)0%   (0/65)0%   (0/15)
caseResourceContainer (ResourceContainer): Object 0%   (0/1)0%   (0/20)0%   (0/5)
caseResourceEnvironment (ResourceEnvironment): Object 0%   (0/1)0%   (0/38)0%   (0/8)
setSchedulingPolicy (ProcessingResourceSpecification, ProcessorType): void 0%   (0/1)0%   (0/63)0%   (0/25)

1package de.uka.ipd.sdq.pcmsolver.transformations.pcm2lqn;
2 
3import java.math.BigInteger;
4 
5import org.apache.log4j.Logger;
6import org.eclipse.emf.common.util.EList;
7 
8import LqnCore.ActivityPhasesType;
9import LqnCore.EntryType;
10import LqnCore.PhaseActivities;
11import LqnCore.ProcessorType;
12import LqnCore.SchedulingType;
13import LqnCore.TaskType;
14import LqnCore.TypeType;
15import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
16import de.uka.ipd.sdq.pcm.resourceenvironment.CommunicationLinkResourceSpecification;
17import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource;
18import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification;
19import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer;
20import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment;
21import de.uka.ipd.sdq.pcm.resourceenvironment.util.ResourceenvironmentSwitch;
22import de.uka.ipd.sdq.pcm.resourcetype.CommunicationLinkResourceType;
23import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType;
24import de.uka.ipd.sdq.pcmsolver.runconfig.PCMSolverWorkflowRunConfiguration;
25import de.uka.ipd.sdq.pcmsolver.transformations.ExpressionToPDFWrapper;
26import de.uka.ipd.sdq.pcmsolver.visitors.ExpressionHelper;
27 
28public class ResourceEnvironment2Lqn extends ResourceenvironmentSwitch {
29        
30        private static Logger logger = Logger.getLogger(ResourceEnvironment2Lqn.class.getName());
31        
32        private LqnBuilder lqnBuilder;
33        private PCMSolverWorkflowRunConfiguration config;
34 
35        public ResourceEnvironment2Lqn(LqnBuilder aLqnBuilder, PCMSolverWorkflowRunConfiguration aConfig) {
36                lqnBuilder = aLqnBuilder;
37                config = aConfig;
38        }
39 
40        @Override
41        public Object caseCommunicationLinkResourceSpecification(
42                        CommunicationLinkResourceSpecification object) {
43                LinkingResource lr = (LinkingResource) object.eContainer();
44                CommunicationLinkResourceType clrt = object
45                                .getCommunicationLinkResourceType_CommunicationLinkResourceSpecification();
46                String id = Pcm2LqnHelper.getIdForCommResource(lr,clrt);
47 
48                PCMRandomVariable throughputVariable = object.getThroughput_CommunicationLinkResourceSpecification();
49                PCMRandomVariable latencyVariable = object.getLatency_CommunicationLinkResourceSpecification();
50                
51                
52                if (throughputVariable != null || latencyVariable != null){
53                        //only handle linking resource if a throughput or latency is specified
54                        
55                        ProcessorType pt = lqnBuilder.addProcessor(id);
56                        pt.setSpeedFactor("1");
57                        pt.setScheduling(SchedulingType.FCFS);
58                        
59                        TaskType tt = lqnBuilder.addTask(id, pt);
60                        
61                        // Throughput: Create throughput entry that can be called
62                        // for remote external call with bytesize information
63                        // FIXME: Calls to this need to be added with BYTESIZE info. Not yet supported.
64                        if (throughputVariable != null){
65                                
66                                String throughputID = Pcm2LqnHelper.getIdForThroughput(id);
67                                ActivityPhasesType apt = lqnBuilder.addActivityPhases(throughputID);
68                                PhaseActivities pa = lqnBuilder.addPhaseActivities(apt);
69                                EntryType et = lqnBuilder.addEntry(throughputID, tt);
70                                et.setType(TypeType.NONE);
71                                et.setEntryPhaseActivities(pa);
72                                
73                                // callers must call this task BYTESIZE times, that should make no difference for the LQN mean value analysis
74                                // we could thin about aggregating this to KB or so, but that might cause misunderstandings.
75                                // alternatively, for each call using a BYTESIZE, a new entry of this processor must be created.  
76                                double throughputSpeedFactor = 1/ExpressionHelper.getMeanValue(throughputVariable);
77                                apt.setHostDemandMean(""+throughputSpeedFactor);
78                                
79                                //TODO: each external call can create a new entry here with the demand (compare internal actions)
80                        
81                        }
82                        if (latencyVariable != null){
83                                // careful: calls to the latency are generated only if latency is larger > 0 
84                                
85                                ExpressionToPDFWrapper expToPDF = ExpressionToPDFWrapper.createExpressionToPDFWrapper(latencyVariable.getExpression());
86                                double latency = expToPDF.getMeanValue();
87                                                                
88                                CallType[] callTypes = CallType.values();
89                                // LQN does not allow to receive synchronous and asynchronous calls at one entry, 
90                                // so need to create one entry per call type. 
91                                for (int i = 0; i < callTypes.length; i++) {
92                                        CallType callType = callTypes[i];
93                                        
94                                        String latencyID = Pcm2LqnHelper.getIdForLatency(id, callType);
95                                        ActivityPhasesType apt = lqnBuilder.addActivityPhases(latencyID);
96                                        PhaseActivities pa = lqnBuilder.addPhaseActivities(apt);
97                                        
98                                        EntryType et = lqnBuilder.addEntry(latencyID, tt);
99                                        et.setType(TypeType.PH1PH2);
100                                        et.setEntryPhaseActivities(pa);
101                                        
102                                        apt.setHostDemandMean(""+latency);
103                                        double stdev = expToPDF.getStandardDeviation();
104                                        if (!Double.isNaN(stdev) && latency != 0){
105                                                // squared coefficient of variation
106                                                apt.setHostDemandCvsq(""+(stdev*stdev/(latency*latency)));
107                                        }
108                                }
109                        }
110                        
111                } else {
112                        logger.warn("Found linking resource with neither throughput specification nor latency specification, ignoring it.");
113                }
114                
115                return null;
116        }
117 
118        @Override
119        public Object caseLinkingResource(LinkingResource object) {
120                doSwitch(object
121                                .getCommunicationLinkResourceSpecifications_LinkingResource());
122                return null;
123        }
124 
125        @Override
126        public Object caseProcessingResourceSpecification(
127                        ProcessingResourceSpecification object) {
128                ResourceContainer rc = (ResourceContainer) object.eContainer();
129                ProcessingResourceType prt = object
130                                .getActiveResourceType_ActiveResourceSpecification();
131                String id = Pcm2LqnHelper.getIdForProcResource(rc, prt);
132                
133                ProcessorType pt = lqnBuilder.addProcessor(id);
134                setSchedulingPolicy(object, pt);
135                
136                // The speed of the processing resource is already considered in the resource demands,
137                // they are calculated in term of tiem spent on the processor. 
138                /*String processingRate = object
139                                .getProcessingRate_ProcessingResourceSpecification()
140                                .getSpecification();*/
141                pt.setSpeedFactor("1.0");
142                //pt.setMultiplicity(new BigInteger("1"));
143                pt.setMultiplicity(new BigInteger(""+object.getNumberOfReplicas()));
144                
145//                String processingRateSolved = ExpressionHelper.getSolvedExpressionAsString(processingRate, null);
146//                
147//                pt.setSpeedFactor(processingRateSolved);
148                
149                TaskType tt = lqnBuilder.addTask(id,pt);
150                ActivityPhasesType apt = lqnBuilder.addActivityPhases(id);
151                PhaseActivities pa = lqnBuilder.addPhaseActivities(apt);
152                EntryType et = lqnBuilder.addEntry(id, tt);
153                et.setType(TypeType.NONE);
154                et.setEntryPhaseActivities(pa);
155                
156                return null;
157        }
158 
159        private void setSchedulingPolicy(ProcessingResourceSpecification object,
160                        ProcessorType pt) {
161                switch (object.getSchedulingPolicy()) {
162                case FCFS:
163                        pt.setScheduling(SchedulingType.FCFS);
164                        break;
165                case DELAY:
166                        // The SchedulingType.INF has been added manually to the generated code, so 
167                        // there may appear a compile error here if the LQN code is regenerated again. 
168                        // I purposefully did not set it to "generated not" so that this problem is 
169                        // brought to attention whenever the model is regenerated
170                        // However, if the model is successfully regenerated from the LQN version 4.3 or later XML schema
171                        // the inf value should be available in the generated code and this note can be deleted.  
172                        pt.setScheduling(SchedulingType.INF);
173                        break;
174                case PROCESSOR_SHARING:
175                        pt.setScheduling(SchedulingType.PS);
176                        pt.setQuantum(config.getPsQuantum());
177                        break;
178                default : 
179                        logger.warn("Unknown scheduling strategy "
180                                                        + object.getSchedulingPolicy().getName()
181                                                        + ", using PROCESSOR_SHARING for "
182                                                        + object
183                                                                        .getActiveResourceType_ActiveResourceSpecification()
184                                                                        .getEntityName()
185                                                        + " of server "
186                                                        + object
187                                                                        .getResourceContainer_ProcessingResourceSpecification()
188                                                                        .getEntityName()
189                                                        + " (id: "
190                                                        + object
191                                                                        .getResourceContainer_ProcessingResourceSpecification()
192                                                                        .getId() + ")");
193                        pt.setScheduling(SchedulingType.PS);
194                        pt.setQuantum(config.getPsQuantum());
195                }
196        }
197 
198        @Override
199        public Object caseResourceContainer(ResourceContainer object) {
200                EList<ProcessingResourceSpecification> procResList = object
201                                .getActiveResourceSpecifications_ResourceContainer();
202                for (ProcessingResourceSpecification prs : procResList) {
203                        doSwitch(prs);
204                }
205                return null;
206        }
207 
208        @Override
209        public Object caseResourceEnvironment(ResourceEnvironment object) {
210                EList<ResourceContainer> resConList = object
211                                .getResourceContainer_ResourceEnvironment();
212                for (ResourceContainer rc : resConList) {
213                        doSwitch(rc); //TODO
214                }
215 
216                EList<LinkingResource> linkResList = object.getLinkingResources__ResourceEnvironment();
217                for (LinkingResource lr : linkResList) {
218                        doSwitch(lr);
219                }
220 
221                return null;
222        }
223        
224}

[all classes][de.uka.ipd.sdq.pcmsolver.transformations.pcm2lqn]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov