From 520a675eea6eddbf5427813c3d8f76306cfa151a Mon Sep 17 00:00:00 2001
From: Letitia Li <letitia.li@telecom-paristech.fr>
Date: Wed, 3 Jan 2018 10:24:03 +0100
Subject: [PATCH] Simulation Trace and Performance pragma fix

---
 .../c++2/src_simulator/arch/MultiCoreCPU.cpp  |  4 ++--
 .../c++2/src_simulator/arch/SingleCoreCPU.cpp |  4 ++--
 .../avatartranslator/AvatarPragmaLatency.java | 10 ++++-----
 .../java/avatartranslator/AvatarState.java    | 10 +++++++++
 .../java/ui/AvatarDesignPanelTranslator.java  | 22 ++++++++++++++++---
 .../JFrameAvatarInteractiveSimulation.java    |  4 ++--
 .../JFrameInteractiveSimulation.java          |  6 ++---
 7 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/simulators/c++2/src_simulator/arch/MultiCoreCPU.cpp b/simulators/c++2/src_simulator/arch/MultiCoreCPU.cpp
index e7a1fe8fb3..4217eeb0e3 100644
--- a/simulators/c++2/src_simulator/arch/MultiCoreCPU.cpp
+++ b/simulators/c++2/src_simulator/arch/MultiCoreCPU.cpp
@@ -438,7 +438,7 @@ int MultiCoreCPU::allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const
   int total = 0;
   for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){
     if (cpt >= begining) {
-      (*i)->toXML(glob, 1, _name);
+      (*i)->toXML(glob, 0, _name);
       total ++;
     }
     cpt ++;
@@ -451,7 +451,7 @@ void MultiCoreCPU::latencies2XML(std::ostringstream& glob, int id1, int id2) {
   for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){
 	if ((*i)->getCommand() !=NULL){
 	if ((*i)->getCommand()->getID() == id1 || (*i)->getCommand()->getID() == id2){
-	    (*i)->toXML(glob, 1, _name);
+	    (*i)->toXML(glob, 0, _name);
 	}
 	}
   }
diff --git a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp
index b90dd9e6e9..4bc2334287 100644
--- a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp
+++ b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp
@@ -428,7 +428,7 @@ int SingleCoreCPU::allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) cons
   int total = 0;
   for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){
     if (cpt >= begining) {
-      (*i)->toXML(glob, 1, _name);
+      (*i)->toXML(glob, 0, _name);
       total ++;
     }
     cpt ++;
@@ -440,7 +440,7 @@ void SingleCoreCPU::latencies2XML(std::ostringstream& glob, unsigned int id1, un
 	for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){
 		if ((*i)->getCommand() !=NULL){
 			if ((*i)->getCommand()->getID() == id1 || (*i)->getCommand()->getID() == id2){
-				(*i)->toXML(glob, 1, _name);
+				(*i)->toXML(glob, 0, _name);
 			}
 		}
 	}
diff --git a/src/main/java/avatartranslator/AvatarPragmaLatency.java b/src/main/java/avatartranslator/AvatarPragmaLatency.java
index 19db85bb5e..58276b8759 100644
--- a/src/main/java/avatartranslator/AvatarPragmaLatency.java
+++ b/src/main/java/avatartranslator/AvatarPragmaLatency.java
@@ -50,9 +50,9 @@ package avatartranslator;
 import java.util.List;
 
 public class AvatarPragmaLatency extends AvatarPragma {
-    private AvatarActionOnSignal state1;
+    private AvatarStateMachineElement state1;
     private AvatarBlock block1;
-	private AvatarActionOnSignal state2;
+	private AvatarStateMachineElement state2;
 	private AvatarBlock block2;
 	private int symbolType;
 	public static final int lessThan =1;
@@ -63,7 +63,7 @@ public class AvatarPragmaLatency extends AvatarPragma {
 	private List<String> id2;
 	private String pragmaString="";	
 
-    public AvatarPragmaLatency(String _name, Object _referenceObject, AvatarBlock block1, AvatarActionOnSignal state1, AvatarBlock block2, AvatarActionOnSignal state2,  int symbolType, int time, List<String> id1, List<String> id2, String pragmaString)
+    public AvatarPragmaLatency(String _name, Object _referenceObject, AvatarBlock block1, AvatarStateMachineElement state1, AvatarBlock block2, AvatarStateMachineElement state2,  int symbolType, int time, List<String> id1, List<String> id2, String pragmaString)
     {
         super(_name, _referenceObject);
         this.block1 = block1;
@@ -77,7 +77,7 @@ public class AvatarPragmaLatency extends AvatarPragma {
 		this.pragmaString=pragmaString;
     }
 
-    public AvatarActionOnSignal getState1()
+    public AvatarStateMachineElement getState1()
     {
         return this.state1;
     }
@@ -87,7 +87,7 @@ public class AvatarPragmaLatency extends AvatarPragma {
         return this.block1;
     }
 
-    public AvatarActionOnSignal getState2()
+    public AvatarStateMachineElement getState2()
     {
         return this.state2;
     }
diff --git a/src/main/java/avatartranslator/AvatarState.java b/src/main/java/avatartranslator/AvatarState.java
index 0f0290414d..880eb41b46 100644
--- a/src/main/java/avatartranslator/AvatarState.java
+++ b/src/main/java/avatartranslator/AvatarState.java
@@ -51,6 +51,7 @@ public class AvatarState extends AvatarStateElement {
     private String entryCode;
     private boolean hidden; // i.e, not present in the original state machine
     public int stateID; // to be used by code generator to more efficiently keep track of states.
+	private boolean checkLatency;
 
     public AvatarState(String _name, Object _referenceObject) {
         super(_name, _referenceObject);
@@ -81,6 +82,15 @@ public class AvatarState extends AvatarStateElement {
     public String getNiceName() {
         return "State " + getName();
     }
+    
+    public boolean getCheckLatency(){
+		return checkLatency;
+	}
+	
+	public void setCheckLatency(boolean b){
+		checkLatency=b;
+	}
+
 
     public int hasEmptyTransitionsOnItself(AvatarStateMachine _asm) {
         AvatarTransition at;
diff --git a/src/main/java/ui/AvatarDesignPanelTranslator.java b/src/main/java/ui/AvatarDesignPanelTranslator.java
index 72d8905efe..892e452735 100644
--- a/src/main/java/ui/AvatarDesignPanelTranslator.java
+++ b/src/main/java/ui/AvatarDesignPanelTranslator.java
@@ -270,7 +270,7 @@ public class AvatarDesignPanelTranslator {
 		String block1 = p1.split("\\.")[0];
 		String state1 = p1.split("\\.")[1];
 		AvatarBlock bl1;
-		AvatarActionOnSignal st1=null;
+		AvatarStateMachineElement st1=null;
 		List<String> id1= new ArrayList<String>();
 		bl1 = as.getBlockWithName(block1);
 		if (bl1==null){
@@ -288,6 +288,14 @@ public class AvatarDesignPanelTranslator {
 				st1= aaos;
 			}
 		}
+		AvatarState astate1 = asm.getStateWithName(state1);
+		if (astate1!=null){
+			if (astate1.getCheckLatency()){
+				id1.add("State-"+state1 + ":"+ astate1.getID());
+				st1= astate1;
+			}
+		}
+		
 		if (id1.size()==0){
 			UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, "Cannot find checkable state " + block1+ "." + state1 + " in pragma");
 		   	ce.setTDiagramPanel(adp.getAvatarBDPanel());
@@ -320,7 +328,7 @@ public class AvatarDesignPanelTranslator {
 
 
 		AvatarBlock bl2;
-		AvatarActionOnSignal st2=null;
+		AvatarStateMachineElement st2=null;
 
 		bl2 = as.getBlockWithName(block2);
 		if (bl2==null){
@@ -342,6 +350,14 @@ public class AvatarDesignPanelTranslator {
 			}
 		}
 		
+		AvatarState astate2 = asm.getStateWithName(state2);
+		if (astate2!=null){
+			if (astate2.getCheckLatency()){
+				id2.add("State-"+state2 + ":"+ astate2.getID());
+				st2= astate2;
+			}
+		}
+		
 		if (id2.size()==0){
 			UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, "Cannot find checkable state " + block2+ "." + state2 + " in pragma");
 		   	ce.setTDiagramPanel(adp.getAvatarBDPanel());
@@ -1594,7 +1610,7 @@ public class AvatarDesignPanelTranslator {
         astate.addReferenceObject (tgc);
         tgc.setAVATARID (astate.getID());
 		if (tgc.getCheckLatency()){
-		//	astate.setCheckLatency(true);
+			astate.setCheckLatency(true);
 			_as.checkedIDs.add(tgc.getName()+"-"+tgc.getValue()+":"+astate.getID());
 		}
     }
diff --git a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
index 11b0b717f4..dcd604a490 100755
--- a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
+++ b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java
@@ -927,8 +927,8 @@ public  class JFrameAvatarInteractiveSimulation extends JFrame implements Avatar
         jspLatency = new JScrollPane(latTable);
         jspLatency.setWheelScrollingEnabled(true);
         jspLatency.getVerticalScrollBar().setUnitIncrement(10);
-        jspLatency.setMinimumSize(new Dimension(250, 50));
-        jspLatency.setPreferredSize(new Dimension(250, 50));
+        jspLatency.setMinimumSize(new Dimension(450, 100));
+        jspLatency.setPreferredSize(new Dimension(450, 100));
         latencyPanel.add(jspLatency, c0);
 
 
diff --git a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java
index 3bbcf132a3..3a6497ebcc 100755
--- a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java
+++ b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java
@@ -1534,7 +1534,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene
 		}
 		
 		try {
-			if ((command.equals("Write") || command.equals("Read")) && tran.deviceName.contains("CPU")){
+			if ((command.equals("Write") || command.equals("Read")) && tran.nodeType.equals("0")){
 				TMLChannel chan = tmap.getTMLModeling().getChannelByShortName(tran.channelName);
 				if (chan!=null){
 					TMLTask originTask = chan.getOriginTask();
@@ -1581,7 +1581,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene
 					}
 				}
 			}
-			else if ((command.equals("Send") || command.equals("Wait") || command.equals("SelectEvent"))  && tran.deviceName.contains("CPU") && !tran.channelName.startsWith("reqChannel")){
+			else if ((command.equals("Send") || command.equals("Wait") || command.equals("SelectEvent"))  && tran.nodeType.equals("0") && !tran.channelName.startsWith("reqChannel")){
 				if (command.equals("SelectEvent")){
 					String trace="time="+tran.endTime+ " block=" + tran.taskName + " type=state_entering state=SelectEvent";
 					if (!simtraces.contains(trace)){
@@ -1634,7 +1634,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene
 					}
 				}
 			}
-			else if ((command.equals("Request") || command.equals("Wait")) && tran.deviceName.contains("CPU") && tran.channelName.startsWith("reqChannel")){
+			else if ((command.equals("Request") || command.equals("Wait")) && tran.nodeType.equals("0") && tran.channelName.startsWith("reqChannel")){
 				TMLRequest req=null;
 				for (TMLRequest request: tmap.getTMLModeling().getRequests()){
 					if (tran.channelName.replaceAll("reqChannel_","").equals(request.getDestinationTask().getName())){						
-- 
GitLab