Merge branch 'neon' of https://git.eclipse.org/r/chess/chess into neon
diff --git a/plugins/org.polarsys.chess.monitoring/META-INF/MANIFEST.MF b/plugins/org.polarsys.chess.monitoring/META-INF/MANIFEST.MF
index 344f61b..8c459ae 100644
--- a/plugins/org.polarsys.chess.monitoring/META-INF/MANIFEST.MF
+++ b/plugins/org.polarsys.chess.monitoring/META-INF/MANIFEST.MF
@@ -14,9 +14,15 @@
  org.eclipse.emf.ecore;visibility:=reexport,
  org.eclipse.ui.workbench,
  org.eclipse.ui,
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ org.polarsys.chess.core,
+ org.eclipse.papyrus.infra.tools,
+ org.eclipse.papyrus.infra.widgets.toolbox,
+ org.eclipse.papyrus.emf.facet.custom.metamodel,
+ org.eclipse.uml2.uml
 Bundle-ActivationPolicy: lazy
-Import-Package: org.eclipse.emf.ecore.xmi,
+Import-Package: org.eclipse.core.filesystem,
+ org.eclipse.emf.ecore.xmi,
  org.eclipse.emf.ecore.xmi.impl,
  org.eclipse.m2m.qvt.oml,
  org.eclipse.m2m.qvt.oml.util,
diff --git a/plugins/org.polarsys.chess.monitoring/plugin.properties b/plugins/org.polarsys.chess.monitoring/plugin.properties
index be8bea9..39976b3 100644
--- a/plugins/org.polarsys.chess.monitoring/plugin.properties
+++ b/plugins/org.polarsys.chess.monitoring/plugin.properties
@@ -1,4 +1,4 @@
 #
 
-pluginName = Monitoring Model
-providerName = www.example.org
+pluginName = CHESS Monitoring Support
+providerName = MDH/Intecs
diff --git a/plugins/org.polarsys.chess.monitoring/plugin.xml b/plugins/org.polarsys.chess.monitoring/plugin.xml
index a4808e5..3d42715 100644
--- a/plugins/org.polarsys.chess.monitoring/plugin.xml
+++ b/plugins/org.polarsys.chess.monitoring/plugin.xml
@@ -43,5 +43,62 @@
             class="org.polarsys.chess.monitoring.monitoringxml.MonitoringxmlPackage"
             genModel="model/monitoring.genmodel"/>
    </extension>
+   <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            category="org.polarsys.chess.preferences"
+            class="org.polarsys.chess.monitoring.preferences.MonitoringPreferencePage"
+            id="org.polarsys.chess.monitoring.preferences.MonitoringPreferencePage"
+            name="Monitoring Preferences">
+      </page>
+   </extension>
+   <extension
+         point="org.eclipse.core.runtime.preferences">
+      <initializer
+            class="org.polarsys.chess.monitoring.preferences.PreferenceInitializer">
+      </initializer>
+   </extension>
+   <extension
+         point="org.eclipse.ui.menus">
+      <menuContribution
+            allPopups="false"
+            locationURI="popup:org.polarsys.chess.modelexplorerpopupmenu.id?after=org.polarsys.chess.patterns.id">
+         <menu
+               label=" Monitoring">
+            <command
+                  commandId="org.polarsys.chess.monitoring.importLogcommand"
+                  label="Import Log"
+                  style="push">
+                   <visibleWhen
+                     checkEnabled="false">
+                  <iterate
+                        ifEmpty="false"
+                        operator="and">
+                     <adapt
+                           type="org.eclipse.emf.ecore.EObject">
+                        <instanceof
+                              value="org.eclipse.uml2.uml.Class">
+                        </instanceof>
+                     </adapt>
+                  </iterate>
+               </visibleWhen>
+            </command>
+         </menu>
+      </menuContribution>
+   </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <command
+            id="org.polarsys.chess.monitoring.importCommand"
+            name="importLogCommand">
+      </command>
+   </extension>
+   <extension
+         point="org.eclipse.ui.handlers">
+      <handler
+            class="org.polarsys.chess.monitoring.monitoringxml.popup.actions.ImportLogHandler"
+            commandId="org.polarsys.chess.monitoring.importLogcommand">
+      </handler>
+   </extension>
 
 </plugin>
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/ImportLogHandler.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/ImportLogHandler.java
new file mode 100644
index 0000000..f3a68eb
--- /dev/null
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/ImportLogHandler.java
@@ -0,0 +1,125 @@
+/*

+-----------------------------------------------------------------------

+--                    CHESS monitoring plugin                        --

+--                                                                   --

+--                    Copyright (C) 2020                             --

+--                     Intecs - Italy                                --

+--                                                                   --                      --

+--                                                                   --

+-- All rights reserved. This program and the accompanying materials  --

+-- are made available under the terms of the Eclipse Public License  --

+-- v1.0 which accompanies this distribution, and is available at     --

+-- http://www.eclipse.org/legal/epl-v10.html                         --

+-----------------------------------------------------------------------

+  */ 

+

+package org.polarsys.chess.monitoring.monitoringxml.popup.actions;

+import java.net.URI;

+

+import org.eclipse.core.commands.AbstractHandler;

+import org.eclipse.core.commands.ExecutionEvent;

+import org.eclipse.core.commands.ExecutionException;

+import org.eclipse.core.filesystem.URIUtil;

+import org.eclipse.core.resources.IFile;

+import org.eclipse.core.resources.IProject;

+import org.eclipse.core.resources.IResource;

+import org.eclipse.core.resources.IWorkspace;

+import org.eclipse.core.resources.IWorkspaceRoot;

+import org.eclipse.core.resources.ResourcesPlugin;

+import org.eclipse.emf.ecore.EObject;

+import org.eclipse.jface.viewers.ISelection;

+import org.eclipse.jface.viewers.ITreeSelection;

+import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;

+import org.eclipse.swt.SWT;

+import org.eclipse.swt.widgets.FileDialog;

+import org.eclipse.swt.widgets.Shell;

+import org.eclipse.ui.IEditorInput;

+import org.eclipse.ui.IEditorPart;

+import org.eclipse.ui.ISelectionService;

+import org.eclipse.ui.IWorkbenchPage;

+import org.eclipse.ui.IWorkbenchWindow;

+import org.eclipse.ui.PlatformUI;

+import org.eclipse.ui.handlers.HandlerUtil;

+import org.eclipse.uml2.uml.Class;

+

+//invoked on an AnalysisContext, performs the trace analysis and back propagation

+public class ImportLogHandler extends AbstractHandler {

+

+

+	@Override

+	public Object execute(ExecutionEvent event) throws ExecutionException {

+		

+		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

+		

+		

+		ISelectionService selectionService = window.getSelectionService();

+		ISelection selectionX = selectionService.getSelection();

+		if (!(selectionX instanceof ITreeSelection)){

+			//ResourceNotification.showOk("Please invoke the command on a single selection on the ModelExplorer");

+			return null;

+		}

+		ITreeSelection treesel = (ITreeSelection)selectionX;

+		if (treesel.getPaths().length == 0 ||  treesel.getPaths().length > 1){

+			//ResourceNotification.showError("Please invoke command on a single selection on the ModelExplorer");

+			return null;

+		}

+		

+		Object obj = treesel.getFirstElement();

+		if (!(obj instanceof EObjectTreeElement)){

+			//ResourceNotification.showError("Please invoke the Build Instance command on a single selection on the ModelExplorer");

+			return null;

+		}

+		EObject eobj = ((EObjectTreeElement) obj).getEObject();

+		final Class umlClass = (Class) eobj;

+				

+		//get the current project

+		umlClass.eResource().getResourceSet();

+		

+		IWorkbenchPage activePage = window.getActivePage();

+		IEditorPart activeEditor = activePage.getActiveEditor();

+

+		if (activeEditor != null) {

+		   IEditorInput input = activeEditor.getEditorInput();

+

+		   IProject project = input.getAdapter(IProject.class);

+		   if (project == null) {

+		      IResource resource = input.getAdapter(IResource.class);

+		      if (resource != null) {

+		         project = resource.getProject();

+		         

+		      }

+		   }

+		   IFile monitorinFile = project.getFile("\\src-gen_model\\monitoring.xml");

+		   if (monitorinFile.exists()){

+			   //ask for log file

+			   Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

+			   FileDialog dialog = new FileDialog(activeShell, SWT.OPEN);

+			   dialog.setFilterExtensions(new String [] {""});

+			   String logPath = dialog.open();

+			   

+			   IWorkspace workspace = ResourcesPlugin.getWorkspace();

+			   IWorkspaceRoot root = workspace.getRoot();

+			 

+			   URI logURI = URIUtil.toURI(logPath);

+			   IFile[] logfiles = root.findFilesForLocationURI(logURI);

+			  

+			   //first let's analyze the trace

+			   LaunchTraceAnalysis traceAnalysis = new LaunchTraceAnalysis(activeShell, logfiles[0], null, monitorinFile, false);

+			   traceAnalysis.run(null);

+			   

+			   //now back propagation...

+			   IFile analyzedTraceFile = project.getFile("\\src-gen_model\\"+umlClass.getName()+"_monitoring.xml");

+			   IFile umlFile = project.getFile(umlClass.eResource().getURI().lastSegment());

+			   if (umlFile.exists() && analyzedTraceFile.exists()){

+				   LaunchBackpropagation back = new LaunchBackpropagation(activeShell, analyzedTraceFile, umlFile, null);

+				   back.run(null);

+			   }

+			  

+		   }

+		}

+		

+		return null;

+		

+	}

+

+}

diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchBackpropagation.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchBackpropagation.java
index 0af9775..d8aa5aa 100644
--- a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchBackpropagation.java
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchBackpropagation.java
@@ -2,8 +2,9 @@
 -----------------------------------------------------------------------
 --                    CHESS monitoring plugin                        --
 --                                                                   --
---                    Copyright (C) 2015-2016                        --
---                 Malardalen University, Sweden                       --
+--                    Copyright (C) 2015-2020                        --
+--                 Malardalen University, Sweden
+--					Intecs, Italy
 --                                                                   --                      --
 --                                                                   --
 -- All rights reserved. This program and the accompanying materials  --
@@ -76,8 +77,6 @@
 	private IFile xmlFile;
 	private IFile chessFile;
 	private IWorkspaceRoot root;
-//	private IWorkbenchPart part;
-//	private ISelection selection;
 
 	private static String XML_MODEL_PATH;
 	private static Resource XML_MODEL_RESOURCE;
@@ -119,7 +118,8 @@
 		}
 		
 		try {
-			chessFile = handleBrowseFile("Monitoring backpropagation from XML", "Please choose the target model");
+			if (chessFile == null)
+				chessFile = handleBrowseFile("Monitoring backpropagation from XML", "Please choose the target model");
 			this.backpropagateMonitoringMeasures(xmlFile, chessFile);
 			MessageDialog.openInformation(shell,"Monitoring backpropagation","The backpropagation has been successfully executed.");
 		} catch(Exception exMB){
@@ -211,12 +211,17 @@
 	
 				if(monitor.isCanceled())
 					throw new OperationCanceledException();
-				
+				try {
+					chessFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+				} catch (CoreException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
         monitor.worked(100);
         monitor.done(); 
         
         }});
-			chessFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+			//chessFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
 	}catch(Exception ex){//throw new OperationCanceledException("Operation aborted by the user.");};}
 		throw new OperationCanceledException(ex.getMessage());
 	}
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchTraceAnalysis.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchTraceAnalysis.java
index 2e82ada..b1c2269 100644
--- a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchTraceAnalysis.java
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/monitoringxml/popup/actions/LaunchTraceAnalysis.java
@@ -49,7 +49,7 @@
 
 	private Shell shell;
 	private IFile traceFile;
-	private IFile inXMLFile;
+	private IFile inXMLFile = null;
 	private String outXMLFileName;
 	private IWorkspaceRoot root;
 //	private IWorkbenchPart part;
@@ -59,6 +59,7 @@
 	private static Resource XML_MODEL_RESOURCE;
 	private static String UML_MODEL_PATH;
 	private static Resource UML_MODEL_RESOURCE;
+	private boolean showMsg = true;
 
 	/**
 	 * Constructor for Action1.
@@ -72,6 +73,15 @@
 		this.traceFile = inTraceFile;
 		this.root = inRoot;
 	}
+	
+	public LaunchTraceAnalysis(final Shell inShell, final IFile inTraceFile, final IWorkspaceRoot inRoot, IFile inXMLFile, boolean showMsgDialog) {
+		this.shell = inShell;
+		this.traceFile = inTraceFile;
+		this.root = inRoot;
+		this.inXMLFile = inXMLFile;
+		showMsg = showMsgDialog;
+	}
+	
 
 	/**
 	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
@@ -94,22 +104,26 @@
 //		URI xmlURI = URI.createFileURI(path.toString());
 //		Resource inXMLResource = resourceSet.getResource(xmlURI, true);		
 
-		if (!traceFile.getLocation().getFileExtension().equals("txt")) {
-			MessageDialog.openError(shell, "The selected file is not a TXT file. To perform monitoring Analysis please select the TXT file containing execution traces. " ,"Monitoring Analysis has failed");
-		}
+//		if (!traceFile.getLocation().getFileExtension().equals("txt")) {
+//			MessageDialog.openError(shell, "The selected file is not a TXT file. To perform monitoring Analysis please select the TXT file containing execution traces. " ,"Monitoring Analysis has failed");
+//		}
 		
 		//final LaunchTraceAnalysis mab = new LaunchTraceAnalysis(shell, traceFile, root);
 		try {
-			this.inXMLFile = handleBrowseFile("Monitoring trace analysis", "Please choose the input XML list of threads");
+			if (inXMLFile == null)
+				this.inXMLFile = handleBrowseFile("Monitoring trace analysis", "Please choose the input XML list of threads");
 			this.outXMLFileName = inXMLFile.getName();
 			TraceAnalyser ta = new TraceAnalyser(shell, inXMLFile, outXMLFileName, traceFile);
 			ta.doTraceAnalysis();
-			MessageDialog.openInformation(shell,"Monitoring trace analysis","The analysis has been successfully executed.");
+			if (showMsg)
+				MessageDialog.openInformation(shell,"Monitoring trace analysis","The analysis has been successfully executed.");
 		} catch(Exception exMA){
 			System.out.println(exMA.getMessage());
-			if(!exMA.getMessage().isEmpty())
-				MessageDialog.openError(shell,"Monitoring analysis", exMA.getMessage());	
-			else MessageDialog.openError(shell,"Monitoring analysis", "The analysis has not been successfully executed.");
+			if (showMsg){
+				if(!exMA.getMessage().isEmpty())
+					MessageDialog.openError(shell,"Monitoring analysis", exMA.getMessage());	
+				else MessageDialog.openError(shell,"Monitoring analysis", "The analysis has not been successfully executed.");
+			}
 		};
 	}
 
@@ -225,4 +239,8 @@
 	public static Resource getModelResource(){
 		return UML_MODEL_RESOURCE;
 	}
+	
+	
+	
+	
 }
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/MonitoringPreferencePage.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/MonitoringPreferencePage.java
new file mode 100644
index 0000000..076dd8e
--- /dev/null
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/MonitoringPreferencePage.java
@@ -0,0 +1,53 @@
+/*
+-----------------------------------------------------------------------
+--                    CHESS monitoring plugin                        --
+--                                                                   --
+--                    Copyright (C) 2020                             --
+--                     Intecs - Italy                                --
+--                                                                   --                      --
+--                                                                   --
+-- All rights reserved. This program and the accompanying materials  --
+-- are made available under the terms of the Eclipse Public License  --
+-- v1.0 which accompanies this distribution, and is available at     --
+-- http://www.eclipse.org/legal/epl-v10.html                         --
+-----------------------------------------------------------------------
+  */ 
+
+
+package org.polarsys.chess.monitoring.preferences;
+
+import org.eclipse.jface.preference.*;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.polarsys.chess.monitoring.monitoringxml.Activator;
+
+
+public class MonitoringPreferencePage
+	extends FieldEditorPreferencePage
+	implements IWorkbenchPreferencePage {
+
+	public MonitoringPreferencePage() {
+		super(GRID);
+		setPreferenceStore(Activator.getDefault().getPreferenceStore());
+		//setDescription("n");
+	}
+	
+	/**
+	 * Creates the field editors. Field editors are abstractions of
+	 * the common GUI blocks needed to manipulate various types
+	 * of preferences. Each field editor knows how to save and
+	 * restore itself.
+	 */
+	public void createFieldEditors() {
+	
+		addField(
+			new IntegerFieldEditor(PreferenceConstants.COUNTER_SCALE_FACTOR_INT, "Counter scale factor", getFieldEditorParent()));
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+	 */
+	public void init(IWorkbench workbench) {
+	}
+	
+}
\ No newline at end of file
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceConstants.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceConstants.java
new file mode 100644
index 0000000..0e57e73
--- /dev/null
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceConstants.java
@@ -0,0 +1,26 @@
+/*
+-----------------------------------------------------------------------
+--                    CHESS monitoring plugin                        --
+--                                                                   --
+--                    Copyright (C) 2020                             --
+--                     Intecs - Italy                                --
+--                                                                   --                      --
+--                                                                   --
+-- All rights reserved. This program and the accompanying materials  --
+-- are made available under the terms of the Eclipse Public License  --
+-- v1.0 which accompanies this distribution, and is available at     --
+-- http://www.eclipse.org/legal/epl-v10.html                         --
+-----------------------------------------------------------------------
+  */ 
+
+
+package org.polarsys.chess.monitoring.preferences;
+
+/**
+ * Constant definitions for plug-in preferences
+ */
+public class PreferenceConstants {
+
+	public static final String COUNTER_SCALE_FACTOR_INT = "Counter scale factor";
+	
+}
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceInitializer.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceInitializer.java
new file mode 100644
index 0000000..f9aef83
--- /dev/null
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/preferences/PreferenceInitializer.java
@@ -0,0 +1,39 @@
+/*
+-----------------------------------------------------------------------
+--                    CHESS monitoring plugin                        --
+--                                                                   --
+--                    Copyright (C) 2020                             --
+--                     Intecs - Italy                                --
+--                                                                   --                      --
+--                                                                   --
+-- All rights reserved. This program and the accompanying materials  --
+-- are made available under the terms of the Eclipse Public License  --
+-- v1.0 which accompanies this distribution, and is available at     --
+-- http://www.eclipse.org/legal/epl-v10.html                         --
+-----------------------------------------------------------------------
+  */ 
+
+package org.polarsys.chess.monitoring.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.polarsys.chess.monitoring.monitoringxml.Activator;
+
+/**
+ * Class used to initialize default preference values.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+	 */
+	public void initializeDefaultPreferences() {
+		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+		store.setDefault(PreferenceConstants.COUNTER_SCALE_FACTOR_INT,
+				"1");
+	}
+
+}
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/Parameters.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/Parameters.java
index 61e3eaa..1967dcb 100644
--- a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/Parameters.java
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/Parameters.java
@@ -22,6 +22,8 @@
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
+import org.polarsys.chess.monitoring.monitoringxml.Activator;
+import org.polarsys.chess.monitoring.preferences.PreferenceConstants;
 import org.polarsys.chess.monitoring.traceanalyser.Event;
 import org.polarsys.chess.monitoring.traceanalyser.EventType;
 import org.polarsys.chess.monitoring.traceanalyser.ThreadEvents;
@@ -59,6 +61,7 @@
 	private double clockRate; 	
 	private IFolder traceExtractionPath; // This path is used to output files that contains all the values of execution time, inter-arrival time and response time
 	private int noOfThreads; 
+	private int counterScaleFactor = 1;
 
 	public Parameters(TraceReader inTrace, IFolder inTraceExtractionPath) 
 	{
@@ -66,6 +69,7 @@
 		threadSpecificEvents = trace.GetThreadSpecificEvents();
 		threadIDs = trace.GetThreadIDs(); 
 		noOfThreads = threadIDs.size();
+		//clock rate can be passed through the log file (optional value), in the first line; the trace analyzed is in charge to retrieve it, if available
 		clockRate = trace.GetClockRate(); 
 
 		this.traceExtractionPath = inTraceExtractionPath; 
@@ -97,6 +101,11 @@
 		varianceInArrivalTimeOfAllThreads = new ArrayList<Double>(noOfThreads); 
 		varianceInBlockingOfAllThreads = new ArrayList<Double>(noOfThreads); 
 		varianceInResponseTimeOfAllThreads = new ArrayList<Double>(noOfThreads); 
+		
+		counterScaleFactor = Integer.parseInt(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.COUNTER_SCALE_FACTOR_INT));
+		
+		clockRate = clockRate*counterScaleFactor;
+		
 	}
 
 	public void ComputeParameters()
@@ -272,6 +281,8 @@
 						previousEvent.PrintEvent();
 						System.out.print("before current event:");
 						currentEvent.PrintEvent();
+						//let's consider wakeup and sleep events...
+						executionTime += (currentEvent.GetTimeStamp() -previousEvent.GetTimeStamp()); 
 					} 
 					executionTimeOfThread.add(executionTime); 
 					blockingTimeOfThread.add(blockedTime); 
@@ -361,8 +372,6 @@
 	
 	public void WriteAllValuesInFile(ArrayList<Long> parameter, IFolder path, String fileName) throws IOException
 	{
-//		File dir = new File(path);
-//		dir.mkdirs();
 
 		IFile outputFile = path.getProject().getFile(path.getProjectRelativePath()+ File.separator +fileName);
 		FileWriter fstream = new FileWriter(outputFile.getLocation().toOSString());
@@ -467,4 +476,8 @@
 	public ArrayList<Double> GetAverageInterArrivalTimeOfAllThreads() {
 		return averageInterArrivalTimeOfAllThreads;
 	}
+	
+	public Integer getCounterScaleFactor(){
+		return counterScaleFactor;
+	}
 }
\ No newline at end of file
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceAnalyser.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceAnalyser.java
index c509340..31f62bb 100644
--- a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceAnalyser.java
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceAnalyser.java
@@ -81,7 +81,7 @@
 		        if (monitor.isCanceled())
 					throw new OperationCanceledException();
 
-		        // Read trace file and get thread specific data
+		        // Read trace file and get thread specific data: clockRate, (optional, default is 1) and thread's eventss
 		        TraceReader trace;
 		        trace = new TraceReader(inTraceFile, inputFile, delimiter);
 		        monitor.worked(45);
@@ -96,7 +96,8 @@
 		        // Write output data in a file
 		        //WriteoutputFile(outputFileName, trace.GetAnalysisContext(), trace.GetThreadIDs(), parameters, unitFactor, unitName,trace.GetClockRate());
 		        try {
-		        	CreateMonitoringXMLOutput(inputFile, outputName, trace.GetAnalysisContext(), trace.GetThreadIDs(), parameters, unitFactor, unitName,trace.GetClockRate());
+		        	double factor = trace.GetClockRate()*parameters.getCounterScaleFactor();
+		        	CreateMonitoringXMLOutput(inputFile, outputName, trace.GetAnalysisContext(), trace.GetThreadIDs(), parameters, unitFactor, unitName,factor);
 		        } catch (Exception e) {
 		        	// TODO Auto-generated catch block
 		        	e.printStackTrace();
diff --git a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceReader.java b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceReader.java
index a8102c3..0e96712 100644
--- a/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceReader.java
+++ b/plugins/org.polarsys.chess.monitoring/src/org/polarsys/chess/monitoring/traceanalyser/TraceReader.java
@@ -25,6 +25,7 @@
 import javax.xml.parsers.DocumentBuilder;
 
 import org.eclipse.core.resources.IFile;
+import org.polarsys.chess.core.util.CHESSProjectSupport;
 import org.polarsys.chess.monitoring.traceanalyser.Event;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
@@ -54,7 +55,7 @@
 		
 		if(threadIDs.size() == 0)
 		{
-			System.out.println("Error: No thread ID to analyze.");
+			CHESSProjectSupport.printlnToCHESSConsole("Error: No thread ID to analyze.");
 			System.exit(0); 
 		}
 		
@@ -142,30 +143,49 @@
 			BufferedReader br = new BufferedReader(file); 
 			String strLine; 
 			Event event ;  
+			Boolean firstLine = true;
 			
-			strLine = br.readLine();
-			if(strLine != null)
-			{
-				strLine = strLine.trim();
-				String[] strEvent = strLine.split(delimiter);
-				
-				if(strEvent.length == 2 && strEvent[0].equals("clockrate"))
-				{
-					clockrate=Double.parseDouble(strEvent[1]);
-				}
-				else
-				{
-					System.out.println("Error: clockrate is not specified in the trace file.");
-					br.close();
-					return;
-				}
-			}
+//			strLine = br.readLine();
+//			if(strLine != null)
+//			{
+//				strLine = strLine.trim();
+//				String[] strEvent = strLine.split(delimiter);
+//				
+//				if(strEvent.length == 2 && strEvent[0].equals("clockrate"))
+//				{
+//					clockrate=Double.parseDouble(strEvent[1]);
+//				}
+//				else
+//				{
+//					//assume rate=1
+//					clockrate=1;
+//					CHESSProjectSupport.printlnToCHESSConsole("Clockrate is not available: 1 will be assumed");
+//					br.close();
+//					return;
+//				}
+//			}
 
 			while ((strLine = br.readLine()) != null) 
 			{
+				
 				strLine = strLine.trim();
 				String[] strEvent = strLine.split(delimiter); 
 				
+				if (firstLine){
+					if(strEvent.length == 2 && strEvent[0].equals("clockrate"))
+					{
+						clockrate=Double.parseDouble(strEvent[1]);
+						continue;
+					}
+					else
+					{
+						//assume rate=1
+						clockrate=1;
+						CHESSProjectSupport.printlnToCHESSConsole("Clockrate is not available: 1 will be assumed");
+					}
+					firstLine = false;
+				}
+				
 				if(strEvent.length ==3)
 				{	
 					event = new Event(Long.parseLong(strEvent[time_Stamp_Column]), Integer.parseInt(strEvent[event_ID_Column]), strEvent[thread_ID_Column]); 
@@ -175,7 +195,7 @@
 				}
 				else
 				{
-					System.out.println("Error: Some events do not follow the expected trace format.");
+					CHESSProjectSupport.printlnToCHESSConsole("Error: Some events do not follow the expected trace format.");
 					br.close();
 					return;
 				}
@@ -192,9 +212,9 @@
 	{
 		int indexOfThread = threadIDs.indexOf(tid); 
 
-		System.out.println("Time Stamp \t EventID \t ThreadID");
+		CHESSProjectSupport.printlnToCHESSConsole("Time Stamp \t EventID \t ThreadID");
 		for(Event event : threadSpecificEvents.get(indexOfThread))
-			System.out.println(event.GetTimeStamp()+"\t"+event.GetEventID() +"\t"+ event.GetThreadID());		
+			CHESSProjectSupport.printlnToCHESSConsole(event.GetTimeStamp()+"\t"+event.GetEventID() +"\t"+ event.GetThreadID());		
 	}
 
 	public void WriteThreadSpecificEventsIntoFile(String tid)