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

COVERAGE SUMMARY FOR SOURCE FILE [Pcm2RegExStrategy.java]

nameclass, %method, %block, %line, %
Pcm2RegExStrategy.java0%   (0/1)0%   (0/10)0%   (0/355)0%   (0/85)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Pcm2RegExStrategy0%   (0/1)0%   (0/10)0%   (0/355)0%   (0/85)
<static initializer> 0%   (0/1)0%   (0/5)0%   (0/2)
Pcm2RegExStrategy (PCMSolverWorkflowRunConfiguration): void 0%   (0/1)0%   (0/12)0%   (0/6)
loadTransformedModel (String): void 0%   (0/1)0%   (0/23)0%   (0/5)
printStoRegEx (): void 0%   (0/1)0%   (0/20)0%   (0/4)
runDSolver (PCMInstance): void 0%   (0/1)0%   (0/37)0%   (0/9)
runPcm2RegEx (PCMInstance): void 0%   (0/1)0%   (0/39)0%   (0/8)
solve (): void 0%   (0/1)0%   (0/116)0%   (0/21)
storeTransformedModel (String): void 0%   (0/1)0%   (0/5)0%   (0/2)
transform (PCMInstance): void 0%   (0/1)0%   (0/62)0%   (0/14)
visualize (IProbabilityDensityFunction): void 0%   (0/1)0%   (0/36)0%   (0/14)

1package de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex;
2 
3import java.util.concurrent.TimeUnit;
4 
5import org.apache.log4j.Logger;
6import org.eclipse.emf.ecore.EObject;
7 
8import de.uka.ipd.sdq.pcm.usagemodel.UsageScenario;
9import de.uka.ipd.sdq.pcmsolver.exprsolver.ExpressionSolver;
10import de.uka.ipd.sdq.pcmsolver.models.PCMInstance;
11import de.uka.ipd.sdq.pcmsolver.runconfig.PCMSolverWorkflowRunConfiguration;
12import de.uka.ipd.sdq.pcmsolver.transformations.EMFHelper;
13import de.uka.ipd.sdq.pcmsolver.transformations.SolverStrategy;
14import de.uka.ipd.sdq.pcmsolver.visitors.UsageModelVisitor;
15import de.uka.ipd.sdq.pcmsolver.visualisation.JFVisualisation;
16import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction;
17import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory;
18import de.uka.ipd.sdq.probfunction.math.ISamplePDF;
19import de.uka.ipd.sdq.probfunction.math.ManagedPDF;
20import de.uka.ipd.sdq.probfunction.math.PDFConfiguration;
21import de.uka.ipd.sdq.probfunction.math.exception.ConfigurationNotSetException;
22import de.uka.ipd.sdq.probfunction.math.exception.ProbabilityFunctionException;
23import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException;
24import de.uka.ipd.sdq.probfunction.print.ProbFunctionCSVPrint;
25import de.uka.ipd.sdq.spa.expression.Expression;
26 
27/**
28 * This is an excerpt of Heiko's dissertation (see below for link)
29 * 
30 * The Stochastic Regular Expression (SRE) model is an analytical performance
31 * model in the class of semi-Markov processes [Tri01]. It consists of a
32 * discrete time Markov-chain (DTMC) to model state transitions, but the sojourn
33 * time in each state can follow arbitrary probability distributions instead of
34 * being limited to exponential distributions as in Markov chains. Furthermore,
35 * SREs are hierarchically structured and do not allow cycles in the embedded
36 * DTMC for more accurate predictions. Chapter 6.3.3 will provide the syntax and
37 * semantics of SREs, afterwards Chapter 6.3.4 shows how to compute overall
38 * sojourn times with SREs. Only a partial transformation of PCM instances to
39 * SREs is possible, because of the model�s limited expressiveness. The
40 * transformation is straight-forward, as the control flow modelling of PCM
41 * instances and SREs are closely aligned. Chapter 6.3.5 will describe the
42 * transformation PCM2SRE. While allowing accurate predictions by supporting
43 * arbitrary distribution functions for timing values, SRE are limited to
44 * analysing single-user scenarios. They do not include queues or control flow
45 * forks, and cannot express contention effects due to concurrent requests.
46 * However, they provide a fast method of producing performance predictions
47 * during early development stages, as they are usually more quickly solved than
48 * running a simulation. Chapter 6.3.6 discusses the assumptions underlying SREs
49 * in detail. The SRE model will be used for a performance prediction in a case
50 * study in Chapter 7.3.3.
51 * 
52 * @see Heiko's dissertation, section 6.3 at
53 *      http://docserver.bis.uni-oldenburg.de
54 *      /_publikationen/dissertation/2008/kozpar08/pdf/kozpar08.pdf
55 * @author Heiko Koziolek
56 * 
57 */
58public class Pcm2RegExStrategy implements SolverStrategy {
59 
60        Expression stoRegEx;
61 
62        protected IProbabilityFunctionFactory iProbFuncFactory = 
63                IProbabilityFunctionFactory.eINSTANCE;
64        
65        private static Logger logger = Logger.getLogger(Pcm2RegExStrategy.class.getName());
66        
67        private long overallDuration = 0;
68 
69        private PCMSolverWorkflowRunConfiguration configuration;
70        
71        public Pcm2RegExStrategy(PCMSolverWorkflowRunConfiguration configuration) {
72                this.configuration = configuration;
73        }
74 
75        public void loadTransformedModel(String fileName) {
76                EObject object = EMFHelper.loadFromXMIFile(fileName);
77                if (object instanceof Expression){
78                        this.stoRegEx = (Expression)object;
79                } else {
80                        logger.warn("Could not load "+fileName+" because is not an Expression model");
81                }
82        }
83 
84        public void solve() {
85                if (stoRegEx != null){
86                        long timeBeforeCalc = System.nanoTime();
87                        ExpressionSolver solver = new ExpressionSolver();
88                        ManagedPDF resultPDF = solver.getResponseTime(stoRegEx);
89                        
90                        if(resultPDF == null){
91                                logger.error("StochasticRegularExpression could not be solved!");
92                                return;
93                        }
94                        
95                        long timeAfterCalc = System.nanoTime();
96                        long duration = TimeUnit.NANOSECONDS.toMillis(timeAfterCalc-timeBeforeCalc);
97                        overallDuration += duration;
98                        logger.info("Finished Running ExprSolver:\t"+ duration + " ms");
99                        logger.debug("Resulting PDF:\t\t\t"+resultPDF.toString());
100                        logger.trace("As csv:\n\nx;probability\n"+new ProbFunctionCSVPrint().doSwitch(resultPDF.getModelBoxedPdf()));
101                        
102                        visualize(resultPDF.getPdfTimeDomain());
103                        long timeAfterVisualisation = System.nanoTime();
104                        
105                        //logger.info("PDF in time domain: "+resultPDF.getPdfTimeDomain());
106                        
107                        duration = TimeUnit.NANOSECONDS.toMillis(timeAfterVisualisation-timeAfterCalc);
108                        overallDuration += duration;
109                        logger.info("Finished Visualisation:\t\t"+ duration + " ms");
110                        logger.info("Finished SRE-Solver:\t\t"+ overallDuration+ " ms");
111                        
112                } else
113                        logger.error("No StochasticRegularExpression available for solution!");
114        }
115 
116        public void storeTransformedModel(String fileName) {
117                
118                EMFHelper.saveToXMIFile(stoRegEx, fileName);
119                
120        }
121 
122        public void transform(PCMInstance model) {
123                
124                if (!this.configuration.isUseSREInputModel()){
125                        long timeBeforeCalc = System.nanoTime();
126                        runDSolver(model);
127                        runPcm2RegEx(model);
128                        printStoRegEx();
129                
130                        storeTransformedModel(this.configuration.getSREOutputFile());
131                
132                        long timeAfterCalc = System.nanoTime();
133                        long duration = TimeUnit.NANOSECONDS.toMillis(timeAfterCalc-timeBeforeCalc);
134                        overallDuration += duration;
135                        logger.info("Finished Running PCM2SRE:\t\t"+ duration + " ms");
136                } else {
137                        String filename = this.configuration.getSREOutputFile();
138                        loadTransformedModel(filename);
139                        logger.warn("Using predefined Expression model "+filename);
140                }
141                
142                
143        }
144 
145        private void printStoRegEx() {
146                ExpressionPrinter expPrinter = new ExpressionPrinter();
147                expPrinter.doSwitch(stoRegEx);
148                logger.debug("ExpressionPrinter: "+expPrinter.getOutput());
149        }
150 
151        private void runPcm2RegEx(PCMInstance model) {
152                TransformUsageModelVisitor umVisit = new TransformUsageModelVisitor(model);
153                UsageScenario us = (UsageScenario)model.getUsageModel().getUsageScenario_UsageModel().get(0);
154                try {
155                        stoRegEx = (Expression)umVisit.doSwitch(us.getScenarioBehaviour_UsageScenario());
156                } catch (Exception e) {
157                        logger.error("Transforming the PCM instance into a stochastic regular expression caused an Exception! Check your model for broken references, e.g. old, dangling Connectors." + e.getMessage());
158                        e.printStackTrace();
159                        
160                        throw new RuntimeException(e);
161                }
162        }
163 
164        private void runDSolver(PCMInstance model) {
165                UsageModelVisitor visitor = new UsageModelVisitor(model);
166                try {
167                        UsageScenario us = (UsageScenario) model.getUsageModel()
168                                        .getUsageScenario_UsageModel().get(0);
169                        visitor.doSwitch(us.getScenarioBehaviour_UsageScenario());
170                } catch (Exception e) {
171                        logger.error("Running the dependency solver caused an Exception! Check your model for broken references, e.g. old, dangling Connectors." + e.getMessage());
172                        e.printStackTrace();
173                        
174                        throw new RuntimeException(e);
175                }
176        }
177        
178        private void visualize(IProbabilityDensityFunction iPDF) {
179                ISamplePDF samplePDF = null;
180                try {
181                        samplePDF = iProbFuncFactory.transformToSamplePDF(iPDF);
182                } catch (UnknownPDFTypeException e1) {
183                        // TODO Auto-generated catch block
184                        e1.printStackTrace();
185                }
186                
187                try {
188                        double dist = 0.0;
189                        try {
190                                dist = PDFConfiguration.getCurrentConfiguration().getDistance();
191                        } catch (ConfigurationNotSetException e) {
192                                // TODO Auto-generated catch block
193                                e.printStackTrace();
194                        }
195                        JFVisualisation vis = new JFVisualisation(dist);
196                        vis.addSamplePDF(samplePDF,"Execution Time");
197                        vis.visualizeOverlay();
198                } catch (ProbabilityFunctionException e) {
199                        e.printStackTrace();
200                }
201        }
202 
203}

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