From 6b12c251bb191bd1d92b7d282ddf53bbde9feaea Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Fri, 20 May 2016 14:42:18 +0000 Subject: [PATCH] Update on simulator: new cmd to list transactions, and graphnical representation --- simulators/c++2/Makefile.defs | 5 +- .../c++2/src_simulator/TMLTransaction.cpp | 13 +- .../c++2/src_simulator/TMLTransaction.h | 7 +- simulators/c++2/src_simulator/arch/Bus.cpp | 16 + simulators/c++2/src_simulator/arch/Bus.h | 7 + simulators/c++2/src_simulator/arch/CPU.h | 2 +- .../src_simulator/arch/SchedulableDevice.h | 6 + .../c++2/src_simulator/arch/SingleCoreCPU.cpp | 841 +-- .../c++2/src_simulator/arch/SingleCoreCPU.h | 11 +- simulators/c++2/src_simulator/definitions.h | 4 +- .../c++2/src_simulator/sim/Simulator.cpp | 2703 ++++----- simulators/c++2/src_simulator/sim/Simulator.h | 2 +- src/remotesimulation/CommandParser.java | 943 +-- src/remotesimulation/RemoteConnection.java | 168 +- .../GenericTransaction.java | 114 +- .../InteractiveSimulationActions.java | 254 +- .../JFrameInteractiveSimulation.java | 5287 +++++++++-------- .../SimulationTransaction.java | 72 + 18 files changed, 5351 insertions(+), 5104 deletions(-) create mode 100755 src/ui/interactivesimulation/SimulationTransaction.java diff --git a/simulators/c++2/Makefile.defs b/simulators/c++2/Makefile.defs index 56ed9af65a..52f218aea5 100644 --- a/simulators/c++2/Makefile.defs +++ b/simulators/c++2/Makefile.defs @@ -36,7 +36,10 @@ $(OBJDIR)/%.o: $(SRCS_base_DIR)/%.cpp $(OBJDIR)/%.o: ./%.cpp $(CC) $(CFLAGS) $(INCDIR) -o $@ -c $< -clean:: +test: + ./run.x -oxml answer.xml -cmd '1 2 1000000;22 100;7 0 vcddump.vcd' + +clean: rm -f $(OBJS_simulator) $(OBJS) *~ $(EXE) core ultraclean: clean diff --git a/simulators/c++2/src_simulator/TMLTransaction.cpp b/simulators/c++2/src_simulator/TMLTransaction.cpp index a0fcf7f9d5..ab1c44c35c 100755 --- a/simulators/c++2/src_simulator/TMLTransaction.cpp +++ b/simulators/c++2/src_simulator/TMLTransaction.cpp @@ -79,7 +79,18 @@ std::string TMLTransaction::toShortString() const{ } -void toXML(std::ostringstream& glob, int deviceID, std::string deviceNAME) const { +void TMLTransaction::toXML(std::ostringstream& glob, int deviceID, std::string deviceName) const { + if (_command==0) { + glob << TAG_TRANSo << " deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" command=\"0\""; + } else { + glob << TAG_TRANSo << " deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" command=\"" << _command->toShortString() << "\""; + glob << " starttime=\"" << _startTime << "\" length=\"" << _length << "\" virtuallength=\"" << _virtualLength << "\""; + if (_channel!=0) glob << " ch=\"" << _channel->toShortString() << "\""; + } + + + glob << TAG_TRANSc << "\n"; + } diff --git a/simulators/c++2/src_simulator/TMLTransaction.h b/simulators/c++2/src_simulator/TMLTransaction.h index d349ccadd9..6fb712e34f 100644 --- a/simulators/c++2/src_simulator/TMLTransaction.h +++ b/simulators/c++2/src_simulator/TMLTransaction.h @@ -47,7 +47,7 @@ Ludovic Apvrille, Renaud Pacalet class TMLCommand; class TMLChannel; -class TMLTransaction{ +class TMLTransaction { public: ///Constructor /** @@ -214,6 +214,8 @@ public: */ inline void setChannel(TMLChannel* iChannel) {_channel=iChannel;} ///Get channel on which data was conveyed + + /** \return Pointer to channel */ @@ -227,7 +229,8 @@ public: inline void setStateID(ID iID) {_stateID=iID;} inline ID getStateID() {return _stateID;} - void toXML(std::ostringstream& glob, int deviceID, std::string deviceNAME) const; + void toXML(std::ostringstream& glob, int deviceID, std::string deviceName) const; + protected: ///Time when the transaction became runnable diff --git a/simulators/c++2/src_simulator/arch/Bus.cpp b/simulators/c++2/src_simulator/arch/Bus.cpp index 870998d3fb..81f77dede0 100644 --- a/simulators/c++2/src_simulator/arch/Bus.cpp +++ b/simulators/c++2/src_simulator/arch/Bus.cpp @@ -177,6 +177,22 @@ void Bus::schedule2TXT(std::ofstream& myfile) const{ } } +void Bus::allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const { + int size = _transactList.size(); + int begining = size - maxNbOfTrans; + if (begining <0) { + begining = 0; + } + int cpt =0; + for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ + if (cpt >= begining) { + (*i)->toXML(glob, 1, _name); + } + cpt ++; + } +} + + //Returns the next signal change (for vcd output) void Bus::getNextSignalChange(bool iInit, SignalChangeData* oSigData){ //std::ostringstream outp; diff --git a/simulators/c++2/src_simulator/arch/Bus.h b/simulators/c++2/src_simulator/arch/Bus.h index 8229488911..81fe3bc0ab 100644 --- a/simulators/c++2/src_simulator/arch/Bus.h +++ b/simulators/c++2/src_simulator/arch/Bus.h @@ -102,6 +102,12 @@ public: */ std::string toShortString() const; ///Writes a HTML representation of the schedule to an output file + + /** + \param glob refers to the output stream + */ + void allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const; + /** \param myfile Reference to the ofstream object representing the output file */ @@ -111,6 +117,7 @@ public: \param myfile Reference to the ofstream object representing the output file */ void schedule2TXT(std::ofstream& myfile) const; + void getNextSignalChange(bool iInit, SignalChangeData* oSigData); virtual void streamBenchmarks(std::ostream& s) const; virtual void reset(); diff --git a/simulators/c++2/src_simulator/arch/CPU.h b/simulators/c++2/src_simulator/arch/CPU.h index c0093c9964..1c125bd2cd 100755 --- a/simulators/c++2/src_simulator/arch/CPU.h +++ b/simulators/c++2/src_simulator/arch/CPU.h @@ -62,7 +62,7 @@ enum vcdCPUVisState }; ///Represents the base class for CPUs -class CPU: public SchedulableDevice, public TraceableDevice{ +class CPU: public SchedulableDevice, public TraceableDevice { public: ///Constructor /** diff --git a/simulators/c++2/src_simulator/arch/SchedulableDevice.h b/simulators/c++2/src_simulator/arch/SchedulableDevice.h index aa633e26d4..8ed184e67a 100644 --- a/simulators/c++2/src_simulator/arch/SchedulableDevice.h +++ b/simulators/c++2/src_simulator/arch/SchedulableDevice.h @@ -87,6 +87,12 @@ public: \param myfile Reference to the ofstream object representing the output file */ virtual void schedule2TXT(std::ofstream& myfile) const =0; + + /** + \param glob references the output stream object + */ + virtual void allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const =0; + virtual std::string toString() const =0; virtual std::istream& readObject(std::istream &is){ READ_STREAM(is,_endSchedule); diff --git a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp index 7cdce1382d..0a4d9fde5b 100644 --- a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp +++ b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp @@ -1,42 +1,42 @@ /*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, -Ludovic Apvrille, Renaud Pacalet - * - * ludovic.apvrille AT telecom-paristech.fr - * - * This software is a computer program whose purpose is to allow the - * edition of TURTLE analysis, design and deployment diagrams, to - * allow the generation of RT-LOTOS or Java code from this diagram, - * and at last to allow the analysis of formal validation traces - * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP - * from INRIA Rhone-Alpes. - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ + Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ #include <SingleCoreCPU.h> #include <TMLTask.h> @@ -49,484 +49,493 @@ Ludovic Apvrille, Renaud Pacalet SingleCoreCPU::SingleCoreCPU(ID iID, std::string iName, WorkloadSource* iScheduler, TMLTime iTimePerCycle, unsigned int iCyclesPerExeci, unsigned int iCyclesPerExecc, unsigned int iPipelineSize, unsigned int iTaskSwitchingCycles, unsigned int iBranchingMissrate, unsigned int iChangeIdleModeCycles, unsigned int iCyclesBeforeIdle, unsigned int ibyteDataSize): CPU(iID, iName, iScheduler), /*_lastTransaction(0),*/ _masterNextTransaction(0), _timePerCycle(iTimePerCycle) #ifdef PENALTIES_ENABLED -, _pipelineSize(iPipelineSize), _taskSwitchingCycles(iTaskSwitchingCycles),_brachingMissrate(iBranchingMissrate) -, _changeIdleModeCycles(iChangeIdleModeCycles), _cyclesBeforeIdle(iCyclesBeforeIdle) -#endif -, _cyclesPerExeci(iCyclesPerExeci) /*, _busyCycles(0)*/ + , _pipelineSize(iPipelineSize), _taskSwitchingCycles(iTaskSwitchingCycles),_brachingMissrate(iBranchingMissrate) + , _changeIdleModeCycles(iChangeIdleModeCycles), _cyclesBeforeIdle(iCyclesBeforeIdle) +#endif + , _cyclesPerExeci(iCyclesPerExeci) /*, _busyCycles(0)*/ #ifdef PENALTIES_ENABLED -, _timePerExeci(_cyclesPerExeci * _timePerCycle * (_pipelineSize * _brachingMissrate + 100 - _brachingMissrate) /100.0) -,_taskSwitchingTime(_taskSwitchingCycles*_timePerCycle) -, _timeBeforeIdle(_cyclesBeforeIdle*_timePerCycle) -, _changeIdleModeTime(_changeIdleModeCycles*_timePerCycle) + , _timePerExeci(_cyclesPerExeci * _timePerCycle * (_pipelineSize * _brachingMissrate + 100 - _brachingMissrate) /100.0) + ,_taskSwitchingTime(_taskSwitchingCycles*_timePerCycle) + , _timeBeforeIdle(_cyclesBeforeIdle*_timePerCycle) + , _changeIdleModeTime(_changeIdleModeCycles*_timePerCycle) #else -, _timePerExeci(_cyclesPerExeci*_timePerCycle) + , _timePerExeci(_cyclesPerExeci*_timePerCycle) #endif -//, _pipelineSizeTimesExeci(_pipelineSize * _timePerExeci) -//,_missrateTimesPipelinesize(_brachingMissrate*_pipelineSize) + //, _pipelineSizeTimesExeci(_pipelineSize * _timePerExeci) + //,_missrateTimesPipelinesize(_brachingMissrate*_pipelineSize) { - //std::cout << "Time per EXECIiiiiiiiiiiiiiiiiiiiiii: " << _timePerExeci << "\n"; - //_transactList.reserve(BLOCK_SIZE); + //std::cout << "Time per EXECIiiiiiiiiiiiiiiiiiiiiii: " << _timePerExeci << "\n"; + //_transactList.reserve(BLOCK_SIZE); } -SingleCoreCPU::~SingleCoreCPU(){ - std::cout << _transactList.size() << " elements in List of " << _name << ", busy cycles: " << _busyCycles << std::endl; - std::cout << " consumption value " << ((_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle)<< std::endl; - - //delete _scheduler; +SingleCoreCPU::~SingleCoreCPU(){ + std::cout << _transactList.size() << " elements in List of " << _name << ", busy cycles: " << _busyCycles << std::endl; + std::cout << " consumption value " << ((_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle)<< std::endl; + + //delete _scheduler; } TMLTransaction* SingleCoreCPU::getNextTransaction(){ #ifdef BUS_ENABLED - if (_masterNextTransaction==0 || _nextTransaction==0){ - return _nextTransaction; - }else{ + if (_masterNextTransaction==0 || _nextTransaction==0){ + return _nextTransaction; + }else{ #ifdef DEBUG_CPU - std::cout << "CPU:getNT: " << _name << " has bus transaction on master " << _masterNextTransaction->toString() << std::endl; + std::cout << "CPU:getNT: " << _name << " has bus transaction on master " << _masterNextTransaction->toString() << std::endl; #endif - //std::cout << "CRASH Trans:" << _nextTransaction->toString() << std::endl << "Channel: " << _nextTransaction->getChannel() << "\n"; - BusMaster* aTempMaster = getMasterForBus(_nextTransaction->getChannel()->getFirstMaster(_nextTransaction)); - //std::cout << "1 aTempMaster: " << aTempMaster << std::endl; - bool aResult = aTempMaster->accessGranted(); - //std::cout << "2" << std::endl; - while (aResult && aTempMaster!=_masterNextTransaction){ - //std::cout << "3" << std::endl; - aTempMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); - //std::cout << "4" << std::endl; - aResult = aTempMaster->accessGranted(); - //std::cout << "5" << std::endl; - } - return (aResult)?_nextTransaction:0; - } + //std::cout << "CRASH Trans:" << _nextTransaction->toString() << std::endl << "Channel: " << _nextTransaction->getChannel() << "\n"; + BusMaster* aTempMaster = getMasterForBus(_nextTransaction->getChannel()->getFirstMaster(_nextTransaction)); + //std::cout << "1 aTempMaster: " << aTempMaster << std::endl; + bool aResult = aTempMaster->accessGranted(); + //std::cout << "2" << std::endl; + while (aResult && aTempMaster!=_masterNextTransaction){ + //std::cout << "3" << std::endl; + aTempMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); + //std::cout << "4" << std::endl; + aResult = aTempMaster->accessGranted(); + //std::cout << "5" << std::endl; + } + return (aResult)?_nextTransaction:0; + } #else - return _nextTransaction; + return _nextTransaction; #endif } void SingleCoreCPU::calcStartTimeLength(TMLTime iTimeSlice){ -#ifdef DEBUG_CPU - std::cout << "CPU:calcSTL: scheduling decision of CPU " << _name << ": " << _nextTransaction->toString() << std::endl; +#ifdef DEBUG_CPU + std::cout << "CPU:calcSTL: scheduling decision of CPU " << _name << ": " << _nextTransaction->toString() << std::endl; #endif #ifdef BUS_ENABLED - //std::cout << "get channel " << std::endl; - TMLChannel* aChannel=_nextTransaction->getCommand()->getChannel(0); - //std::cout << "after get channel " << std::endl; - if(aChannel==0){ - //std::cout << "no channel " << std::endl; - _masterNextTransaction=0; - }else{ - //std::cout << "get bus " << std::endl; - _masterNextTransaction= getMasterForBus(aChannel->getFirstMaster(_nextTransaction)); - //std::cout << "after get first bus " << std::endl; - if (_masterNextTransaction!=0){ - //std::cout << "before register transaction at bus " << std::endl; - _masterNextTransaction->registerTransaction(_nextTransaction); - //std::cout << "Transaction registered at bus " << std::endl; - } - } -#endif - //round to full cycles!!! - TMLTime aStartTime = max(_endSchedule,_nextTransaction->getRunnableTime()); - TMLTime aReminder = aStartTime % _timePerCycle; - if (aReminder!=0) aStartTime+=_timePerCycle - aReminder; - _nextTransaction->setStartTime(aStartTime); - + //std::cout << "get channel " << std::endl; + TMLChannel* aChannel=_nextTransaction->getCommand()->getChannel(0); + //std::cout << "after get channel " << std::endl; + if(aChannel==0){ + //std::cout << "no channel " << std::endl; + _masterNextTransaction=0; + }else{ + //std::cout << "get bus " << std::endl; + _masterNextTransaction= getMasterForBus(aChannel->getFirstMaster(_nextTransaction)); + //std::cout << "after get first bus " << std::endl; + if (_masterNextTransaction!=0){ + //std::cout << "before register transaction at bus " << std::endl; + _masterNextTransaction->registerTransaction(_nextTransaction); + //std::cout << "Transaction registered at bus " << std::endl; + } + } +#endif + //round to full cycles!!! + TMLTime aStartTime = max(_endSchedule,_nextTransaction->getRunnableTime()); + TMLTime aReminder = aStartTime % _timePerCycle; + if (aReminder!=0) aStartTime+=_timePerCycle - aReminder; + _nextTransaction->setStartTime(aStartTime); + #ifdef BUS_ENABLED - if (_masterNextTransaction==0){ + if (_masterNextTransaction==0){ #endif - //calculate length of transaction - //if (_nextTransaction->getOperationLength()!=-1){ - if (iTimeSlice!=0){ - _nextTransaction->setVirtualLength(max(min(_nextTransaction->getVirtualLength(), (TMLLength)(iTimeSlice /_timePerExeci)), (TMLTime)1)); - } - _nextTransaction->setLength(_nextTransaction->getVirtualLength()*_timePerExeci); - + //calculate length of transaction + //if (_nextTransaction->getOperationLength()!=-1){ + if (iTimeSlice!=0){ + _nextTransaction->setVirtualLength(max(min(_nextTransaction->getVirtualLength(), (TMLLength)(iTimeSlice /_timePerExeci)), (TMLTime)1)); + } + _nextTransaction->setLength(_nextTransaction->getVirtualLength()*_timePerExeci); + #ifdef BUS_ENABLED - } + } #endif #ifdef PENALTIES_ENABLED - if (_lastTransaction==0 || _lastTransaction->getCommand()->getTask()!=_nextTransaction->getCommand()->getTask()){ - _nextTransaction->setTaskSwitchingPenalty(_taskSwitchingTime); - } + if (_lastTransaction==0 || _lastTransaction->getCommand()->getTask()!=_nextTransaction->getCommand()->getTask()){ + _nextTransaction->setTaskSwitchingPenalty(_taskSwitchingTime); + } - if ((_nextTransaction->getStartTime()-_endSchedule) >=_timeBeforeIdle){ - _nextTransaction->setIdlePenalty(_changeIdleModeTime); - } + if ((_nextTransaction->getStartTime()-_endSchedule) >=_timeBeforeIdle){ + _nextTransaction->setIdlePenalty(_changeIdleModeTime); + } #endif } void SingleCoreCPU::truncateAndAddNextTransAt(TMLTime iTime){ - //std::cout << "CPU:schedule BEGIN " << _name << "+++++++++++++++++++++++++++++++++\n"; - //return truncateNextTransAt(iTime); - //not a problem if scheduling does not take place at time when transaction is actually truncated, tested - //std::cout << "CPU:truncateAndAddNextTransAt " << _name << "time: +++++++++++++++++++++" << iTime << "\n"; - TMLTime aTimeSlice = _scheduler->schedule(iTime); - //_schedulingNeeded=false; 05/05/11 - TMLTransaction* aNewTransaction =_scheduler->getNextTransaction(iTime); - //std::cout << "before if\n"; - - //_scheduler->transWasScheduled(this); //NEW was in if before 05/05/11 - - if (aNewTransaction!=_nextTransaction){ - //std::cout << "in if\n"; - if (truncateNextTransAt(iTime)!=0) addTransaction(0); - //if (_nextTransaction!=0 && truncateNextTransAt(iTime)!=0) addTransaction(); //NEW!!!! - if (_nextTransaction!=0 && _masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); - _nextTransaction = aNewTransaction; - if (_nextTransaction!=0) calcStartTimeLength(aTimeSlice); - } - //std::cout << "CPU:schedule END " << _name << "+++++++++++++++++++++++++++++++++\n"; + //std::cout << "CPU:schedule BEGIN " << _name << "+++++++++++++++++++++++++++++++++\n"; + //return truncateNextTransAt(iTime); + //not a problem if scheduling does not take place at time when transaction is actually truncated, tested + //std::cout << "CPU:truncateAndAddNextTransAt " << _name << "time: +++++++++++++++++++++" << iTime << "\n"; + TMLTime aTimeSlice = _scheduler->schedule(iTime); + //_schedulingNeeded=false; 05/05/11 + TMLTransaction* aNewTransaction =_scheduler->getNextTransaction(iTime); + //std::cout << "before if\n"; + + //_scheduler->transWasScheduled(this); //NEW was in if before 05/05/11 + + if (aNewTransaction!=_nextTransaction){ + //std::cout << "in if\n"; + if (truncateNextTransAt(iTime)!=0) addTransaction(0); + //if (_nextTransaction!=0 && truncateNextTransAt(iTime)!=0) addTransaction(); //NEW!!!! + if (_nextTransaction!=0 && _masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); + _nextTransaction = aNewTransaction; + if (_nextTransaction!=0) calcStartTimeLength(aTimeSlice); + } + //std::cout << "CPU:schedule END " << _name << "+++++++++++++++++++++++++++++++++\n"; } -TMLTime SingleCoreCPU::truncateNextTransAt(TMLTime iTime){ - if (_masterNextTransaction==0){ +TMLTime SingleCoreCPU::truncateNextTransAt(TMLTime iTime){ + if (_masterNextTransaction==0){ #ifdef PENALTIES_ENABLED - if (iTime < _nextTransaction->getStartTime()) return 0; - TMLTime aNewDuration = iTime - _nextTransaction->getStartTime(); - TMLTime aStaticPenalty = _nextTransaction->getIdlePenalty() + _nextTransaction->getTaskSwitchingPenalty(); - if (aNewDuration<=aStaticPenalty){ - _nextTransaction->setLength(_timePerExeci); - _nextTransaction->setVirtualLength(1); + if (iTime < _nextTransaction->getStartTime()) return 0; + TMLTime aNewDuration = iTime - _nextTransaction->getStartTime(); + TMLTime aStaticPenalty = _nextTransaction->getIdlePenalty() + _nextTransaction->getTaskSwitchingPenalty(); + if (aNewDuration<=aStaticPenalty){ + _nextTransaction->setLength(_timePerExeci); + _nextTransaction->setVirtualLength(1); #ifdef DEBUG_CPU - std::cout << "CPU:truncateNTA: transaction truncated\n"; + std::cout << "CPU:truncateNTA: transaction truncated\n"; #endif - }else{ - aNewDuration-=aStaticPenalty; - _nextTransaction->setVirtualLength(max((TMLTime)(aNewDuration /_timePerExeci),(TMLTime)1)); - _nextTransaction->setLength(_nextTransaction->getVirtualLength() *_timePerExeci); - } + }else{ + aNewDuration-=aStaticPenalty; + _nextTransaction->setVirtualLength(max((TMLTime)(aNewDuration /_timePerExeci),(TMLTime)1)); + _nextTransaction->setLength(_nextTransaction->getVirtualLength() *_timePerExeci); + } #else - if (iTime <= _nextTransaction->getStartTime()) return 0; //before: <= - TMLTime aNewDuration = iTime - _nextTransaction->getStartTime(); - _nextTransaction->setVirtualLength(max((TMLTime)(aNewDuration /_timePerExeci), (TMLTime)1)); - _nextTransaction->setLength(_nextTransaction->getVirtualLength() *_timePerExeci); + if (iTime <= _nextTransaction->getStartTime()) return 0; //before: <= + TMLTime aNewDuration = iTime - _nextTransaction->getStartTime(); + _nextTransaction->setVirtualLength(max((TMLTime)(aNewDuration /_timePerExeci), (TMLTime)1)); + _nextTransaction->setLength(_nextTransaction->getVirtualLength() *_timePerExeci); #endif #ifdef DEBUG_CPU - std::cout << "aNewDuration: " << aNewDuration << std::endl; - std::cout << "CPU:truncateNTA: ### cut transaction at " << _nextTransaction->getVirtualLength() << std::endl; + std::cout << "aNewDuration: " << aNewDuration << std::endl; + std::cout << "CPU:truncateNTA: ### cut transaction at " << _nextTransaction->getVirtualLength() << std::endl; #endif - } - return _nextTransaction->getOverallLength(); + } + return _nextTransaction->getOverallLength(); } bool SingleCoreCPU::addTransaction(TMLTransaction* iTransToBeAdded){ - bool aFinish; - //TMLTransaction* aTransCopy=0; - if (_masterNextTransaction==0){ - aFinish=true; + bool aFinish; + //TMLTransaction* aTransCopy=0; + if (_masterNextTransaction==0){ + aFinish=true; #ifdef DEBUG_CPU - std::cout << _name << "CPU:addT: non bus transaction added" << std::endl; + std::cout << _name << "CPU:addT: non bus transaction added" << std::endl; #endif - }else{ + }else{ #ifdef DEBUG_CPU - std::cout << _name << "CPU:addT: handling bus transaction" << std::endl; + std::cout << _name << "CPU:addT: handling bus transaction" << std::endl; #endif - //Slave* aLastSlave=_nextTransaction->getChannel()->getNextSlave(_nextTransaction); - BusMaster* aFollowingMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); - if (aFollowingMaster==0){ - //std::cout << "1\n"; - aFinish=true; - //aTransCopy = new TMLTransaction(*_nextTransaction); - //_nextTransaction = aTransCopy; - BusMaster* aTempMaster = getMasterForBus(_nextTransaction->getChannel()->getFirstMaster(_nextTransaction)); - //std::cout << "2\n"; - Slave* aTempSlave= _nextTransaction->getChannel()->getNextSlave(_nextTransaction); - //std::cout << "3\n"; - aTempMaster->addBusContention(_nextTransaction->getStartTime()-max(_endSchedule,_nextTransaction->getRunnableTime())); - while (aTempMaster!=0){ - //std::cout << "3a\n"; - aTempMaster->addTransaction(_nextTransaction); - //std::cout << "3b\n"; - //if (aTempSlave!=0) aTempSlave->addTransaction(_nextTransaction); - if (aTempSlave!=0) aTempSlave->addTransaction(_nextTransaction); //NEW - //std::cout << "4\n"; - aTempMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); - //std::cout << "5\n"; - aTempSlave= _nextTransaction->getChannel()->getNextSlave(_nextTransaction); - } - //std::cout << "6\n"; - }else{ - //std::cout << _name << " bus transaction next round" << std::endl; - _masterNextTransaction=aFollowingMaster; - //std::cout << "7\n"; - _masterNextTransaction->registerTransaction(_nextTransaction); - aFinish=false; - } - //std::cout << "8\n"; - } - if (aFinish){ + //Slave* aLastSlave=_nextTransaction->getChannel()->getNextSlave(_nextTransaction); + BusMaster* aFollowingMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); + if (aFollowingMaster==0){ + //std::cout << "1\n"; + aFinish=true; + //aTransCopy = new TMLTransaction(*_nextTransaction); + //_nextTransaction = aTransCopy; + BusMaster* aTempMaster = getMasterForBus(_nextTransaction->getChannel()->getFirstMaster(_nextTransaction)); + //std::cout << "2\n"; + Slave* aTempSlave= _nextTransaction->getChannel()->getNextSlave(_nextTransaction); + //std::cout << "3\n"; + aTempMaster->addBusContention(_nextTransaction->getStartTime()-max(_endSchedule,_nextTransaction->getRunnableTime())); + while (aTempMaster!=0){ + //std::cout << "3a\n"; + aTempMaster->addTransaction(_nextTransaction); + //std::cout << "3b\n"; + //if (aTempSlave!=0) aTempSlave->addTransaction(_nextTransaction); + if (aTempSlave!=0) aTempSlave->addTransaction(_nextTransaction); //NEW + //std::cout << "4\n"; + aTempMaster =_nextTransaction->getChannel()->getNextMaster(_nextTransaction); + //std::cout << "5\n"; + aTempSlave= _nextTransaction->getChannel()->getNextSlave(_nextTransaction); + } + //std::cout << "6\n"; + }else{ + //std::cout << _name << " bus transaction next round" << std::endl; + _masterNextTransaction=aFollowingMaster; + //std::cout << "7\n"; + _masterNextTransaction->registerTransaction(_nextTransaction); + aFinish=false; + } + //std::cout << "8\n"; + } + if (aFinish){ #ifdef DEBUG_CPU - std::cout << "CPU:addt: " << _name << " finalizing transaction " << _nextTransaction->toString() << std::endl; + std::cout << "CPU:addt: " << _name << " finalizing transaction " << _nextTransaction->toString() << std::endl; #endif - //_nextTransaction->getCommand()->execute(); //NEW!!!! - _endSchedule=_nextTransaction->getEndTime(); - //std::cout << "set end schedule CPU: " << _endSchedule << "\n"; - _simulatedTime=max(_simulatedTime,_endSchedule); - _overallTransNo++; //NEW!!!!!!!! - _overallTransSize+=_nextTransaction->getOperationLength(); //NEW!!!!!!!! - //std::cout << "lets crash execute\n"; - _nextTransaction->getCommand()->execute(); //NEW!!!! - //std::cout << "not crashed\n"; + //_nextTransaction->getCommand()->execute(); //NEW!!!! + _endSchedule=_nextTransaction->getEndTime(); + //std::cout << "set end schedule CPU: " << _endSchedule << "\n"; + _simulatedTime=max(_simulatedTime,_endSchedule); + _overallTransNo++; //NEW!!!!!!!! + _overallTransSize+=_nextTransaction->getOperationLength(); //NEW!!!!!!!! + //std::cout << "lets crash execute\n"; + _nextTransaction->getCommand()->execute(); //NEW!!!! + //std::cout << "not crashed\n"; #ifdef TRANSLIST_ENABLED - _transactList.push_back(_nextTransaction); + _transactList.push_back(_nextTransaction); #endif - _lastTransaction=_nextTransaction; - _busyCycles+=_nextTransaction->getOverallLength(); + _lastTransaction=_nextTransaction; + _busyCycles+=_nextTransaction->getOverallLength(); #ifdef LISTENERS_ENABLED - NOTIFY_TRANS_EXECUTED(_nextTransaction); + NOTIFY_TRANS_EXECUTED(_nextTransaction); #endif - _nextTransaction=0; - //std::cout << "this is not the reason\n"; - return true; - }else return false; + _nextTransaction=0; + //std::cout << "this is not the reason\n"; + return true; + }else return false; } void SingleCoreCPU::schedule(){ - //std::cout <<"Hello\n"; - //std::cout << "CPU:schedule BEGIN " << _name << "+++++++++++++++++++++++++++++++++\n"; - TMLTime aTimeSlice = _scheduler->schedule(_endSchedule); - //_schedulingNeeded=false; 05/05/11 - //std::cout << "1\n"; - TMLTransaction* aOldTransaction = _nextTransaction; - _nextTransaction=_scheduler->getNextTransaction(_endSchedule); - //std::cout << "2\n"; - - //_scheduler->transWasScheduled(this); //NEW 05/05/11 - - //if (aOldTransaction!=0){ - if (aOldTransaction!=0 && aOldTransaction!=_nextTransaction){ //NEW - //std::cout << "3\n"; - //aOldTransaction->getCommand()->getTask()->resetScheduledFlag(); TO BE OMITTED???????????????????????????????? - //std::cout << "4\n"; - //if (aOldTransaction!=_nextTransaction && _masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); - if (_masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); - } - //std::cout << "5\n"; - if (_nextTransaction!=0 && aOldTransaction != _nextTransaction) calcStartTimeLength(aTimeSlice); - //std::cout << "CPU:schedule END " << _name << "+++++++++++++++++++++++++++++++++\n"; + //std::cout <<"Hello\n"; + //std::cout << "CPU:schedule BEGIN " << _name << "+++++++++++++++++++++++++++++++++\n"; + TMLTime aTimeSlice = _scheduler->schedule(_endSchedule); + //_schedulingNeeded=false; 05/05/11 + //std::cout << "1\n"; + TMLTransaction* aOldTransaction = _nextTransaction; + _nextTransaction=_scheduler->getNextTransaction(_endSchedule); + //std::cout << "2\n"; + + //_scheduler->transWasScheduled(this); //NEW 05/05/11 + + //if (aOldTransaction!=0){ + if (aOldTransaction!=0 && aOldTransaction!=_nextTransaction){ //NEW + //std::cout << "3\n"; + //aOldTransaction->getCommand()->getTask()->resetScheduledFlag(); TO BE OMITTED???????????????????????????????? + //std::cout << "4\n"; + //if (aOldTransaction!=_nextTransaction && _masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); + if (_masterNextTransaction!=0) _masterNextTransaction->registerTransaction(0); + } + //std::cout << "5\n"; + if (_nextTransaction!=0 && aOldTransaction != _nextTransaction) calcStartTimeLength(aTimeSlice); + //std::cout << "CPU:schedule END " << _name << "+++++++++++++++++++++++++++++++++\n"; } //std::string SingleCoreCPU::toString() const{ -// return _name; +// return _name; //} std::string SingleCoreCPU::toShortString() const{ - std::ostringstream outp; - outp << "cpu" << _ID; - return outp.str(); + std::ostringstream outp; + outp << "cpu" << _ID; + return outp.str(); } void SingleCoreCPU::schedule2HTML(std::ofstream& myfile) const{ - TMLTime aCurrTime=0; - TMLTransaction* aCurrTrans; - unsigned int aBlanks,aLength,aColor; - std::string aCommentString; - //if (_transactList.empty()) return; - //std::cout << "0. size: " << _transactList.size() << '\n'; - myfile << "<h2><span>Scheduling for device: "<< _name <<"</span></h2>\n<table>\n<tr>"; - for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ - aCurrTrans=*i; - //if (aCurrTrans->getVirtualLength()==0) continue; - aBlanks=aCurrTrans->getStartTime()-aCurrTime; - if (aBlanks>0){ - if (aBlanks==1) - myfile << "<td title=\"idle time\" class=\"not\"></td>\n"; - else - myfile << "<td colspan=\""<< aBlanks <<"\" title=\"idle time\" class=\"not\"></td>\n"; - } - aLength=aCurrTrans->getPenalties(); - if (aLength!=0){ - if (aLength==1){ - //myfile << "<td title=\""<< aCurrTrans->toShortString() << "\" class=\"t15\"></td>\n"; - //myfile << "<td title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << " bran:" << aCurrTrans->getBranchingPenalty() << "\" class=\"t15\"></td>\n"; - myfile << "<td title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << "\" class=\"t15\"></td>\n"; - }else{ - //myfile << "<td colspan=\"" << aLength << "\" title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << " bran:" << aCurrTrans->getBranchingPenalty() << "\" class=\"t15\"></td>\n"; - myfile << "<td colspan=\"" << aLength << "\" title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << "\" class=\"t15\"></td>\n"; - } - } - aLength=aCurrTrans->getOperationLength(); - aColor=aCurrTrans->getCommand()->getTask()->getInstanceNo() & 15; - if (aLength==1) - myfile << "<td title=\""<< aCurrTrans->toShortString() << "\" class=\"t"<< aColor <<"\"></td>\n"; - else - myfile << "<td colspan=\"" << aLength << "\" title=\"" << aCurrTrans->toShortString() << "\" class=\"t"<< aColor <<"\"></td>\n"; - - - aCurrTime=aCurrTrans->getEndTime(); - //std::cout << "end time: " << aCurrTrans->getEndTime() << std::endl; - } - //std::cout << "acurrTime: " << aCurrTime << std::endl; - myfile << "</tr>\n<tr>"; - for(aLength=0;aLength<aCurrTime;aLength++) myfile << "<th></th>"; - myfile << "</tr>\n<tr>"; - for(aLength=0;aLength<aCurrTime;aLength+=5) myfile << "<td colspan=\"5\" class=\"sc\">" << aLength << "</td>"; - myfile << "</tr>\n</table>\n<table>\n<tr>"; - for(TaskList::const_iterator j=_taskList.begin(); j != _taskList.end(); ++j){ - aColor=(*j)->getInstanceNo() & 15; - myfile << "<td class=\"t"<< aColor <<"\"></td><td>"<< (*j)->toString() << "</td><td class=\"space\"></td>\n"; - } - myfile << "</tr>"; + TMLTime aCurrTime=0; + TMLTransaction* aCurrTrans; + unsigned int aBlanks,aLength,aColor; + std::string aCommentString; + //if (_transactList.empty()) return; + //std::cout << "0. size: " << _transactList.size() << '\n'; + myfile << "<h2><span>Scheduling for device: "<< _name <<"</span></h2>\n<table>\n<tr>"; + for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ + aCurrTrans=*i; + //if (aCurrTrans->getVirtualLength()==0) continue; + aBlanks=aCurrTrans->getStartTime()-aCurrTime; + if (aBlanks>0){ + if (aBlanks==1) + myfile << "<td title=\"idle time\" class=\"not\"></td>\n"; + else + myfile << "<td colspan=\""<< aBlanks <<"\" title=\"idle time\" class=\"not\"></td>\n"; + } + aLength=aCurrTrans->getPenalties(); + if (aLength!=0){ + if (aLength==1){ + //myfile << "<td title=\""<< aCurrTrans->toShortString() << "\" class=\"t15\"></td>\n"; + //myfile << "<td title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << " bran:" << aCurrTrans->getBranchingPenalty() << "\" class=\"t15\"></td>\n"; + myfile << "<td title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << "\" class=\"t15\"></td>\n"; + }else{ + //myfile << "<td colspan=\"" << aLength << "\" title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << " bran:" << aCurrTrans->getBranchingPenalty() << "\" class=\"t15\"></td>\n"; + myfile << "<td colspan=\"" << aLength << "\" title=\" idle:" << aCurrTrans->getIdlePenalty() << " switch:" << aCurrTrans->getTaskSwitchingPenalty() << "\" class=\"t15\"></td>\n"; + } + } + aLength=aCurrTrans->getOperationLength(); + aColor=aCurrTrans->getCommand()->getTask()->getInstanceNo() & 15; + if (aLength==1) + myfile << "<td title=\""<< aCurrTrans->toShortString() << "\" class=\"t"<< aColor <<"\"></td>\n"; + else + myfile << "<td colspan=\"" << aLength << "\" title=\"" << aCurrTrans->toShortString() << "\" class=\"t"<< aColor <<"\"></td>\n"; + + + aCurrTime=aCurrTrans->getEndTime(); + //std::cout << "end time: " << aCurrTrans->getEndTime() << std::endl; + } + //std::cout << "acurrTime: " << aCurrTime << std::endl; + myfile << "</tr>\n<tr>"; + for(aLength=0;aLength<aCurrTime;aLength++) myfile << "<th></th>"; + myfile << "</tr>\n<tr>"; + for(aLength=0;aLength<aCurrTime;aLength+=5) myfile << "<td colspan=\"5\" class=\"sc\">" << aLength << "</td>"; + myfile << "</tr>\n</table>\n<table>\n<tr>"; + for(TaskList::const_iterator j=_taskList.begin(); j != _taskList.end(); ++j){ + aColor=(*j)->getInstanceNo() & 15; + myfile << "<td class=\"t"<< aColor <<"\"></td><td>"<< (*j)->toString() << "</td><td class=\"space\"></td>\n"; + } + myfile << "</tr>"; #ifdef ADD_COMMENTS - bool aMoreComments=true, aInit=true; - Comment* aComment; - while(aMoreComments){ - aMoreComments=false; - myfile << "<tr>"; - for(TaskList::const_iterator j=_taskList.begin(); j != _taskList.end(); ++j){ - aCommentString = (*j)->getNextComment(aInit, aComment); - if (aComment==0){ - myfile << "<td></td><td></td><td class=\"space\"></td>"; - }else{ - replaceAll(aCommentString,"<","<"); - replaceAll(aCommentString,">",">"); - aMoreComments=true; - myfile << "<td>" << aComment->_time << "</td><td><pre>" << aCommentString << "</pre></td><td class=\"space\"></td>"; - } - } - aInit=false; - myfile << "</tr>\n"; - } + bool aMoreComments=true, aInit=true; + Comment* aComment; + while(aMoreComments){ + aMoreComments=false; + myfile << "<tr>"; + for(TaskList::const_iterator j=_taskList.begin(); j != _taskList.end(); ++j){ + aCommentString = (*j)->getNextComment(aInit, aComment); + if (aComment==0){ + myfile << "<td></td><td></td><td class=\"space\"></td>"; + } else{ + replaceAll(aCommentString,"<","<"); + replaceAll(aCommentString,">",">"); + aMoreComments=true; + myfile << "<td>" << aComment->_time << "</td><td><pre>" << aCommentString << "</pre></td><td class=\"space\"></td>"; + } + } + aInit=false; + myfile << "</tr>\n"; + } #endif - myfile << "</table>\n"; + myfile << "</table>\n"; } void SingleCoreCPU::schedule2TXT(std::ofstream& myfile) const{ - myfile << "========= Scheduling for device: "<< _name << " =========\n" ; - for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ - myfile << (*i)->toShortString() << std::endl; - } + myfile << "========= Scheduling for device: "<< _name << " =========\n" ; + for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ + myfile << (*i)->toShortString() << std::endl; + } } -void allTrans2XML(std::ostringstream& glob) const { +void SingleCoreCPU::allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const { + int size = _transactList.size(); + int begining = size - maxNbOfTrans; + if (begining <0) { + begining = 0; + } + int cpt =0; for(TransactionList::const_iterator i=_transactList.begin(); i != _transactList.end(); ++i){ - (*i)->toXML(glob, 0, _name); + if (cpt >= begining) { + (*i)->toXML(glob, 1, _name); + } + cpt ++; } } //TMLTime SingleCoreCPU::getNextSignalChange(bool iInit, std::string& oSigChange, bool& oNoMoreTrans){ void SingleCoreCPU::getNextSignalChange(bool iInit, SignalChangeData* oSigData){ - //new (oSigData) SignalChangeData(RUNNING, aCurrTrans->getStartTimeOperation(), this); - //std::ostringstream outp; - //oNoMoreTrans=false; - if (iInit){ - _posTrasactListVCD=_transactList.begin(); - _previousTransEndTime=0; - _vcdOutputState=END_IDLE_CPU; - if (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTime()!=0){ - //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; - //oSigChange=outp.str(); - new (oSigData) SignalChangeData(END_IDLE_CPU, 0, this); - //return 0 - return; - } - } - if (_posTrasactListVCD == _transactList.end()){ - //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; - //oSigChange=outp.str(); - //oNoMoreTrans=true; - //return _previousTransEndTime; - new (oSigData) SignalChangeData(END_IDLE_CPU, _previousTransEndTime, this); - }else{ - TMLTransaction* aCurrTrans=*_posTrasactListVCD; - switch (_vcdOutputState){ - case END_TASK_CPU: - do{ - _previousTransEndTime=(*_posTrasactListVCD)->getEndTime(); - _posTrasactListVCD++; - }while (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTimeOperation()==_previousTransEndTime); - if (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTime()==_previousTransEndTime){ - //outp << VCD_PREFIX << vcdValConvert(END_PENALTY_CPU) << "cpu" << _ID; - _vcdOutputState=END_PENALTY_CPU; - new (oSigData) SignalChangeData(END_PENALTY_CPU, _previousTransEndTime, this); - }else{ - //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; - _vcdOutputState=END_IDLE_CPU; - //if (_posTrasactListVCD == _transactList.end()) oNoMoreTrans=true; - new (oSigData) SignalChangeData(END_IDLE_CPU, _previousTransEndTime, this); - } - //oSigChange=outp.str(); - //return _previousTransEndTime; - break; - case END_PENALTY_CPU: - //outp << VCD_PREFIX << vcdValConvert(END_TASK_CPU) << "cpu" << _ID; - //oSigChange=outp.str(); - _vcdOutputState=END_TASK_CPU; - //return aCurrTrans->getStartTimeOperation(); - new (oSigData) SignalChangeData(END_TASK_CPU, aCurrTrans->getStartTimeOperation(), this); - break; - case END_IDLE_CPU: - if (aCurrTrans->getPenalties()==0){ - //outp << VCD_PREFIX << vcdValConvert(END_TASK_CPU) << "cpu" << _ID; - _vcdOutputState=END_TASK_CPU; - new (oSigData) SignalChangeData(END_TASK_CPU, aCurrTrans->getStartTime(), this); - }else{ - //outp << VCD_PREFIX << vcdValConvert(END_PENALTY_CPU) << "cpu" << _ID; - _vcdOutputState=END_PENALTY_CPU; - new (oSigData) SignalChangeData(END_PENALTY_CPU, aCurrTrans->getStartTime(), this); - } - //oSigChange=outp.str(); - //return aCurrTrans->getStartTime(); - break; - } - } - //return 0; + //new (oSigData) SignalChangeData(RUNNING, aCurrTrans->getStartTimeOperation(), this); + //std::ostringstream outp; + //oNoMoreTrans=false; + if (iInit){ + _posTrasactListVCD=_transactList.begin(); + _previousTransEndTime=0; + _vcdOutputState=END_IDLE_CPU; + if (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTime()!=0){ + //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; + //oSigChange=outp.str(); + new (oSigData) SignalChangeData(END_IDLE_CPU, 0, this); + //return 0 + return; + } + } + if (_posTrasactListVCD == _transactList.end()){ + //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; + //oSigChange=outp.str(); + //oNoMoreTrans=true; + //return _previousTransEndTime; + new (oSigData) SignalChangeData(END_IDLE_CPU, _previousTransEndTime, this); + }else{ + TMLTransaction* aCurrTrans=*_posTrasactListVCD; + switch (_vcdOutputState){ + case END_TASK_CPU: + do{ + _previousTransEndTime=(*_posTrasactListVCD)->getEndTime(); + _posTrasactListVCD++; + }while (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTimeOperation()==_previousTransEndTime); + if (_posTrasactListVCD != _transactList.end() && (*_posTrasactListVCD)->getStartTime()==_previousTransEndTime){ + //outp << VCD_PREFIX << vcdValConvert(END_PENALTY_CPU) << "cpu" << _ID; + _vcdOutputState=END_PENALTY_CPU; + new (oSigData) SignalChangeData(END_PENALTY_CPU, _previousTransEndTime, this); + }else{ + //outp << VCD_PREFIX << vcdValConvert(END_IDLE_CPU) << "cpu" << _ID; + _vcdOutputState=END_IDLE_CPU; + //if (_posTrasactListVCD == _transactList.end()) oNoMoreTrans=true; + new (oSigData) SignalChangeData(END_IDLE_CPU, _previousTransEndTime, this); + } + //oSigChange=outp.str(); + //return _previousTransEndTime; + break; + case END_PENALTY_CPU: + //outp << VCD_PREFIX << vcdValConvert(END_TASK_CPU) << "cpu" << _ID; + //oSigChange=outp.str(); + _vcdOutputState=END_TASK_CPU; + //return aCurrTrans->getStartTimeOperation(); + new (oSigData) SignalChangeData(END_TASK_CPU, aCurrTrans->getStartTimeOperation(), this); + break; + case END_IDLE_CPU: + if (aCurrTrans->getPenalties()==0){ + //outp << VCD_PREFIX << vcdValConvert(END_TASK_CPU) << "cpu" << _ID; + _vcdOutputState=END_TASK_CPU; + new (oSigData) SignalChangeData(END_TASK_CPU, aCurrTrans->getStartTime(), this); + }else{ + //outp << VCD_PREFIX << vcdValConvert(END_PENALTY_CPU) << "cpu" << _ID; + _vcdOutputState=END_PENALTY_CPU; + new (oSigData) SignalChangeData(END_PENALTY_CPU, aCurrTrans->getStartTime(), this); + } + //oSigChange=outp.str(); + //return aCurrTrans->getStartTime(); + break; + } + } + //return 0; } void SingleCoreCPU::reset(){ - CPU::reset(); - _scheduler->reset(); - _transactList.clear(); - _nextTransaction=0; - _lastTransaction=0; - _masterNextTransaction=0; - _busyCycles=0; + CPU::reset(); + _scheduler->reset(); + _transactList.clear(); + _nextTransaction=0; + _lastTransaction=0; + _masterNextTransaction=0; + _busyCycles=0; } void SingleCoreCPU::streamBenchmarks(std::ostream& s) const{ - s << TAG_CPUo << " id=\"" << _ID << "\" name=\"" << _name << "\">" << std::endl; - if (_simulatedTime!=0) s << TAG_UTILo << (static_cast<float>(_busyCycles)/static_cast<float>(_simulatedTime)) << TAG_UTILc; - s << TAG_ENERGYo << ( (_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle) << TAG_ENERGYc; - std::cout<< "power consumption "<< ((_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle)<< std::endl; - for(BusMasterList::const_iterator i=_busMasterList.begin(); i != _busMasterList.end(); ++i) (*i)->streamBenchmarks(s); - - s << TAG_CPUc; + s << TAG_CPUo << " id=\"" << _ID << "\" name=\"" << _name << "\">" << std::endl; + if (_simulatedTime!=0) s << TAG_UTILo << (static_cast<float>(_busyCycles)/static_cast<float>(_simulatedTime)) << TAG_UTILc; + s << TAG_ENERGYo << ( (_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle) << TAG_ENERGYc; + std::cout<< "power consumption "<< ((_simulatedTime/_timePerCycle)*_static_consumPerCycle) + ((_busyCycles/_timePerCycle)*_dynamic_consumPerCycle)<< std::endl; + for(BusMasterList::const_iterator i=_busMasterList.begin(); i != _busMasterList.end(); ++i) (*i)->streamBenchmarks(s); + + s << TAG_CPUc; } BusMaster* SingleCoreCPU::getMasterForBus(BusMaster* iDummy){ - if (iDummy!=0){ - SchedulableCommDevice* aBus = iDummy->getBus(); - for(BusMasterList::iterator i=_busMasterList.begin(); i != _busMasterList.end(); ++i){ - if ((*i)->getBus()==aBus) return *i; - } - std::cout << "cry!!!!!!!!!!!!! no bus master found\n"; - exit(1); - } - return 0; + if (iDummy!=0){ + SchedulableCommDevice* aBus = iDummy->getBus(); + for(BusMasterList::iterator i=_busMasterList.begin(); i != _busMasterList.end(); ++i){ + if ((*i)->getBus()==aBus) return *i; + } + std::cout << "cry!!!!!!!!!!!!! no bus master found\n"; + exit(1); + } + return 0; } std::istream& SingleCoreCPU::readObject(std::istream &is){ - CPU::readObject(is); - _scheduler->readObject(is); + CPU::readObject(is); + _scheduler->readObject(is); #ifdef SAVE_BENCHMARK_VARS - READ_STREAM(is,_busyCycles); + READ_STREAM(is,_busyCycles); #ifdef DEBUG_SERIALIZE - std::cout << "Read: CPU " << _name << " busy cycles: " << _busyCycles << std::endl; + std::cout << "Read: CPU " << _name << " busy cycles: " << _busyCycles << std::endl; #endif #endif - return is; + return is; } std::ostream& SingleCoreCPU::writeObject(std::ostream &os){ - CPU::writeObject(os); - _scheduler->writeObject(os); + CPU::writeObject(os); + _scheduler->writeObject(os); #ifdef SAVE_BENCHMARK_VARS - WRITE_STREAM(os,_busyCycles); + WRITE_STREAM(os,_busyCycles); #ifdef DEBUG_SERIALIZE - std::cout << "Write: CPU " << _name << " busy cycles: " << _busyCycles << std::endl; + std::cout << "Write: CPU " << _name << " busy cycles: " << _busyCycles << std::endl; #endif #endif - return os; + return os; } diff --git a/simulators/c++2/src_simulator/arch/SingleCoreCPU.h b/simulators/c++2/src_simulator/arch/SingleCoreCPU.h index abdb37bae3..8c6ca19c18 100644 --- a/simulators/c++2/src_simulator/arch/SingleCoreCPU.h +++ b/simulators/c++2/src_simulator/arch/SingleCoreCPU.h @@ -111,6 +111,12 @@ public: \param myfile Reference to the ofstream object representing the output file */ void schedule2TXT(std::ofstream& myfile) const; + + /** + \param glob refers to the output stream + */ + void allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const; + virtual void streamBenchmarks(std::ostream& s) const; virtual void reset(); inline void streamStateXML(std::ostream& s) const {streamBenchmarks(s);} @@ -119,11 +125,6 @@ public: protected: ///Truncates the next transaction at time iTime - /** - \param glob refers to the output stream - */ - void allTrans2XML(std::ostringstream& glob) const; - /** \param iTime Indicates at what time the transaction should be truncated diff --git a/simulators/c++2/src_simulator/definitions.h b/simulators/c++2/src_simulator/definitions.h index dcecb3dcc4..d361a6b501 100644 --- a/simulators/c++2/src_simulator/definitions.h +++ b/simulators/c++2/src_simulator/definitions.h @@ -190,8 +190,8 @@ using std::max; #define TAG_EXTIMEc "</extime>" #define TAG_CONTDELo "<contdel" #define TAG_CONTDELc "</contdel>" -#define TAG_TRANSo "<trans>" -#define TAG_TRANSc "</trans>" +#define TAG_TRANSo "<transinfo " +#define TAG_TRANSc " />" #define TAG_BUSo "<bus" #define TAG_BUSc "</bus>" diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index f7338db591..c81df70d6d 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -1,42 +1,42 @@ /*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, -Ludovic Apvrille, Renaud Pacalet - * - * ludovic.apvrille AT telecom-paristech.fr - * - * This software is a computer program whose purpose is to allow the - * edition of TURTLE analysis, design and deployment diagrams, to - * allow the generation of RT-LOTOS or Java code from this diagram, - * and at last to allow the analysis of formal validation traces - * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP - * from INRIA Rhone-Alpes. - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ + Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ #include <Simulator.h> //#include <Server.h> //#include <ServerLocal.h> @@ -63,549 +63,549 @@ Simulator::Simulator(SimServSyncInfo* iSyncInfo):_syncInfo(iSyncInfo), _simComp( } Simulator::~Simulator(){ - //if (_currCmdListener!=0) delete _currCmdListener; - //if (_randChoiceBreak!=0) delete _randChoiceBreak; + //if (_currCmdListener!=0) delete _currCmdListener; + //if (_randChoiceBreak!=0) delete _randChoiceBreak; } TMLTransaction* Simulator::getTransLowestEndTime(SchedulableDevice*& oResultDevice) const{ - //int tmp=0; - TMLTransaction *aMarker=0, *aTempTrans; - TMLTime aLowestTime=-1; - SchedulableDevice* aTempDevice; - //static unsigned int aTransitionNo=0; + //int tmp=0; + TMLTransaction *aMarker=0, *aTempTrans; + TMLTime aLowestTime=-1; + SchedulableDevice* aTempDevice; + //static unsigned int aTransitionNo=0; #ifdef DEBUG_KERNEL - std::cout << "kernel:getTLET: before loop" << std::endl; + std::cout << "kernel:getTLET: before loop" << std::endl; #endif - //for(SchedulingList::const_iterator i=_simComp->_cpuList.begin(); i != _simComp->_cpuList.end(); ++i){ - //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - aTempDevice=*i; - aTempTrans=aTempDevice->getNextTransaction(); - if (aTempTrans!=0 && aTempTrans->getVirtualLength()>0){ + //for(SchedulingList::const_iterator i=_simComp->_cpuList.begin(); i != _simComp->_cpuList.end(); ++i){ + //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ + aTempDevice=*i; + aTempTrans=aTempDevice->getNextTransaction(); + if (aTempTrans!=0 && aTempTrans->getVirtualLength()>0){ #ifdef DEBUG_KERNEL - std::cout << "kernel:getTLET: transaction found on " << aTempDevice->toString() << ": " << aTempTrans->toString() << std::endl; + std::cout << "kernel:getTLET: transaction found on " << aTempDevice->toString() << ": " << aTempTrans->toString() << std::endl; #endif - //tmp++; - if (aTempTrans->getEndTime() < aLowestTime){ - aMarker=aTempTrans; - aLowestTime=aTempTrans->getEndTime(); - oResultDevice=aTempDevice; - } - } -//#ifdef DEBUG_KERNEL - else { - /*if (!_simComp->couldCPUBeIdle(*i)){ - std::cout << "kernel:getTLET: no transaction found on " << aTempDevice->toString() << std::endl; - std::cout << "Cry !!!!!!!!"; - //exit(1); - }*/ - } -//#endif - } - //if (tmp==1) std::cout << "trans only on one CPU " << oResultDevice->toString() << "\n"; - return aMarker; + //tmp++; + if (aTempTrans->getEndTime() < aLowestTime){ + aMarker=aTempTrans; + aLowestTime=aTempTrans->getEndTime(); + oResultDevice=aTempDevice; + } + } + //#ifdef DEBUG_KERNEL + else { + /*if (!_simComp->couldCPUBeIdle(*i)){ + std::cout << "kernel:getTLET: no transaction found on " << aTempDevice->toString() << std::endl; + std::cout << "Cry !!!!!!!!"; + //exit(1); + }*/ + } + //#endif + } + //if (tmp==1) std::cout << "trans only on one CPU " << oResultDevice->toString() << "\n"; + return aMarker; } ID Simulator::schedule2GraphDOT(std::ostream& iDOTFile, std::ostream& iAUTFile, ID iStartState, unsigned int& oTransCounter) const{ - CPUList::iterator i; - //std::cout << "entry graph output\n"; - GraphTransactionQueue aQueue; - TMLTransaction* aTrans, *aTopElement; - ID aStartState=iStartState, aEndState=0; - for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - aTrans = (*i)->getTransactions1By1(true); - if (aTrans!=0) aQueue.push(aTrans); - } - //std::ostringstream aOutp; - while (!aQueue.empty()){ - CPU* aCPU; - aTopElement = aQueue.top(); - aCPU = aTopElement->getCommand()->getTask()->getCPU(); - aEndState = aTopElement->getStateID(); - if (aEndState==0){ - aEndState=TMLTransaction::getID(); - TMLTransaction::incID(); - } - //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; - oTransCounter++; - iDOTFile << aStartState << " -> " << aEndState << " [label = \"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); - if (aTopElement->getChannel()!=0){ - iDOTFile << "__" << aTopElement->getChannel()->toShortString(); - } - iDOTFile << "<" << aTopElement->getVirtualLength() << ">)\"]\n"; - //(20,"i(CPU0__test1__TMLTask_1__wr__test1__ch<4 ,4>)", 24) - iAUTFile << "(" << aStartState << "," << "\"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); - if (aTopElement->getChannel()!=0){ - iAUTFile << "__" << aTopElement->getChannel()->toShortString(); - } - iAUTFile << "<" << aTopElement->getVirtualLength() << ">)\"," << aEndState <<")\n"; - aStartState = aEndState; - aQueue.pop(); - aTrans = aCPU->getTransactions1By1(false); - if (aTrans!=0) aQueue.push(aTrans); - } - //std::cout << "exit graph output\n"; - return aStartState; + CPUList::iterator i; + //std::cout << "entry graph output\n"; + GraphTransactionQueue aQueue; + TMLTransaction* aTrans, *aTopElement; + ID aStartState=iStartState, aEndState=0; + for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ + aTrans = (*i)->getTransactions1By1(true); + if (aTrans!=0) aQueue.push(aTrans); + } + //std::ostringstream aOutp; + while (!aQueue.empty()){ + CPU* aCPU; + aTopElement = aQueue.top(); + aCPU = aTopElement->getCommand()->getTask()->getCPU(); + aEndState = aTopElement->getStateID(); + if (aEndState==0){ + aEndState=TMLTransaction::getID(); + TMLTransaction::incID(); + } + //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; + oTransCounter++; + iDOTFile << aStartState << " -> " << aEndState << " [label = \"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); + if (aTopElement->getChannel()!=0){ + iDOTFile << "__" << aTopElement->getChannel()->toShortString(); + } + iDOTFile << "<" << aTopElement->getVirtualLength() << ">)\"]\n"; + //(20,"i(CPU0__test1__TMLTask_1__wr__test1__ch<4 ,4>)", 24) + iAUTFile << "(" << aStartState << "," << "\"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); + if (aTopElement->getChannel()!=0){ + iAUTFile << "__" << aTopElement->getChannel()->toShortString(); + } + iAUTFile << "<" << aTopElement->getVirtualLength() << ">)\"," << aEndState <<")\n"; + aStartState = aEndState; + aQueue.pop(); + aTrans = aCPU->getTransactions1By1(false); + if (aTrans!=0) aQueue.push(aTrans); + } + //std::cout << "exit graph output\n"; + return aStartState; } void Simulator::schedule2Graph(std::string& iTraceFileName) const{ - struct timeval aBegin,aEnd; - gettimeofday(&aBegin,NULL); - std::ofstream myfile (iTraceFileName.c_str()); - if (myfile.is_open()){ - CPUList::iterator i; - GraphTransactionQueue aQueue; - TMLTransaction* aTrans, *aTopElement; - unsigned int aTransitionNo=0; - //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - aTrans = (*i)->getTransactions1By1(true); - if (aTrans!=0) aQueue.push(aTrans); - } - std::ostringstream aOutp; - while (!aQueue.empty()){ - //std::ostringstream aTempStr; - CPU* aCPU; - aTopElement = aQueue.top(); - aCPU = aTopElement->getCommand()->getTask()->getCPU(); - for (TMLLength a=0; a < aTopElement->getVirtualLength(); a++){ - aOutp << "(" << aTransitionNo << ",\"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); - if (aTopElement->getChannel()!=0){ - aOutp << "__" << aTopElement->getChannel()->toShortString(); - //if (dynamic_cast<TMLEventChannel*>(aTopElement->getChannel())==0) aOutp << "<" << aTopElement->getVirtualLength() << ", " << ">"; - } - aOutp << ")\"," << ++aTransitionNo << ")\n"; - - //aOutp << aTempStr.str() << ++aTransitionNo << ")\n"; - } - //myfile << aTempStr.str(); - aQueue.pop(); - aTrans = aCPU->getTransactions1By1(false); - if (aTrans!=0) aQueue.push(aTrans); - } - myfile << "des (0, " << aTransitionNo+1 << ", " << aTransitionNo+2 << ")\n"; - myfile << aOutp.str() << "(" << aTransitionNo << ",\"i(exit)\", " << aTransitionNo+1 << ")\n"; - myfile.close(); - } - else - std::cout << "Unable to open Graph output file" << std::endl; - gettimeofday(&aEnd,NULL); - std::cout << "The Graph output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; + struct timeval aBegin,aEnd; + gettimeofday(&aBegin,NULL); + std::ofstream myfile (iTraceFileName.c_str()); + if (myfile.is_open()){ + CPUList::iterator i; + GraphTransactionQueue aQueue; + TMLTransaction* aTrans, *aTopElement; + unsigned int aTransitionNo=0; + //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ + aTrans = (*i)->getTransactions1By1(true); + if (aTrans!=0) aQueue.push(aTrans); + } + std::ostringstream aOutp; + while (!aQueue.empty()){ + //std::ostringstream aTempStr; + CPU* aCPU; + aTopElement = aQueue.top(); + aCPU = aTopElement->getCommand()->getTask()->getCPU(); + for (TMLLength a=0; a < aTopElement->getVirtualLength(); a++){ + aOutp << "(" << aTransitionNo << ",\"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); + if (aTopElement->getChannel()!=0){ + aOutp << "__" << aTopElement->getChannel()->toShortString(); + //if (dynamic_cast<TMLEventChannel*>(aTopElement->getChannel())==0) aOutp << "<" << aTopElement->getVirtualLength() << ", " << ">"; + } + aOutp << ")\"," << ++aTransitionNo << ")\n"; + + //aOutp << aTempStr.str() << ++aTransitionNo << ")\n"; + } + //myfile << aTempStr.str(); + aQueue.pop(); + aTrans = aCPU->getTransactions1By1(false); + if (aTrans!=0) aQueue.push(aTrans); + } + myfile << "des (0, " << aTransitionNo+1 << ", " << aTransitionNo+2 << ")\n"; + myfile << aOutp.str() << "(" << aTransitionNo << ",\"i(exit)\", " << aTransitionNo+1 << ")\n"; + myfile.close(); + } + else + std::cout << "Unable to open Graph output file" << std::endl; + gettimeofday(&aEnd,NULL); + std::cout << "The Graph output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; } void Simulator::schedule2TXT(std::string& iTraceFileName) const{ - struct timeval aBegin,aEnd; - gettimeofday(&aBegin,NULL); - std::ofstream myfile (iTraceFileName.c_str()); - if (myfile.is_open()){ - //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - (*i)->schedule2TXT(myfile); - } - //for(BusList::const_iterator j=_simComp->getBusIterator(false); j != _simComp->getBusIterator(true); ++j){ - for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ - (*j)->schedule2TXT(myfile); - } - myfile.close(); - } - else - std::cout << "Unable to open text output file." << std::endl; - gettimeofday(&aEnd,NULL); - std::cout << "The text output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; + struct timeval aBegin,aEnd; + gettimeofday(&aBegin,NULL); + std::ofstream myfile (iTraceFileName.c_str()); + if (myfile.is_open()){ + //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ + (*i)->schedule2TXT(myfile); + } + //for(BusList::const_iterator j=_simComp->getBusIterator(false); j != _simComp->getBusIterator(true); ++j){ + for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ + (*j)->schedule2TXT(myfile); + } + myfile.close(); + } + else + std::cout << "Unable to open text output file." << std::endl; + gettimeofday(&aEnd,NULL); + std::cout << "The text output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; } -void Simulator::allTrans2XML(std::ostringstream& glob) const{ - glob << TAG_TRANSo << "Transaction" << TAG_TRANSc << std::endl; +void Simulator::allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const{ + //glob << TAG_TRANSo << "Transaction" << TAG_TRANSc << std::endl; for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - (*i)->allTrans2XML(myfile); + (*i)->allTrans2XML(glob, maxNbOfTrans); } - + for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ - (*j)->allTrans2XML(myfile); + (*j)->allTrans2XML(glob, maxNbOfTrans); } } void Simulator::schedule2HTML(std::string& iTraceFileName) const{ - struct timeval aBegin,aEnd; - gettimeofday(&aBegin,NULL); - std::ofstream myfile (iTraceFileName.c_str()); - if (myfile.is_open()){ - myfile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; - myfile << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"schedstyle.css\" />\n<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />\n<title>Scheduling</title>\n</head>\n<body>\n"; - //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ - (*i)->schedule2HTML(myfile); - } - //for(BusList::const_iterator j=_simComp->getBusIterator(false); j != _simComp->getBusIterator(true); ++j){ - for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ - (*j)->schedule2HTML(myfile); - } - //for_each(iCPUlist.begin(), iCPUlist.end(),std::bind2nd(std::mem_fun(&CPU::schedule2HTML),myfile)); - myfile << "</body>\n</html>\n"; - myfile.close(); - } - else - std::cout << "Unable to open HTML output file." << std::endl; - gettimeofday(&aEnd,NULL); - std::cout << "The HTML output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; + struct timeval aBegin,aEnd; + gettimeofday(&aBegin,NULL); + std::ofstream myfile (iTraceFileName.c_str()); + if (myfile.is_open()){ + myfile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; + myfile << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"schedstyle.css\" />\n<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />\n<title>Scheduling</title>\n</head>\n<body>\n"; + //for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ + (*i)->schedule2HTML(myfile); + } + //for(BusList::const_iterator j=_simComp->getBusIterator(false); j != _simComp->getBusIterator(true); ++j){ + for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ + (*j)->schedule2HTML(myfile); + } + //for_each(iCPUlist.begin(), iCPUlist.end(),std::bind2nd(std::mem_fun(&CPU::schedule2HTML),myfile)); + myfile << "</body>\n</html>\n"; + myfile.close(); + } + else + std::cout << "Unable to open HTML output file." << std::endl; + gettimeofday(&aEnd,NULL); + std::cout << "The HTML output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; } void Simulator::schedule2VCD(std::string& iTraceFileName) const{ - time_t aRawtime; - struct tm * aTimeinfo; - struct timeval aBegin,aEnd; - gettimeofday(&aBegin,NULL); - time(&aRawtime); - aTimeinfo=localtime(&aRawtime); - std::ofstream myfile (iTraceFileName.c_str()); - if (myfile.is_open()){ - //std::cout << "File is open" << std::endl; - SignalChangeQueue aQueue; - std::string aSigString; - //bool aNoMoreTrans; - //TraceableDevice* actDevice; - TMLTime aCurrTime=-1; - SignalChangeData* aTopElement; - TMLTime aNextClockEvent=0; - myfile << "$date\n" << asctime(aTimeinfo) << "$end\n\n$version\nDaniel's TML simulator\n$end\n\n"; - myfile << "$timescale\n5 ns\n$end\n\n$scope module Simulation $end\n"; - //std::cout << "Before 1st loop" << std::endl; - //for (TraceableDeviceList::const_iterator i=_simComp->getVCDIterator(false); i!= _simComp->getVCDIterator(true); ++i){ - for (TraceableDeviceList::const_iterator i=_simComp->getVCDList().begin(); i!= _simComp->getVCDList().end(); ++i){ - //TraceableDevice* a=*i; -// a->streamBenchmarks(std::cout); -// a->toString(); - //std::cout << "in 1st loop " << a << std::endl; - //std::cout << "device: " << (*i)->toString() << std::endl; - //myfile << "$var integer 3 " << (*i)->toShortString() << " " << (*i)->toString() << " $end\n"; - myfile << "$var wire 1 " << (*i)->toShortString() << " " << (*i)->toString() << " $end\n"; - //std::cout << "get next signal change" << std::endl; - //aTime = (*i)->getNextSignalChange(true, aSigString, aNoMoreTrans); - aTopElement = new SignalChangeData(); - (*i)->getNextSignalChange(true, aTopElement); - aQueue.push(aTopElement); - //std::cout << "push" << std::endl; - //aQueue.push(new SignalChangeData(aSigString, aTime, (aNoMoreTrans)?0:(*i))); - } - myfile << "$var integer 32 clk Clock $end\n"; - myfile << "$upscope $end\n$enddefinitions $end\n\n"; - //std::cout << "Before 2nd loop" << std::endl; - while (!aQueue.empty()){ - aTopElement=aQueue.top(); - while (aNextClockEvent < aTopElement->_time){ - myfile << "#" << aNextClockEvent << "\nr" << aNextClockEvent << " clk\n"; - aNextClockEvent+=CLOCK_INC; - } - if (aCurrTime!=aTopElement->_time){ - aCurrTime=aTopElement->_time; - myfile << "#" << aCurrTime << "\n"; - } - if (aNextClockEvent == aTopElement->_time){ - myfile << "b" << vcdTimeConvert(aNextClockEvent) << " clk\n"; - aNextClockEvent+=CLOCK_INC; - } - //myfile << aTopElement->_sigChange << "\n"; - myfile << vcdValConvert(aTopElement->_sigChange) << aTopElement->_device->toShortString() << "\n"; - aQueue.pop(); - TMLTime aTime = aTopElement->_time; - aTopElement->_device->getNextSignalChange(false, aTopElement); - if (aTopElement->_time == aTime) - delete aTopElement; - else - aQueue.push(aTopElement); - //actDevice=aTopElement->_device; - //if (actDevice!=0) aTime = actDevice->getNextSignalChange(false, aSigString, aNoMoreTrans); - //delete aTopElement; - //aQueue.pop(); - //if (actDevice!=0) aQueue.push(new SignalChangeData(aSigString, aTime, (aNoMoreTrans)?0:actDevice)); - } - myfile << "#" << aCurrTime+1 << "\n"; - std::cout << "Simulated cycles: " << aCurrTime << std::endl; - //for (TraceableDeviceList::const_iterator i=_simComp->getVCDIterator(false); i!= _simComp->getVCDIterator(true); ++i){ - for (TraceableDeviceList::const_iterator i=_simComp->getVCDList().begin(); i!= _simComp->getVCDList().end(); ++i){ - //myfile << VCD_PREFIX << "100 " << (*i)->toShortString() << "\n"; - myfile << "0" << (*i)->toShortString() << "\n"; - //std::cout << "Utilization of component " << (*i)->toString() << ": " << ((float)(*i)->getBusyCycles()) / ((float)aCurrTime) << std::endl; - } + time_t aRawtime; + struct tm * aTimeinfo; + struct timeval aBegin,aEnd; + gettimeofday(&aBegin,NULL); + time(&aRawtime); + aTimeinfo=localtime(&aRawtime); + std::ofstream myfile (iTraceFileName.c_str()); + if (myfile.is_open()){ + //std::cout << "File is open" << std::endl; + SignalChangeQueue aQueue; + std::string aSigString; + //bool aNoMoreTrans; + //TraceableDevice* actDevice; + TMLTime aCurrTime=-1; + SignalChangeData* aTopElement; + TMLTime aNextClockEvent=0; + myfile << "$date\n" << asctime(aTimeinfo) << "$end\n\n$version\nDaniel's TML simulator\n$end\n\n"; + myfile << "$timescale\n5 ns\n$end\n\n$scope module Simulation $end\n"; + //std::cout << "Before 1st loop" << std::endl; + //for (TraceableDeviceList::const_iterator i=_simComp->getVCDIterator(false); i!= _simComp->getVCDIterator(true); ++i){ + for (TraceableDeviceList::const_iterator i=_simComp->getVCDList().begin(); i!= _simComp->getVCDList().end(); ++i){ + //TraceableDevice* a=*i; + // a->streamBenchmarks(std::cout); + // a->toString(); + //std::cout << "in 1st loop " << a << std::endl; + //std::cout << "device: " << (*i)->toString() << std::endl; + //myfile << "$var integer 3 " << (*i)->toShortString() << " " << (*i)->toString() << " $end\n"; + myfile << "$var wire 1 " << (*i)->toShortString() << " " << (*i)->toString() << " $end\n"; + //std::cout << "get next signal change" << std::endl; + //aTime = (*i)->getNextSignalChange(true, aSigString, aNoMoreTrans); + aTopElement = new SignalChangeData(); + (*i)->getNextSignalChange(true, aTopElement); + aQueue.push(aTopElement); + //std::cout << "push" << std::endl; + //aQueue.push(new SignalChangeData(aSigString, aTime, (aNoMoreTrans)?0:(*i))); + } + myfile << "$var integer 32 clk Clock $end\n"; + myfile << "$upscope $end\n$enddefinitions $end\n\n"; + //std::cout << "Before 2nd loop" << std::endl; + while (!aQueue.empty()){ + aTopElement=aQueue.top(); + while (aNextClockEvent < aTopElement->_time){ + myfile << "#" << aNextClockEvent << "\nr" << aNextClockEvent << " clk\n"; + aNextClockEvent+=CLOCK_INC; + } + if (aCurrTime!=aTopElement->_time){ + aCurrTime=aTopElement->_time; + myfile << "#" << aCurrTime << "\n"; + } + if (aNextClockEvent == aTopElement->_time){ + myfile << "b" << vcdTimeConvert(aNextClockEvent) << " clk\n"; + aNextClockEvent+=CLOCK_INC; + } + //myfile << aTopElement->_sigChange << "\n"; + myfile << vcdValConvert(aTopElement->_sigChange) << aTopElement->_device->toShortString() << "\n"; + aQueue.pop(); + TMLTime aTime = aTopElement->_time; + aTopElement->_device->getNextSignalChange(false, aTopElement); + if (aTopElement->_time == aTime) + delete aTopElement; + else + aQueue.push(aTopElement); + //actDevice=aTopElement->_device; + //if (actDevice!=0) aTime = actDevice->getNextSignalChange(false, aSigString, aNoMoreTrans); + //delete aTopElement; + //aQueue.pop(); + //if (actDevice!=0) aQueue.push(new SignalChangeData(aSigString, aTime, (aNoMoreTrans)?0:actDevice)); + } + myfile << "#" << aCurrTime+1 << "\n"; + std::cout << "Simulated cycles: " << aCurrTime << std::endl; + //for (TraceableDeviceList::const_iterator i=_simComp->getVCDIterator(false); i!= _simComp->getVCDIterator(true); ++i){ + for (TraceableDeviceList::const_iterator i=_simComp->getVCDList().begin(); i!= _simComp->getVCDList().end(); ++i){ + //myfile << VCD_PREFIX << "100 " << (*i)->toShortString() << "\n"; + myfile << "0" << (*i)->toShortString() << "\n"; + //std::cout << "Utilization of component " << (*i)->toString() << ": " << ((float)(*i)->getBusyCycles()) / ((float)aCurrTime) << std::endl; + } - myfile.close(); - } - else - std::cout << "Unable to open VCD output file." << std::endl; - gettimeofday(&aEnd,NULL); - std::cout << "The VCD output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; + myfile.close(); + } + else + std::cout << "Unable to open VCD output file." << std::endl; + gettimeofday(&aEnd,NULL); + std::cout << "The VCD output took " << getTimeDiff(aBegin,aEnd) << "usec. File: " << iTraceFileName << std::endl; } bool Simulator::channelImpactsCommand(TMLChannel* iCh, TMLCommand* iCmd){ - unsigned int nbOfChannels = iCmd->getNbOfChannels(); - for (unsigned int i=0; i<nbOfChannels; i++) - if (iCh==iCmd->getChannel(i)) return true; - return false; + unsigned int nbOfChannels = iCmd->getNbOfChannels(); + for (unsigned int i=0; i<nbOfChannels; i++) + if (iCh==iCmd->getChannel(i)) return true; + return false; } bool Simulator::simulate(TMLTransaction*& oLastTrans){ - TMLTransaction* depTransaction,*depCPUnextTrans,*transLET; - TMLCommand* commandLET,*depCommand,*depCPUnextCommand; - TMLTask* depTask; - SchedulableDevice* cpuLET; - CPU* depCPU; + TMLTransaction* depTransaction,*depCPUnextTrans,*transLET; + TMLCommand* commandLET,*depCommand,*depCPUnextCommand; + TMLTask* depTask; + SchedulableDevice* cpuLET; + CPU* depCPU; #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: first schedule" << std::endl; + std::cout << "kernel:simulate: first schedule" << std::endl; #endif - _simComp->setStopFlag(false,""); - //std::cout << "before loop " << std::endl; - //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i!=_simComp->getTaskIterator(true);i++){ - for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i!=_simComp->getTaskList().end();i++){ - //std::cout << "loop it " << (*i)->toString() << std::endl; - if ((*i)->getCurrCommand()!=0) (*i)->getCurrCommand()->prepare(true); - //std::cout << "loop it end" << (*i)->toString() << std::endl; - } - //std::cout << "after loop1" << std::endl; + _simComp->setStopFlag(false,""); + //std::cout << "before loop " << std::endl; + //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i!=_simComp->getTaskIterator(true);i++){ + for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i!=_simComp->getTaskList().end();i++){ + //std::cout << "loop it " << (*i)->toString() << std::endl; + if ((*i)->getCurrCommand()!=0) (*i)->getCurrCommand()->prepare(true); + //std::cout << "loop it end" << (*i)->toString() << std::endl; + } + //std::cout << "after loop1" << std::endl; #ifdef EBRDD_ENABLED - for(EBRDDList::const_iterator i=_simComp->getEBRDDIterator(false); i!=_simComp->getEBRDDIterator(true);i++){ - if ((*i)->getCurrCommand()!=0) (*i)->getCurrCommand()->prepare(); - } + for(EBRDDList::const_iterator i=_simComp->getEBRDDIterator(false); i!=_simComp->getEBRDDIterator(true);i++){ + if ((*i)->getCurrCommand()!=0) (*i)->getCurrCommand()->prepare(); + } #endif - //std::cout << "after loop2" << std::endl; - //for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::setRescheduleFlag)); - //for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::schedule)); - for_each(_simComp->getCPUList().begin(), _simComp->getCPUList().end(),std::mem_fun(&CPU::schedule)); - //std::cout << "after schedule" << std::endl; - transLET=getTransLowestEndTime(cpuLET); - //std::cout << "after getTLET" << std::endl; + //std::cout << "after loop2" << std::endl; + //for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::setRescheduleFlag)); + //for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::schedule)); + for_each(_simComp->getCPUList().begin(), _simComp->getCPUList().end(),std::mem_fun(&CPU::schedule)); + //std::cout << "after schedule" << std::endl; + transLET=getTransLowestEndTime(cpuLET); + //std::cout << "after getTLET" << std::endl; #ifdef LISTENERS_ENABLED - if (_wasReset) NOTIFY_SIM_STARTED(); - _wasReset=false; + if (_wasReset) NOTIFY_SIM_STARTED(); + _wasReset=false; #endif - while (transLET!=0 && !_simComp->getStopFlag()){ + while (transLET!=0 && !_simComp->getStopFlag()){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: scheduling decision: " << transLET->toString() << std::endl; + std::cout << "kernel:simulate: scheduling decision: " << transLET->toString() << std::endl; #endif - commandLET=transLET->getCommand(); + commandLET=transLET->getCommand(); #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: add trans " << commandLET->toString() << std::endl; + std::cout << "kernel:simulate: add trans " << commandLET->toString() << std::endl; #endif - if (cpuLET->addTransaction(0)){ - unsigned int nbOfChannels = commandLET->getNbOfChannels(); - //bool aRescheduleCoresFlag=false; - for (unsigned int i=0;i<nbOfChannels; i++){ - if ((depTask=commandLET->getDependentTask(i))==0) continue; - //if (depTask!=0){ + if (cpuLET->addTransaction(0)){ + unsigned int nbOfChannels = commandLET->getNbOfChannels(); + //bool aRescheduleCoresFlag=false; + for (unsigned int i=0;i<nbOfChannels; i++){ + if ((depTask=commandLET->getDependentTask(i))==0) continue; + //if (depTask!=0){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: dependent Task found" << std::endl; + std::cout << "kernel:simulate: dependent Task found" << std::endl; #endif - depCPU=depTask->getCPU(); - //std::cout << "CPU this task : " << cpuLET->toString(); - //if (depCPU==0) std::cout << " CPU dep task " << depTask->toString() << ": 0\n"; else std::cout << " CPU dep task: "<< depTask->toString() << " " << depCPU->toString() << std::endl; - if (depCPU!=cpuLET){ + depCPU=depTask->getCPU(); + //std::cout << "CPU this task : " << cpuLET->toString(); + //if (depCPU==0) std::cout << " CPU dep task " << depTask->toString() << ": 0\n"; else std::cout << " CPU dep task: "<< depTask->toString() << " " << depCPU->toString() << std::endl; + if (depCPU!=cpuLET){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: Tasks running on different CPUs" << std::endl; + std::cout << "kernel:simulate: Tasks running on different CPUs" << std::endl; #endif - depCommand=depTask->getCurrCommand(); - //if (depCommand!=0 && (dynamic_cast<TMLSelectCommand*>(depCommand)!=0 || channelImpactsCommand(commandLET->getChannel(i), depCommand))){ - if (depCommand!=0 && channelImpactsCommand(commandLET->getChannel(i), depCommand)) { //RIGHT one + depCommand=depTask->getCurrCommand(); + //if (depCommand!=0 && (dynamic_cast<TMLSelectCommand*>(depCommand)!=0 || channelImpactsCommand(commandLET->getChannel(i), depCommand))){ + if (depCommand!=0 && channelImpactsCommand(commandLET->getChannel(i), depCommand)) { //RIGHT one #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: commands are accessing the same channel" << std::endl; + std::cout << "kernel:simulate: commands are accessing the same channel" << std::endl; #endif - depTransaction=depCommand->getCurrTransaction(); - if (depTransaction!=0 && depTransaction->getVirtualLength()!=0){ + depTransaction=depCommand->getCurrTransaction(); + if (depTransaction!=0 && depTransaction->getVirtualLength()!=0){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: dependent task has a current transaction and is not blocked any more" << std::endl; + std::cout << "kernel:simulate: dependent task has a current transaction and is not blocked any more" << std::endl; #endif - /* if (depCPU==0){ - aRescheduleCoresFlag=true; -//#ifdef DEBUG_KERNEL - std::cout << "Multi Core scheduling procedure\n"; -//#endif - depTask->setRescheduleFlagForCores(); - continue; - }*/ - //std::cout << "Let's crash!!!!!!!!\n"; - depCPUnextTrans=depCPU->getNextTransaction(); - //std::cout << "Not crahed!!!!!!!!\n"; - if (depCPUnextTrans!=0){ + /* if (depCPU==0){ + aRescheduleCoresFlag=true; + //#ifdef DEBUG_KERNEL + std::cout << "Multi Core scheduling procedure\n"; + //#endif + depTask->setRescheduleFlagForCores(); + continue; + }*/ + //std::cout << "Let's crash!!!!!!!!\n"; + depCPUnextTrans=depCPU->getNextTransaction(); + //std::cout << "Not crahed!!!!!!!!\n"; + if (depCPUnextTrans!=0){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: transaction scheduled on dependent CPU" << std::endl; + std::cout << "kernel:simulate: transaction scheduled on dependent CPU" << std::endl; #endif - depCPUnextCommand=depCPUnextTrans->getCommand(); - if (depCPUnextCommand->getTask()!=depTask){ + depCPUnextCommand=depCPUnextTrans->getCommand(); + if (depCPUnextCommand->getTask()!=depTask){ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: dependent task not yet scheduled on dependent CPU" << std::endl; + std::cout << "kernel:simulate: dependent task not yet scheduled on dependent CPU" << std::endl; #endif - depCPU->truncateAndAddNextTransAt(transLET->getEndTime()); + depCPU->truncateAndAddNextTransAt(transLET->getEndTime()); #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: dependent transaction truncated" << std::endl; + std::cout << "kernel:simulate: dependent transaction truncated" << std::endl; #endif - } - }else{ + } + }else{ #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: schedule dependent CPU " << depCPU->toString() << std::endl; + std::cout << "kernel:simulate: schedule dependent CPU " << depCPU->toString() << std::endl; #endif - depCPU->schedule(); - } - } - } - } - } + depCPU->schedule(); + } + } + } + } + } #ifdef DEBUG_KERNEL - std::cout << "kernel:simulate: invoke schedule on executing CPU" << std::endl; + std::cout << "kernel:simulate: invoke schedule on executing CPU" << std::endl; #endif - /*if (aRescheduleCoresFlag){ - for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - if (*i!=cpuLET) (*i)->truncateIfNecessary(transLET->getEndTime()); - } - for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - if (*i!=cpuLET) (*i)->rescheduleIfNecessary(); - } - }*/ - cpuLET->schedule(); + /*if (aRescheduleCoresFlag){ + for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + if (*i!=cpuLET) (*i)->truncateIfNecessary(transLET->getEndTime()); + } + for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + if (*i!=cpuLET) (*i)->rescheduleIfNecessary(); + } + }*/ + cpuLET->schedule(); #ifdef LISTENERS_ENABLED - NOTIFY_TIME_ADVANCES(transLET->getEndTime()); + NOTIFY_TIME_ADVANCES(transLET->getEndTime()); #endif - } - oLastTrans=transLET; - //std::cout << "kernel:simulate: getTransLowestEndTime" << std::endl; - transLET=getTransLowestEndTime(cpuLET); - //_syncInfo->_server->sendReply("Sleep once again\n"); - //sleep(1); - } + } + oLastTrans=transLET; + //std::cout << "kernel:simulate: getTransLowestEndTime" << std::endl; + transLET=getTransLowestEndTime(cpuLET); + //_syncInfo->_server->sendReply("Sleep once again\n"); + //sleep(1); + } - bool aSimCompleted = (transLET==0 && !_simComp->getStoppedOnAction()); + bool aSimCompleted = (transLET==0 && !_simComp->getStoppedOnAction()); - if (aSimCompleted){ + if (aSimCompleted){ #ifdef LISTENERS_ENABLED - NOTIFY_SIM_STOPPED(); - NOTIFY_EVALUATE(); + NOTIFY_SIM_STOPPED(); + NOTIFY_EVALUATE(); #endif - _longRunTime = max(_longRunTime, SchedulableDevice::getSimulatedTime()); - _shortRunTime = min(_shortRunTime, SchedulableDevice::getSimulatedTime()); - //_simComp->showTaskStates(); - } - return (aSimCompleted); + _longRunTime = max(_longRunTime, SchedulableDevice::getSimulatedTime()); + _shortRunTime = min(_shortRunTime, SchedulableDevice::getSimulatedTime()); + //_simComp->showTaskStates(); + } + return (aSimCompleted); } const std::string Simulator::getArgs(const std::string& iComp, const std::string& iDefault, int iLen, char** iArgs){ - int aPosition=0; - while (aPosition < iLen){ - if (iComp.compare(iArgs[aPosition])==0){ - if (aPosition+1 < iLen && iArgs[aPosition+1][0]!='-'){ - return std::string(iArgs[aPosition+1]); - }else - return iDefault; - } - aPosition++; - } - return std::string(""); + int aPosition=0; + while (aPosition < iLen){ + if (iComp.compare(iArgs[aPosition])==0){ + if (aPosition+1 < iLen && iArgs[aPosition+1][0]!='-'){ + return std::string(iArgs[aPosition+1]); + }else + return iDefault; + } + aPosition++; + } + return std::string(""); } void Simulator::printHelp(){ - std::cout << "\n************************** Command line arguments *************************\n" - "-gpath specify path for graph output\n" - "-server launch simulator in server mode\n" - "-file read simulation commands from file\n" - "-help display this help text\n" - "-ohtml ofile simulate and write traces to ofile in html format\n" - "-otxt ofile simulate and write traces to ofile in text format\n" - "-ovcd ofile simulate and write traces to ofile in vcd format\n" - "-ograph ofile simulate and write traces to ofile in aut format\n" - "-explo generate the reachability graph \n" - "-cmd \'c1 p1 p2;c2\' execute commands c1 with parameters p1 and p2 and c2\n" - "-oxml ofile xml reply is written to ofile, in case the -cmd option is used\n" - "***************************************************************************\n\n"; + std::cout << "\n************************** Command line arguments *************************\n" + "-gpath specify path for graph output\n" + "-server launch simulator in server mode\n" + "-file read simulation commands from file\n" + "-help display this help text\n" + "-ohtml ofile simulate and write traces to ofile in html format\n" + "-otxt ofile simulate and write traces to ofile in text format\n" + "-ovcd ofile simulate and write traces to ofile in vcd format\n" + "-ograph ofile simulate and write traces to ofile in aut format\n" + "-explo generate the reachability graph \n" + "-cmd \'c1 p1 p2;c2\' execute commands c1 with parameters p1 and p2 and c2\n" + "-oxml ofile xml reply is written to ofile, in case the -cmd option is used\n" + "***************************************************************************\n\n"; } void Simulator::run(){ - std::string* aNewCmd; - std::cout << "Running in server mode.\n"; - while (!_syncInfo->_terminate){ - //pthread_mutex_lock (&_syncInfo->_mutexConsume); - //std::cout << "Simulator Waiting for cmd\n"; - aNewCmd=_syncInfo->popCommand(); - //decodeCommand(_syncInfo->_command); - //std::cout << "Let's crash.\n"; - decodeCommand(*aNewCmd); - //std::cout << "Returned from decode.\n"; - //std::cout << "Before delete.\n"; - delete aNewCmd; - //pthread_mutex_unlock (&_syncInfo->_mutexProduce); - } - std::cout << "Simulator loop terminated." << std::endl; + std::string* aNewCmd; + std::cout << "Running in server mode.\n"; + while (!_syncInfo->_terminate){ + //pthread_mutex_lock (&_syncInfo->_mutexConsume); + //std::cout << "Simulator Waiting for cmd\n"; + aNewCmd=_syncInfo->popCommand(); + //decodeCommand(_syncInfo->_command); + //std::cout << "Let's crash.\n"; + decodeCommand(*aNewCmd); + //std::cout << "Returned from decode.\n"; + //std::cout << "Before delete.\n"; + delete aNewCmd; + //pthread_mutex_unlock (&_syncInfo->_mutexProduce); + } + std::cout << "Simulator loop terminated." << std::endl; } ServerIF* Simulator::run(int iLen, char ** iArgs){ - std::string aArgString; - std::cout << "Starting up...\n"; - _graphOutPath = getArgs("-gpath", "", iLen, iArgs); - if (_graphOutPath.length()>0 && _graphOutPath[_graphOutPath.length()-1]!='/') - _graphOutPath+="/"; - aArgString =getArgs("-server", "server", iLen, iArgs); - if (!aArgString.empty()) return new Server(); - aArgString =getArgs("-file", "file", iLen, iArgs); - if (!aArgString.empty()) return new ServerLocal(aArgString); - aArgString =getArgs("-explo", "file", iLen, iArgs); - std::cout << "Just analyzed explo 1->" + aArgString + "<-\n"; - if (!aArgString.empty()) decodeCommand("1 7 100 100"); - std::cout << "Just analyzed explo 2\n"; - //if (!aArgString.empty()) return new ServerExplore(); - std::cout << "Running in command line mode.\n"; - _replyToServer = false; - aArgString =getArgs("-help", "help", iLen, iArgs); - if (aArgString.empty()){ - //aArgString =getArgs("-explo", "explo", iLen, iArgs); - aArgString =getArgs("-cmd", "1 0", iLen, iArgs); - if (aArgString.empty()){ - TMLTransaction* oLastTrans; - simulate(oLastTrans); - aArgString=getArgs("-ohtml", "scheduling.html", iLen, iArgs); - if (!aArgString.empty()) schedule2HTML(aArgString); - aArgString=getArgs("-otxt", "scheduling.txt", iLen, iArgs); - if (!aArgString.empty()) schedule2TXT(aArgString); - aArgString=getArgs("-ovcd", "scheduling.vcd", iLen, iArgs); - if (!aArgString.empty()) schedule2VCD(aArgString); - aArgString=getArgs("-ograph", "scheduling.aut", iLen, iArgs); - if (!aArgString.empty()) schedule2Graph(aArgString); - _simComp->streamBenchmarks(std::cout); - std::cout << "Simulated time: " << SchedulableDevice::getSimulatedTime() << " time units.\n"; - }else{ - std::ofstream aXmlOutFile; - std::string aXmlFileName = getArgs("-oxml", "reply.xml", iLen, iArgs); - if (aXmlFileName.empty()) aXmlOutFile.open("/dev/null"); else aXmlOutFile.open(aXmlFileName.c_str()); - if (aXmlOutFile.is_open()){ - std::string aNextCmd; - std::istringstream iss(aArgString+";"); - getline(iss, aNextCmd, ';'); - while (!(iss.eof() || aNextCmd.empty())){ - std::cout << "next cmd to execute: \"" << aNextCmd << "\"\n"; - decodeCommand(aNextCmd, aXmlOutFile); - getline(iss, aNextCmd, ';'); - } - aXmlOutFile.close(); - }else - std::cout << "XML output file could not be opened, aborting.\n"; - } - rusage res; - getrusage(RUSAGE_SELF, &res); - //std::cerr << res.ru_utime.tv_sec << "," << res.ru_utime.tv_usec << "," << res.ru_stime.tv_sec << "," << res.ru_stime.tv_usec << "\n"; - double aRunTime = ((double)((res.ru_utime.tv_sec + res.ru_stime.tv_sec) *1000000 + res.ru_utime.tv_usec + res.ru_stime.tv_usec))/1000000; - std::cerr << "trans/sec: " << ((double)SchedulableDevice::getOverallTransNo())/aRunTime << "\n"; - std::cerr << "cycles/trans: " << ((double)SchedulableDevice::getOverallTransSize())/((double)SchedulableDevice::getOverallTransNo()) << "\n"; - std::cerr << "Trans size: " << SchedulableDevice::getOverallTransSize() << " trans no: " << SchedulableDevice::getOverallTransNo() << "\n"; - std::cerr << "Statement coverage of application: " << TMLCommand::getCmdCoverage() << "%\n"; - std::cerr << "Branch coverage of application: " << TMLCommand::getBranchCoverage() << "%\n"; - }else{ - printHelp(); - } - //clock_t tick =sysconf(_SC_CLK_TCK); - //tms test; - //times(&test); - //std::cout << "user time: " << test.tms_utime << " system time: " << test.tms_stime + test.tms_cstime << " tick: " << tick << "\n"; - return 0; + std::string aArgString; + std::cout << "Starting up...\n"; + _graphOutPath = getArgs("-gpath", "", iLen, iArgs); + if (_graphOutPath.length()>0 && _graphOutPath[_graphOutPath.length()-1]!='/') + _graphOutPath+="/"; + aArgString =getArgs("-server", "server", iLen, iArgs); + if (!aArgString.empty()) return new Server(); + aArgString =getArgs("-file", "file", iLen, iArgs); + if (!aArgString.empty()) return new ServerLocal(aArgString); + aArgString =getArgs("-explo", "file", iLen, iArgs); + std::cout << "Just analyzed explo 1->" + aArgString + "<-\n"; + if (!aArgString.empty()) decodeCommand("1 7 100 100"); + std::cout << "Just analyzed explo 2\n"; + //if (!aArgString.empty()) return new ServerExplore(); + std::cout << "Running in command line mode.\n"; + _replyToServer = false; + aArgString =getArgs("-help", "help", iLen, iArgs); + if (aArgString.empty()){ + //aArgString =getArgs("-explo", "explo", iLen, iArgs); + aArgString =getArgs("-cmd", "1 0", iLen, iArgs); + if (aArgString.empty()){ + TMLTransaction* oLastTrans; + simulate(oLastTrans); + aArgString=getArgs("-ohtml", "scheduling.html", iLen, iArgs); + if (!aArgString.empty()) schedule2HTML(aArgString); + aArgString=getArgs("-otxt", "scheduling.txt", iLen, iArgs); + if (!aArgString.empty()) schedule2TXT(aArgString); + aArgString=getArgs("-ovcd", "scheduling.vcd", iLen, iArgs); + if (!aArgString.empty()) schedule2VCD(aArgString); + aArgString=getArgs("-ograph", "scheduling.aut", iLen, iArgs); + if (!aArgString.empty()) schedule2Graph(aArgString); + _simComp->streamBenchmarks(std::cout); + std::cout << "Simulated time: " << SchedulableDevice::getSimulatedTime() << " time units.\n"; + }else{ + std::ofstream aXmlOutFile; + std::string aXmlFileName = getArgs("-oxml", "reply.xml", iLen, iArgs); + if (aXmlFileName.empty()) aXmlOutFile.open("/dev/null"); else aXmlOutFile.open(aXmlFileName.c_str()); + if (aXmlOutFile.is_open()){ + std::string aNextCmd; + std::istringstream iss(aArgString+";"); + getline(iss, aNextCmd, ';'); + while (!(iss.eof() || aNextCmd.empty())){ + std::cout << "next cmd to execute: \"" << aNextCmd << "\"\n"; + decodeCommand(aNextCmd, aXmlOutFile); + getline(iss, aNextCmd, ';'); + } + aXmlOutFile.close(); + }else + std::cout << "XML output file could not be opened, aborting.\n"; + } + rusage res; + getrusage(RUSAGE_SELF, &res); + //std::cerr << res.ru_utime.tv_sec << "," << res.ru_utime.tv_usec << "," << res.ru_stime.tv_sec << "," << res.ru_stime.tv_usec << "\n"; + double aRunTime = ((double)((res.ru_utime.tv_sec + res.ru_stime.tv_sec) *1000000 + res.ru_utime.tv_usec + res.ru_stime.tv_usec))/1000000; + std::cerr << "trans/sec: " << ((double)SchedulableDevice::getOverallTransNo())/aRunTime << "\n"; + std::cerr << "cycles/trans: " << ((double)SchedulableDevice::getOverallTransSize())/((double)SchedulableDevice::getOverallTransNo()) << "\n"; + std::cerr << "Trans size: " << SchedulableDevice::getOverallTransSize() << " trans no: " << SchedulableDevice::getOverallTransNo() << "\n"; + std::cerr << "Statement coverage of application: " << TMLCommand::getCmdCoverage() << "%\n"; + std::cerr << "Branch coverage of application: " << TMLCommand::getBranchCoverage() << "%\n"; + }else{ + printHelp(); + } + //clock_t tick =sysconf(_SC_CLK_TCK); + //tms test; + //times(&test); + //std::cout << "user time: " << test.tms_utime << " system time: " << test.tms_stime + test.tms_cstime << " tick: " << tick << "\n"; + return 0; } void Simulator::decodeCommand(std::string iCmd, std::ostream& iXmlOutStream){ @@ -627,920 +627,925 @@ void Simulator::decodeCommand(std::string iCmd, std::ostream& iXmlOutStream){ //std::cout << "Not crashed. I: " << iCmd << std::endl; //std::cout << "Decoding command: d" << iCmd << " " << aCmd<<std::endl; switch (aCmd){ - case 0: //Quit simulation - std::cout << "QUIT SIMULATION from Decode Command" << std::endl; - break; - case 1:{ - struct timeval aBegin,aEnd; - gettimeofday(&aBegin,NULL); - _busy=true; - //std::cout << "Not crashed. I: " << iCmd << std::endl; - anAckMsg << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << /*TAG_REPLYo << anIssuedCmd << TAG_REPLYc << std::endl<< */ TAG_MSGo << "Command received" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl << TAG_STATUSo << SIM_BUSY << TAG_STATUSc << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - if (_replyToServer) { - if (_syncInfo != NULL) - if (_syncInfo->_server != NULL) - _syncInfo->_server->sendReply(anAckMsg.str()); - } - aInpStream >> aParam1; - std::cout << "Not crashed. I: " << iCmd << " param= " << aParam1 << std::endl; - TMLTransaction* oLastTrans; - switch (aParam1){ - case 0: //Run to next breakpoint - std::cout << "Run to next breakpoint." << std::endl; - aGlobMsg << TAG_MSGo << "Run to next breakpoint" << TAG_MSGc << std::endl; - _simTerm=runToNextBreakpoint(oLastTrans); - std::cout << "End Run to next breakpoint." << std::endl; - break; - case 1: //Run up to trans x - std::cout << "Run to transaction x." << std::endl; - aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; - anErrorCode=1; - std::cout << "End Run to transaction x." << std::endl; - break; - case 2: //Run x transactions - std::cout << "Run x transactions." << std::endl; - aInpStream >> aParam2; - //_currCmdListener=new RunXTransactions(_simComp,aParam2); - aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " transactions" << TAG_MSGc << std::endl; - _simTerm=runXTransactions(aParam2, oLastTrans); - std::cout << "Run x transactions." << std::endl; - break; - case 3: //Run up to command x - std::cout << "Run to command x." << std::endl; - aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; - anErrorCode=1; - std::cout << "End Run to command x." << std::endl; - break; - case 4: //Run x commands - std::cout << "Run x commands." << std::endl; - aInpStream >> aParam2; - //_currCmdListener=new RunXCommands(_simComp,aParam2); - aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " commands" << TAG_MSGc << std::endl; - _simTerm=runXCommands(aParam2, oLastTrans); - std::cout << "End Run x commands." << std::endl; - break; - case 5: //Run up to time x - std::cout << "Run to time x." << std::endl; - aInpStream >> aParam2; - //_currCmdListener=new RunXTimeUnits(_simComp,aParam2); - aGlobMsg << TAG_MSGo << "Created listener run to time " << aParam2 << TAG_MSGc << std::endl; - _simTerm=runTillTimeX(aParam2, oLastTrans); - std::cout << "End Run to time x." << std::endl; - break; - case 6: //Run for x time units - std::cout << "Run for x time units." << std::endl; - aInpStream >> aParam2; - //_currCmdListener=new RunXTimeUnits(_simComp,aParam2+SchedulableDevice::getSimulatedTime()); - aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " time units" << TAG_MSGc << std::endl; - _simTerm=runXTimeUnits(aParam2, oLastTrans); - std::cout << "End Run for x time units." << std::endl; - break; - case 7: {//Explore Tree - //for (int i=0; i<RECUR_DEPTH; i++) leafsForLevel[i]=0; - std::cout << "Explore tree." << std::endl; - _commandCoverage=100; _branchCoverage=100; - aInpStream >> _commandCoverage; - aInpStream >> _branchCoverage; - std::stringstream aPath; - aPath << _graphOutPath << "tree.dot"; - std::ofstream myDOTfile (aPath.str().c_str()); - aPath.str(""); - aPath << _graphOutPath << "tree.aut.tmp"; - std::ofstream myAUTfile (aPath.str().c_str()); - aPath.str(""); - //std::ofstream myfile2 ("tree.txt"); - if (myDOTfile.is_open() && myAUTfile.is_open()){ -//#ifdef DOT_GRAPH_ENABLED - myDOTfile << "digraph BCG {\nsize = \"7, 10.5\";\ncenter = TRUE;\nnode [shape = circle];\n0 [peripheries = 2];\n"; -//#endif - unsigned int aTransCounter=0; - _terminateExplore=false; - exploreTree(0, 0, myDOTfile, myAUTfile, aTransCounter); -//#ifdef DOT_GRAPH_ENABLED - myDOTfile << "}\n"; - //system ("mv tree tree.dot"); - myDOTfile.close(); -//#else - myAUTfile.close(); - aPath.str(""); - aPath << _graphOutPath << "header"; - std::ofstream myTMPfile (aPath.str().c_str()); - if (myTMPfile.is_open()){ - //des (0, 29, 27) - myTMPfile << "des(0," << aTransCounter << "," << TMLTransaction::getID() << ")\n"; - myTMPfile.close(); - //system ("cat header tree.aut.tmp > tree.aut"); - //system ("rm header tree.aut.tmp"); - aPath.str(""); - aPath << "cat " << _graphOutPath << "header " << _graphOutPath << "tree.aut.tmp > " << _graphOutPath << "tree.aut"; - system(aPath.str().c_str()); - aPath.str(""); - aPath << "rm " << _graphOutPath << "header " << _graphOutPath << "tree.aut.tmp"; - system(aPath.str().c_str()); - } -//#endif - //myfile2.close(); - } - aGlobMsg << TAG_MSGo << "Tree was explored" << TAG_MSGc << std::endl; - _simTerm=true; - //aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; - //anErrorCode=1; - std::cout << "** Longest runtime: " << _longRunTime << ", shortest runtime: " << _shortRunTime << " **\n"; - std::cout << "End Explore tree." << std::endl; - break; - } - case 8:{//Run to next transfer on bus x - std::cout << "Run to next transfer on bus x." << std::endl; - aInpStream >> aStrParam; - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getBusByName(aStrParam)); - SchedulableCommDevice* aBus=_simComp->getBusByName(aStrParam); - if (aBus!=0){ - //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - aGlobMsg << TAG_MSGo << "Created listener on Bus " << aStrParam << TAG_MSGc << std::endl; - _simTerm=runToBusTrans(aBus, oLastTrans); - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run to next transfer on bus x." << std::endl; - break; - } - case 9:{//Run until CPU x executes - std::cout << "Run until CPU x executes." << std::endl; - aInpStream >> aStrParam; - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getCPUByName(aStrParam)); - SchedulableDevice* aCPU=_simComp->getCPUByName(aStrParam); - if (aCPU!=0){ - //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - aGlobMsg << TAG_MSGo << "Created listener on CPU " << aStrParam << TAG_MSGc << std::endl; - _simTerm=runToCPUTrans(aCPU, oLastTrans); - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run until CPU x executes." << std::endl; - break; - } - case 10:{//Run until Task x executes - std::cout << "Run until Task x executes." << std::endl; - aInpStream >> aStrParam; - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getTaskByName(aStrParam)); - TMLTask* aTask=_simComp->getTaskByName(aStrParam); - if (aTask!=0){ - aGlobMsg << TAG_MSGo << "Created listener on Task " << aStrParam << TAG_MSGc << std::endl; - _simTerm=runToTaskTrans(aTask, oLastTrans); - //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run until Task x executes." << std::endl; - break; - } - case 11:{//Run until Mem x is accessed - std::cout << "Run until Mem x is accessed." << std::endl; - aInpStream >> aStrParam; - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getSlaveByName(aStrParam)); - Slave* aSlave=_simComp->getSlaveByName(aStrParam); - if (aSlave!=0){ - //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - aGlobMsg << TAG_MSGo << "Created listener on Slave " << aStrParam << TAG_MSGc << std::endl; - _simTerm=runToSlaveTrans(aSlave, oLastTrans); - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run until Mem x is accessed." << std::endl; - break; - } - case 12:{//Run until operation on channel x is performed - std::cout << "Run until operation on channel x is performed." << std::endl; - aInpStream >> aStrParam; - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getChannelByName(aStrParam)); - TMLChannel* aChannel=_simComp->getChannelByName(aStrParam); - if (aChannel!=0){ - //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - aGlobMsg << TAG_MSGo << "Created listener on Channel " << aStrParam << TAG_MSGc << std::endl; - _simTerm=runToChannelTrans(aChannel, oLastTrans); - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run until operation on channel x is performed." << std::endl; - break; - } - case 13:{//Run to next random choice command - std::cout << "Run to next random command." << std::endl; - _simTerm=runToNextRandomCommand(oLastTrans); - std::cout << "End Run to next random choice command." << std::endl; - break; - } - case 14:{//Run until condition is satisfied - std::cout << "Run until condition is satisfied." << std::endl; - aInpStream >> aStrParam; - TMLTask* aTask=_simComp->getTaskByName(aStrParam); - if (aTask!=0){ - bool aSuccess, aTerminated; - aInpStream >> aStrParam; - aTerminated = runUntilCondition(aStrParam, aTask, oLastTrans, aSuccess); - if (aSuccess){ - _simTerm=aTerminated; - aGlobMsg << TAG_MSGo << "Created listeners for condition " << aStrParam << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CONDERR << TAG_MSGc << std::endl; - anErrorCode=5; - } - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - std::cout << "End Run until condition is satisfied." << std::endl; - break; - } - default: - aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; - anErrorCode=3; - } - gettimeofday(&aEnd,NULL); - _simDuration += getTimeDiff(aBegin,aEnd); - aGlobMsg << TAG_SIMDURo << _simDuration << TAG_SIMDURc << std::endl; - //std::cout << "Before sim\n"; - if (anErrorCode==0){ - //aGlobMsg << TAG_CURRTASKo << oLastTrans->getCommand()->getTask()->getID() << TAG_CURRTASKc; - //simulate(); - //aGlobMsg << - std::cout << "Simulated time: " << SchedulableDevice::getSimulatedTime() << " time units.\n"; - } - _busy=false; - break; - } - case 2: //reset - std::cout << "Simulator reset." << std::endl; - _wasReset=true; - _simComp->reset(); - _simComp->resetStateHash(); - _simTerm=false; - _simDuration=0; - aGlobMsg << TAG_MSGo << "Simulator reset" << TAG_MSGc << std::endl; - std::cout << "End Simulator reset." << std::endl; - break; - case 3:{//Print variable x - std::cout << "Print variable x." << std::endl; - aInpStream >> aStrParam; - if (aStrParam=="all"){ - //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i !=_simComp->getTaskIterator(true); ++i){ - for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i !=_simComp->getTaskList().end(); ++i){ - printVariablesOfTask(*i, anEntityMsg); - } - }else{ - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - if (aTask==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - //std::cout << "Task " << aStrParam << " exists" << std::endl; - aInpStream >> aStrParam; - if (aStrParam=="all"){ - printVariablesOfTask(aTask, anEntityMsg); - }else{ - //std::cout << "Check if Var *" << aStrParam << "* exists" << std::endl; - //std::cout << "Len: " << aStrParam.length() << std::endl; - bool aIsId; - ParamType* aParam=aTask->getVariableByName(aStrParam, aIsId); - if (aParam!=0){ - aGlobMsg << TAG_MSGo << "Variable values" << TAG_MSGc << std::endl; - anEntityMsg << TAG_TASKo << " id=\"" << aTask-> getID() << "\" name=\"" << aTask->toString() << "\">" << TAG_VARo; - if (aIsId) anEntityMsg << " id=\""; else anEntityMsg << " name=\""; - anEntityMsg << aStrParam << "\">" << *aParam << TAG_VARc << TAG_TASKc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - } - } - } - std::cout << "End Print variable x." << std::endl; - break; - } - case 4:{//Print information about simulation element x - //bool aFailure=false; - std::cout << "Print information about simulation element x." << std::endl; - aInpStream >> aParam1; - aInpStream >> aStrParam; - anErrorCode=0; - switch (aParam1){ - case 0: {//CPU - TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getCPUByName(aStrParam)); - if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; - break; - } - case 1: {//Bus - TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getBusByName(aStrParam)); - if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; - break; - } - case 2: //Mem - case 3: //Bridge - anErrorCode=1; - break; - case 4:{ //Channel - TMLChannel* aDevice = _simComp->getChannelByName(aStrParam); - if (aDevice!=0){ - std::cout << "get Channel info" << std::endl; - aDevice->streamStateXML(anEntityMsg); - }else anErrorCode=2; - break; - } - case 5: {//Task - TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getTaskByName(aStrParam)); - if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; - break; - } - default:anErrorCode=3; - } - switch(anErrorCode){ - case 0: - aGlobMsg << TAG_MSGo << "Component information" << TAG_MSGc << std::endl; - break; - case 1: - aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; - break; - case 2: - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - break; - default: - aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; - break; - } - std::cout << "End Print information about simulation element x." << std::endl; - break; - } - case 5:{//Set variable x to value y - std::cout << "Set variable x to value y." << std::endl; - aInpStream >> aStrParam; - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - if (aTask==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - aInpStream >> aStrParam; - bool aIsId; - ParamType* aParam=aTask->getVariableByName(aStrParam, aIsId); - if (aParam!=0){ - aInpStream >> *aParam; - aGlobMsg << TAG_MSGo << "Set variable " << aStrParam << " to " << *aParam << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - } - std::cout << "End Set variable x to value y." << std::endl; - break; - } - case 6:{ //Write x samples/events to channel y - std::cout << "Write x samples/events to channel y." << std::endl; - //aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; - //anErrorCode=1; - aInpStream >> aStrParam; - TMLChannel* aChannel = _simComp->getChannelByName(aStrParam); - if (aChannel==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - aInpStream >> aParam1; - TMLEventChannel* anEventChannel = dynamic_cast<TMLEventChannel*>(aChannel); - if (anEventChannel==0){ - //aChannel->insertSamples(aParam1, anInsertParam); - aChannel->insertSamples(aParam1, 0); - }else{ - //Parameter<ParamType> anInsertParam((dynamic_cast<TMLEventChannel*>(aChannel))->getParamNo()); - Parameter* anInsertParam = anEventChannel->buildParameter(); - aInpStream >> anInsertParam; - //aChannel->insertSamples(aParam1, anInsertParam); - aChannel->insertSamples(aParam1, anInsertParam); - } - aGlobMsg << TAG_MSGo << "Write data/event to channel." << TAG_MSGc << std::endl; - } - std::cout << "End Write x samples/events to channel y." << std::endl; - break; - } - case 7: //Save trace in file x - std::cout << "Save trace in file x." << std::endl; - aInpStream >> aParam1; - aInpStream >>aStrParam; - switch (aParam1){ - case 0: //VCD - aGlobMsg << TAG_MSGo << "Schedule output in VCD format" << TAG_MSGc << std::endl; - schedule2VCD(aStrParam); - break; - case 1: //HTML - aGlobMsg << TAG_MSGo << "Schedule output in HTML format" << TAG_MSGc << std::endl; - schedule2HTML(aStrParam); - break; - case 2: //TXT - aGlobMsg << TAG_MSGo << "Schedule output in TXT format" << TAG_MSGc << std::endl; - schedule2TXT(aStrParam); - break; - default: - aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; - anErrorCode=3; - } - std::cout << "End Save trace in file x." << std::endl; - break; - case 8:{ //Save simulation state in file x - std::cout << "Save simulation state in file x." << std::endl; - aInpStream >> aStrParam; - std::ofstream aFile (aStrParam.c_str()); - if (aFile.is_open()){ - _simComp->writeObject(aFile); - aGlobMsg << TAG_MSGo << "Simulation state saved in file " << aStrParam << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; - anErrorCode=4; - } - std::cout << "End Save simulation state in file x." << std::endl; - break; - } - case 9:{//Restore simulation state from file x - std::cout << "Restore simulation state from file x." << std::endl; - aInpStream >> aStrParam; - std::ifstream aFile(aStrParam.c_str()); - if (aFile.is_open()){ - _simTerm=false; - _simComp->reset(); - _simComp->readObject(aFile); - aGlobMsg << TAG_MSGo << "Simulation state restored from file " << aStrParam << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; - anErrorCode=4; - } - std::cout << "End Restore simulation state from file x." << std::endl; - break; - } - case 10:{ //Save benchmarks in file x - std::cout << "Save benchmarks in file x." << std::endl; - aInpStream >> aParam1; - switch (aParam1){ - case 0: _simComp->streamBenchmarks(std::cout); - aGlobMsg << TAG_MSGo << "Benchmarks written to screen " << TAG_MSGc << std::endl; - break; - case 1:{ - aInpStream >> aStrParam; - std::ofstream aFile (aStrParam.c_str()); - if (aFile.is_open()){ - _simComp->streamBenchmarks(aFile); - aGlobMsg << TAG_MSGo << "Benchmarks written to file " << aStrParam << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; - anErrorCode=4; - } - break; - } - default: - aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; - anErrorCode=3; - } - std::cout << "End Save benchmarks in file x." << std::endl; - break; - } - case 11:{//Set breakpoint in task x, command y - std::cout << "Set breakpoint in task x, command y." << std::endl; - aInpStream >> aStrParam; - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - if (aTask==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - aInpStream >> aParam2; - TMLCommand* aCommand=aTask->getCommandByID(aParam2); - if (aCommand!=0){ - aCommand->setBreakpoint(new Breakpoint(_simComp)); - _breakpoints.insert(aCommand); - aGlobMsg << TAG_MSGo << "Breakpoint was created" << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - } - std::cout << "End Set breakpoint in task x, command y." << std::endl; - break; - } - case 12:{//Choose branch - std::cout << "Choose branch." << std::endl; - aInpStream >> aStrParam; - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - if (aTask==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - aInpStream >> aParam1; - //TMLChoiceCommand* aChoiceCmd=dynamic_cast<TMLChoiceCommand*>(aTask->getCommandByID(aParam1)); - IndeterminismSource* aRandomCmd=dynamic_cast<IndeterminismSource*>(aTask->getCommandByID(aParam1)); - if (aRandomCmd!=0){ - aInpStream >> aParam2; - //aChoiceCmd->setPreferredBranch(aParam2); - aRandomCmd->setRandomValue(aParam2); - aGlobMsg << TAG_MSGo << "Preferred branch was set" << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - } - std::cout << "End Choose branch." << std::endl; - break; - } - case 16:{//Delete breakpoint in task x, command y - std::cout << "Delete breakpoint in task x, command y." << std::endl; - aInpStream >> aStrParam; - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - if (aTask==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ + case 0: //Quit simulation + std::cout << "QUIT SIMULATION from Decode Command" << std::endl; + break; + case 1:{ + struct timeval aBegin,aEnd; + gettimeofday(&aBegin,NULL); + _busy=true; + //std::cout << "Not crashed. I: " << iCmd << std::endl; + anAckMsg << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << /*TAG_REPLYo << anIssuedCmd << TAG_REPLYc << std::endl<< */ TAG_MSGo << "Command received" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl << TAG_STATUSo << SIM_BUSY << TAG_STATUSc << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + if (_replyToServer) { + if (_syncInfo != NULL) + if (_syncInfo->_server != NULL) + _syncInfo->_server->sendReply(anAckMsg.str()); + } + aInpStream >> aParam1; + std::cout << "Not crashed. I: " << iCmd << " param= " << aParam1 << std::endl; + TMLTransaction* oLastTrans; + switch (aParam1){ + case 0: //Run to next breakpoint + std::cout << "Run to next breakpoint." << std::endl; + aGlobMsg << TAG_MSGo << "Run to next breakpoint" << TAG_MSGc << std::endl; + _simTerm=runToNextBreakpoint(oLastTrans); + std::cout << "End Run to next breakpoint." << std::endl; + break; + case 1: //Run up to trans x + std::cout << "Run to transaction x." << std::endl; + aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + anErrorCode=1; + std::cout << "End Run to transaction x." << std::endl; + break; + case 2: //Run x transactions + std::cout << "Run x transactions." << std::endl; + aInpStream >> aParam2; + //_currCmdListener=new RunXTransactions(_simComp,aParam2); + aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " transactions" << TAG_MSGc << std::endl; + _simTerm=runXTransactions(aParam2, oLastTrans); + std::cout << "Run x transactions." << std::endl; + break; + case 3: //Run up to command x + std::cout << "Run to command x." << std::endl; + aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + anErrorCode=1; + std::cout << "End Run to command x." << std::endl; + break; + case 4: //Run x commands + std::cout << "Run x commands." << std::endl; + aInpStream >> aParam2; + //_currCmdListener=new RunXCommands(_simComp,aParam2); + aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " commands" << TAG_MSGc << std::endl; + _simTerm=runXCommands(aParam2, oLastTrans); + std::cout << "End Run x commands." << std::endl; + break; + case 5: //Run up to time x + std::cout << "Run to time x." << std::endl; + aInpStream >> aParam2; + //_currCmdListener=new RunXTimeUnits(_simComp,aParam2); + aGlobMsg << TAG_MSGo << "Created listener run to time " << aParam2 << TAG_MSGc << std::endl; + _simTerm=runTillTimeX(aParam2, oLastTrans); + std::cout << "End Run to time x." << std::endl; + break; + case 6: //Run for x time units + std::cout << "Run for x time units." << std::endl; + aInpStream >> aParam2; + //_currCmdListener=new RunXTimeUnits(_simComp,aParam2+SchedulableDevice::getSimulatedTime()); + aGlobMsg << TAG_MSGo << "Created listener run " << aParam2 << " time units" << TAG_MSGc << std::endl; + _simTerm=runXTimeUnits(aParam2, oLastTrans); + std::cout << "End Run for x time units." << std::endl; + break; + case 7: {//Explore Tree + //for (int i=0; i<RECUR_DEPTH; i++) leafsForLevel[i]=0; + std::cout << "Explore tree." << std::endl; + _commandCoverage=100; _branchCoverage=100; + aInpStream >> _commandCoverage; + aInpStream >> _branchCoverage; + std::stringstream aPath; + aPath << _graphOutPath << "tree.dot"; + std::ofstream myDOTfile (aPath.str().c_str()); + aPath.str(""); + aPath << _graphOutPath << "tree.aut.tmp"; + std::ofstream myAUTfile (aPath.str().c_str()); + aPath.str(""); + //std::ofstream myfile2 ("tree.txt"); + if (myDOTfile.is_open() && myAUTfile.is_open()){ + //#ifdef DOT_GRAPH_ENABLED + myDOTfile << "digraph BCG {\nsize = \"7, 10.5\";\ncenter = TRUE;\nnode [shape = circle];\n0 [peripheries = 2];\n"; + //#endif + unsigned int aTransCounter=0; + _terminateExplore=false; + exploreTree(0, 0, myDOTfile, myAUTfile, aTransCounter); + //#ifdef DOT_GRAPH_ENABLED + myDOTfile << "}\n"; + //system ("mv tree tree.dot"); + myDOTfile.close(); + //#else + myAUTfile.close(); + aPath.str(""); + aPath << _graphOutPath << "header"; + std::ofstream myTMPfile (aPath.str().c_str()); + if (myTMPfile.is_open()){ + //des (0, 29, 27) + myTMPfile << "des(0," << aTransCounter << "," << TMLTransaction::getID() << ")\n"; + myTMPfile.close(); + //system ("cat header tree.aut.tmp > tree.aut"); + //system ("rm header tree.aut.tmp"); + aPath.str(""); + aPath << "cat " << _graphOutPath << "header " << _graphOutPath << "tree.aut.tmp > " << _graphOutPath << "tree.aut"; + system(aPath.str().c_str()); + aPath.str(""); + aPath << "rm " << _graphOutPath << "header " << _graphOutPath << "tree.aut.tmp"; + system(aPath.str().c_str()); + } + //#endif + //myfile2.close(); + } + aGlobMsg << TAG_MSGo << "Tree was explored" << TAG_MSGc << std::endl; + _simTerm=true; + //aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + //anErrorCode=1; + std::cout << "** Longest runtime: " << _longRunTime << ", shortest runtime: " << _shortRunTime << " **\n"; + std::cout << "End Explore tree." << std::endl; + break; + } + case 8:{//Run to next transfer on bus x + std::cout << "Run to next transfer on bus x." << std::endl; + aInpStream >> aStrParam; + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getBusByName(aStrParam)); + SchedulableCommDevice* aBus=_simComp->getBusByName(aStrParam); + if (aBus!=0){ + //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); + aGlobMsg << TAG_MSGo << "Created listener on Bus " << aStrParam << TAG_MSGc << std::endl; + _simTerm=runToBusTrans(aBus, oLastTrans); + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run to next transfer on bus x." << std::endl; + break; + } + case 9:{//Run until CPU x executes + std::cout << "Run until CPU x executes." << std::endl; + aInpStream >> aStrParam; + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getCPUByName(aStrParam)); + SchedulableDevice* aCPU=_simComp->getCPUByName(aStrParam); + if (aCPU!=0){ + //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); + aGlobMsg << TAG_MSGo << "Created listener on CPU " << aStrParam << TAG_MSGc << std::endl; + _simTerm=runToCPUTrans(aCPU, oLastTrans); + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run until CPU x executes." << std::endl; + break; + } + case 10:{//Run until Task x executes + std::cout << "Run until Task x executes." << std::endl; + aInpStream >> aStrParam; + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getTaskByName(aStrParam)); + TMLTask* aTask=_simComp->getTaskByName(aStrParam); + if (aTask!=0){ + aGlobMsg << TAG_MSGo << "Created listener on Task " << aStrParam << TAG_MSGc << std::endl; + _simTerm=runToTaskTrans(aTask, oLastTrans); + //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); - aInpStream >> aParam2; - TMLCommand* aCommand=aTask->getCommandByID(aParam2); - if (aCommand!=0){ - aCommand->removeBreakpoint(); - _breakpoints.erase(aCommand); - aGlobMsg << TAG_MSGo << "Breakpoint was removed" << TAG_MSGc << std::endl; - }else{ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - } - } - std::cout << "End Delete breakpoint in task x, command y." << std::endl; - break; - } - case 17:{//Get number of branches of current cmd - std::cout << "Get number of branches of current cmd." << std::endl; - IndeterminismSource* aRandomCmd =_simComp->getCurrentRandomCmd(); - if (aRandomCmd==0){ - aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; - anErrorCode=2; - }else{ - unsigned int aNbNextCmds; - aNbNextCmds = aRandomCmd->getRandomRange(); - TMLCommand* aCmd = dynamic_cast<TMLCommand*>(aRandomCmd); - anEntityMsg << TAG_TASKo << " id=\"" << aCmd->getTask()-> getID() << "\" name=\"" << aCmd->getTask()->toString() << "\">" << TAG_CURRCMDo << " id=\"" << aCmd->getID() << "\">" << TAG_BRANCHo << aNbNextCmds << TAG_BRANCHc << "\">" << TAG_CURRCMDc << TAG_TASKc << std::endl; - aGlobMsg << TAG_MSGo << "Current choice command" << TAG_MSGc << std::endl; - } - std::cout << "End Get number of branches of current cmd." << std::endl; - break; - } - case 18:{//Get breakpoint list - std::cout << "Get breakpoint list." << std::endl; - for(BreakpointSet::iterator i=_breakpoints.begin(); i != _breakpoints.end(); ++i){ - anEntityMsg << TAG_TASKo << " id=\"" << (*i)->getTask()->getID() << "\" name=\"" << (*i)->getTask()->toString() << "\">" << TAG_BREAKCMDo << " id=\"" << (*i)->getID() << "\">" << TAG_BREAKCMDc << TAG_TASKc << std::endl; - } - aGlobMsg << TAG_MSGo << "Breakpoint List" << TAG_MSGc << std::endl; - std::cout << "End Get breakpoint list." << std::endl; - break; - } - case 19://Get Hash Value - std::cout << "Get Hash Value." << std::endl; - aGlobMsg << TAG_HASHo << _simComp->getHashValue() << TAG_HASHc << TAG_MSGo << "Hash Value Notification" << TAG_MSGc << std::endl; - std::cout << "End Get Hash Value." << std::endl; - break; - case 20://Enable Breakpoints - std::cout << "Enable Breakpoints." << std::endl; - aInpStream >> aParam1; - if (aParam1==0){ - aGlobMsg << TAG_MSGo << "Breakpoints are disabled." << TAG_MSGc << std::endl; - Breakpoint::setEnabled(false); - }else{ - aGlobMsg << TAG_MSGo << "Breakpoints are enabled." << TAG_MSGc << std::endl; - Breakpoint::setEnabled(true); - } - std::cout << "End Enable Breakpoints." << std::endl; - break; - case 21://Get execution statistics of commands - std::cout << "Get execution statistics of commands." << std::endl; - TMLCommand::streamStateXML(aGlobMsg); - std::cout << "End Get execution statistics of commands." << std::endl; - break; - case 22://Get list of transactions - std::cout << "Get list of transactions." << std::endl; - //aGlobMsg << TAG_MSGo << "Breakpoints are disabled." << TAG_MSGc << std::endl; - allTrans2XML(aGlobMsg); - std::cout << "End list of transactions." << std::endl; - break; - default: - aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; - anErrorCode=3; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run until Task x executes." << std::endl; + break; + } + case 11:{//Run until Mem x is accessed + std::cout << "Run until Mem x is accessed." << std::endl; + aInpStream >> aStrParam; + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getSlaveByName(aStrParam)); + Slave* aSlave=_simComp->getSlaveByName(aStrParam); + if (aSlave!=0){ + //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); + aGlobMsg << TAG_MSGo << "Created listener on Slave " << aStrParam << TAG_MSGc << std::endl; + _simTerm=runToSlaveTrans(aSlave, oLastTrans); + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run until Mem x is accessed." << std::endl; + break; + } + case 12:{//Run until operation on channel x is performed + std::cout << "Run until operation on channel x is performed." << std::endl; + aInpStream >> aStrParam; + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (_simComp->getChannelByName(aStrParam)); + TMLChannel* aChannel=_simComp->getChannelByName(aStrParam); + if (aChannel!=0){ + //_currCmdListener=new RunTillTransOnDevice(_simComp, aSubject); + aGlobMsg << TAG_MSGo << "Created listener on Channel " << aStrParam << TAG_MSGc << std::endl; + _simTerm=runToChannelTrans(aChannel, oLastTrans); + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run until operation on channel x is performed." << std::endl; + break; + } + case 13:{//Run to next random choice command + std::cout << "Run to next random command." << std::endl; + _simTerm=runToNextRandomCommand(oLastTrans); + std::cout << "End Run to next random choice command." << std::endl; + break; + } + case 14:{//Run until condition is satisfied + std::cout << "Run until condition is satisfied." << std::endl; + aInpStream >> aStrParam; + TMLTask* aTask=_simComp->getTaskByName(aStrParam); + if (aTask!=0){ + bool aSuccess, aTerminated; + aInpStream >> aStrParam; + aTerminated = runUntilCondition(aStrParam, aTask, oLastTrans, aSuccess); + if (aSuccess){ + _simTerm=aTerminated; + aGlobMsg << TAG_MSGo << "Created listeners for condition " << aStrParam << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CONDERR << TAG_MSGc << std::endl; + anErrorCode=5; + } + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + std::cout << "End Run until condition is satisfied." << std::endl; + break; + } + default: + aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; + anErrorCode=3; + } + gettimeofday(&aEnd,NULL); + _simDuration += getTimeDiff(aBegin,aEnd); + aGlobMsg << TAG_SIMDURo << _simDuration << TAG_SIMDURc << std::endl; + //std::cout << "Before sim\n"; + if (anErrorCode==0){ + //aGlobMsg << TAG_CURRTASKo << oLastTrans->getCommand()->getTask()->getID() << TAG_CURRTASKc; + //simulate(); + //aGlobMsg << + std::cout << "Simulated time: " << SchedulableDevice::getSimulatedTime() << " time units.\n"; + } + _busy=false; + break; + } + case 2: //reset + std::cout << "Simulator reset." << std::endl; + _wasReset=true; + _simComp->reset(); + _simComp->resetStateHash(); + _simTerm=false; + _simDuration=0; + aGlobMsg << TAG_MSGo << "Simulator reset" << TAG_MSGc << std::endl; + std::cout << "End Simulator reset." << std::endl; + break; + case 3:{//Print variable x + std::cout << "Print variable x." << std::endl; + aInpStream >> aStrParam; + if (aStrParam=="all"){ + //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i !=_simComp->getTaskIterator(true); ++i){ + for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i !=_simComp->getTaskList().end(); ++i){ + printVariablesOfTask(*i, anEntityMsg); + } + }else{ + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + if (aTask==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + //std::cout << "Task " << aStrParam << " exists" << std::endl; + aInpStream >> aStrParam; + if (aStrParam=="all"){ + printVariablesOfTask(aTask, anEntityMsg); + }else{ + //std::cout << "Check if Var *" << aStrParam << "* exists" << std::endl; + //std::cout << "Len: " << aStrParam.length() << std::endl; + bool aIsId; + ParamType* aParam=aTask->getVariableByName(aStrParam, aIsId); + if (aParam!=0){ + aGlobMsg << TAG_MSGo << "Variable values" << TAG_MSGc << std::endl; + anEntityMsg << TAG_TASKo << " id=\"" << aTask-> getID() << "\" name=\"" << aTask->toString() << "\">" << TAG_VARo; + if (aIsId) anEntityMsg << " id=\""; else anEntityMsg << " name=\""; + anEntityMsg << aStrParam << "\">" << *aParam << TAG_VARc << TAG_TASKc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + } + } + } + std::cout << "End Print variable x." << std::endl; + break; + } + case 4:{//Print information about simulation element x + //bool aFailure=false; + std::cout << "Print information about simulation element x." << std::endl; + aInpStream >> aParam1; + aInpStream >> aStrParam; + anErrorCode=0; + switch (aParam1){ + case 0: {//CPU + TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getCPUByName(aStrParam)); + if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; + break; + } + case 1: {//Bus + TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getBusByName(aStrParam)); + if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; + break; + } + case 2: //Mem + case 3: //Bridge + anErrorCode=1; + break; + case 4:{ //Channel + TMLChannel* aDevice = _simComp->getChannelByName(aStrParam); + if (aDevice!=0){ + std::cout << "get Channel info" << std::endl; + aDevice->streamStateXML(anEntityMsg); + }else anErrorCode=2; + break; + } + case 5: {//Task + TraceableDevice* aDevice = dynamic_cast<TraceableDevice*>(_simComp->getTaskByName(aStrParam)); + if (aDevice!=0) aDevice->streamStateXML(anEntityMsg); else anErrorCode=2; + break; + } + default:anErrorCode=3; + } + switch(anErrorCode){ + case 0: + aGlobMsg << TAG_MSGo << "Component information" << TAG_MSGc << std::endl; + break; + case 1: + aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + break; + case 2: + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + break; + default: + aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; + break; + } + std::cout << "End Print information about simulation element x." << std::endl; + break; + } + case 5:{//Set variable x to value y + std::cout << "Set variable x to value y." << std::endl; + aInpStream >> aStrParam; + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + if (aTask==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + aInpStream >> aStrParam; + bool aIsId; + ParamType* aParam=aTask->getVariableByName(aStrParam, aIsId); + if (aParam!=0){ + aInpStream >> *aParam; + aGlobMsg << TAG_MSGo << "Set variable " << aStrParam << " to " << *aParam << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + } + std::cout << "End Set variable x to value y." << std::endl; + break; + } + case 6:{ //Write x samples/events to channel y + std::cout << "Write x samples/events to channel y." << std::endl; + //aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + //anErrorCode=1; + aInpStream >> aStrParam; + TMLChannel* aChannel = _simComp->getChannelByName(aStrParam); + if (aChannel==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + aInpStream >> aParam1; + TMLEventChannel* anEventChannel = dynamic_cast<TMLEventChannel*>(aChannel); + if (anEventChannel==0){ + //aChannel->insertSamples(aParam1, anInsertParam); + aChannel->insertSamples(aParam1, 0); + }else{ + //Parameter<ParamType> anInsertParam((dynamic_cast<TMLEventChannel*>(aChannel))->getParamNo()); + Parameter* anInsertParam = anEventChannel->buildParameter(); + aInpStream >> anInsertParam; + //aChannel->insertSamples(aParam1, anInsertParam); + aChannel->insertSamples(aParam1, anInsertParam); + } + aGlobMsg << TAG_MSGo << "Write data/event to channel." << TAG_MSGc << std::endl; + } + std::cout << "End Write x samples/events to channel y." << std::endl; + break; + } + case 7: //Save trace in file x + std::cout << "Save trace in file x." << std::endl; + aInpStream >> aParam1; + aInpStream >>aStrParam; + switch (aParam1){ + case 0: //VCD + aGlobMsg << TAG_MSGo << "Schedule output in VCD format" << TAG_MSGc << std::endl; + schedule2VCD(aStrParam); + break; + case 1: //HTML + aGlobMsg << TAG_MSGo << "Schedule output in HTML format" << TAG_MSGc << std::endl; + schedule2HTML(aStrParam); + break; + case 2: //TXT + aGlobMsg << TAG_MSGo << "Schedule output in TXT format" << TAG_MSGc << std::endl; + schedule2TXT(aStrParam); + break; + default: + aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; + anErrorCode=3; + } + std::cout << "End Save trace in file x." << std::endl; + break; + case 8:{ //Save simulation state in file x + std::cout << "Save simulation state in file x." << std::endl; + aInpStream >> aStrParam; + std::ofstream aFile (aStrParam.c_str()); + if (aFile.is_open()){ + _simComp->writeObject(aFile); + aGlobMsg << TAG_MSGo << "Simulation state saved in file " << aStrParam << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; + anErrorCode=4; + } + std::cout << "End Save simulation state in file x." << std::endl; + break; + } + case 9:{//Restore simulation state from file x + std::cout << "Restore simulation state from file x." << std::endl; + aInpStream >> aStrParam; + std::ifstream aFile(aStrParam.c_str()); + if (aFile.is_open()){ + _simTerm=false; + _simComp->reset(); + _simComp->readObject(aFile); + aGlobMsg << TAG_MSGo << "Simulation state restored from file " << aStrParam << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; + anErrorCode=4; + } + std::cout << "End Restore simulation state from file x." << std::endl; + break; + } + case 10:{ //Save benchmarks in file x + std::cout << "Save benchmarks in file x." << std::endl; + aInpStream >> aParam1; + switch (aParam1){ + case 0: _simComp->streamBenchmarks(std::cout); + aGlobMsg << TAG_MSGo << "Benchmarks written to screen " << TAG_MSGc << std::endl; + break; + case 1:{ + aInpStream >> aStrParam; + std::ofstream aFile (aStrParam.c_str()); + if (aFile.is_open()){ + _simComp->streamBenchmarks(aFile); + aGlobMsg << TAG_MSGo << "Benchmarks written to file " << aStrParam << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_FILEERR << aStrParam << TAG_MSGc << std::endl; + anErrorCode=4; + } + break; + } + default: + aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; + anErrorCode=3; + } + std::cout << "End Save benchmarks in file x." << std::endl; + break; + } + case 11:{//Set breakpoint in task x, command y + std::cout << "Set breakpoint in task x, command y." << std::endl; + aInpStream >> aStrParam; + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + if (aTask==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + aInpStream >> aParam2; + TMLCommand* aCommand=aTask->getCommandByID(aParam2); + if (aCommand!=0){ + aCommand->setBreakpoint(new Breakpoint(_simComp)); + _breakpoints.insert(aCommand); + aGlobMsg << TAG_MSGo << "Breakpoint was created" << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + } + std::cout << "End Set breakpoint in task x, command y." << std::endl; + break; + } + case 12:{//Choose branch + std::cout << "Choose branch." << std::endl; + aInpStream >> aStrParam; + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + if (aTask==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + aInpStream >> aParam1; + //TMLChoiceCommand* aChoiceCmd=dynamic_cast<TMLChoiceCommand*>(aTask->getCommandByID(aParam1)); + IndeterminismSource* aRandomCmd=dynamic_cast<IndeterminismSource*>(aTask->getCommandByID(aParam1)); + if (aRandomCmd!=0){ + aInpStream >> aParam2; + //aChoiceCmd->setPreferredBranch(aParam2); + aRandomCmd->setRandomValue(aParam2); + aGlobMsg << TAG_MSGo << "Preferred branch was set" << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + } + std::cout << "End Choose branch." << std::endl; + break; + } + case 16:{//Delete breakpoint in task x, command y + std::cout << "Delete breakpoint in task x, command y." << std::endl; + aInpStream >> aStrParam; + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + if (aTask==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + + aInpStream >> aParam2; + TMLCommand* aCommand=aTask->getCommandByID(aParam2); + if (aCommand!=0){ + aCommand->removeBreakpoint(); + _breakpoints.erase(aCommand); + aGlobMsg << TAG_MSGo << "Breakpoint was removed" << TAG_MSGc << std::endl; + }else{ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } + } + std::cout << "End Delete breakpoint in task x, command y." << std::endl; + break; + } + case 17:{//Get number of branches of current cmd + std::cout << "Get number of branches of current cmd." << std::endl; + IndeterminismSource* aRandomCmd =_simComp->getCurrentRandomCmd(); + if (aRandomCmd==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + }else{ + unsigned int aNbNextCmds; + aNbNextCmds = aRandomCmd->getRandomRange(); + TMLCommand* aCmd = dynamic_cast<TMLCommand*>(aRandomCmd); + anEntityMsg << TAG_TASKo << " id=\"" << aCmd->getTask()-> getID() << "\" name=\"" << aCmd->getTask()->toString() << "\">" << TAG_CURRCMDo << " id=\"" << aCmd->getID() << "\">" << TAG_BRANCHo << aNbNextCmds << TAG_BRANCHc << "\">" << TAG_CURRCMDc << TAG_TASKc << std::endl; + aGlobMsg << TAG_MSGo << "Current choice command" << TAG_MSGc << std::endl; + } + std::cout << "End Get number of branches of current cmd." << std::endl; + break; + } + case 18:{//Get breakpoint list + std::cout << "Get breakpoint list." << std::endl; + for(BreakpointSet::iterator i=_breakpoints.begin(); i != _breakpoints.end(); ++i){ + anEntityMsg << TAG_TASKo << " id=\"" << (*i)->getTask()->getID() << "\" name=\"" << (*i)->getTask()->toString() << "\">" << TAG_BREAKCMDo << " id=\"" << (*i)->getID() << "\">" << TAG_BREAKCMDc << TAG_TASKc << std::endl; + } + aGlobMsg << TAG_MSGo << "Breakpoint List" << TAG_MSGc << std::endl; + std::cout << "End Get breakpoint list." << std::endl; + break; + } + case 19://Get Hash Value + std::cout << "Get Hash Value." << std::endl; + aGlobMsg << TAG_HASHo << _simComp->getHashValue() << TAG_HASHc << TAG_MSGo << "Hash Value Notification" << TAG_MSGc << std::endl; + std::cout << "End Get Hash Value." << std::endl; + break; + case 20://Enable Breakpoints + std::cout << "Enable Breakpoints." << std::endl; + aInpStream >> aParam1; + if (aParam1==0){ + aGlobMsg << TAG_MSGo << "Breakpoints are disabled." << TAG_MSGc << std::endl; + Breakpoint::setEnabled(false); + }else{ + aGlobMsg << TAG_MSGo << "Breakpoints are enabled." << TAG_MSGc << std::endl; + Breakpoint::setEnabled(true); + } + std::cout << "End Enable Breakpoints." << std::endl; + break; + case 21://Get execution statistics of commands + std::cout << "Get execution statistics of commands." << std::endl; + TMLCommand::streamStateXML(aGlobMsg); + std::cout << "End Get execution statistics of commands." << std::endl; + break; + case 22://Get list of transactions + aInpStream >> aParam2; + std::cout << "Get list of at most " << aParam2 << " transactions per CPU and Bus." << std::endl; + //aGlobMsg << TAG_MSGo << "Breakpoints are disabled." << TAG_MSGc << std::endl; + allTrans2XML(aGlobMsg, aParam2); + std::cout << "End list of transactions." << std::endl; + break; + default: + aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; + anErrorCode=3; - } - aGlobMsg << TAG_ERRNOo << anErrorCode << TAG_ERRNOc << std::endl; - //if (aSimTerminated) aGlobMsg << SIM_TERM; else aGlobMsg << SIM_READY; - writeSimState(aGlobMsg); - aGlobMsg << std::endl << TAG_GLOBALc << std::endl << anEntityMsg.str() << TAG_STARTc << std::endl; - //std::cout << "Before reply." << std::endl; - if (_replyToServer) - if (_syncInfo->_server != NULL) - _syncInfo->_server->sendReply(aGlobMsg.str()); else iXmlOutStream << aGlobMsg.str() << "\n"; - //std::cout << "End of command decode procedure." << std::endl; - //std::cout << "Command: " << aCmd << " Param1: " << aParam1 << " Param2: " << aParam2 << std::endl; + } + aGlobMsg << TAG_ERRNOo << anErrorCode << TAG_ERRNOc << std::endl; + //if (aSimTerminated) aGlobMsg << SIM_TERM; else aGlobMsg << SIM_READY; + writeSimState(aGlobMsg); + aGlobMsg << std::endl << TAG_GLOBALc << std::endl << anEntityMsg.str() << TAG_STARTc << std::endl; + //std::cout << "Before reply." << std::endl; + if (_replyToServer) { + if (_syncInfo->_server != NULL) { + _syncInfo->_server->sendReply(aGlobMsg.str()); + } else { + iXmlOutStream << aGlobMsg.str() << "\n"; + } + } + //std::cout << "End of command decode procedure." << std::endl; + //std::cout << "Command: " << aCmd << " Param1: " << aParam1 << " Param2: " << aParam2 << std::endl; } void Simulator::printVariablesOfTask(TMLTask* iTask, std::ostream& ioMessage){ - //if (iTask->getVariableIteratorID(false)==iTask->getVariableIteratorID(true)) return; - if (iTask->getVariableLookUpTableID().size()>0){ - ioMessage << TAG_TASKo << " id=\"" << iTask-> getID() << "\" name=\"" << iTask->toString() << "\">" << std::endl; - //for(VariableLookUpTableID::const_iterator i=iTask->getVariableIteratorID(false); i !=iTask->getVariableIteratorID(true); ++i){ - for(VariableLookUpTableID::const_iterator i=iTask->getVariableLookUpTableID().begin(); i !=iTask->getVariableLookUpTableID().end(); ++i){ - ioMessage << TAG_VARo << " id=\"" << i->first << "\">" << *(i->second) << TAG_VARc << std::endl; - } - ioMessage << TAG_TASKc << std::endl; - } + //if (iTask->getVariableIteratorID(false)==iTask->getVariableIteratorID(true)) return; + if (iTask->getVariableLookUpTableID().size()>0){ + ioMessage << TAG_TASKo << " id=\"" << iTask-> getID() << "\" name=\"" << iTask->toString() << "\">" << std::endl; + //for(VariableLookUpTableID::const_iterator i=iTask->getVariableIteratorID(false); i !=iTask->getVariableIteratorID(true); ++i){ + for(VariableLookUpTableID::const_iterator i=iTask->getVariableLookUpTableID().begin(); i !=iTask->getVariableLookUpTableID().end(); ++i){ + ioMessage << TAG_VARo << " id=\"" << i->first << "\">" << *(i->second) << TAG_VARc << std::endl; + } + ioMessage << TAG_TASKc << std::endl; + } } bool Simulator::runToNextBreakpoint(TMLTransaction*& oLastTrans){ - //TestListener myListener(_simComp); - //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->registerListener(&myListener); - //_simComp->getChannelByName("DIPLODOCUSDesign__evt")->registerListener(&myListener); - //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->getCommandByID(17)->registerListener(&myListener); - bool erg=simulate(oLastTrans); - //return simulate(oLastTrans); - //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->removeListener(&myListener); - //_simComp->getChannelByName("DIPLODOCUSDesign__evt")->removeListener(&myListener); - //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->getCommandByID(17)->removeListener(&myListener); - return erg; + //TestListener myListener(_simComp); + //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->registerListener(&myListener); + //_simComp->getChannelByName("DIPLODOCUSDesign__evt")->registerListener(&myListener); + //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->getCommandByID(17)->registerListener(&myListener); + bool erg=simulate(oLastTrans); + //return simulate(oLastTrans); + //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->removeListener(&myListener); + //_simComp->getChannelByName("DIPLODOCUSDesign__evt")->removeListener(&myListener); + //_simComp->getTaskByName("DIPLODOCUSDesign__TMLTask_0")->getCommandByID(17)->removeListener(&myListener); + return erg; } bool Simulator::runXTransactions(unsigned int iTrans, TMLTransaction*& oLastTrans){ - RunXTransactions aListener(_simComp, iTrans); - return simulate(oLastTrans); + RunXTransactions aListener(_simComp, iTrans); + return simulate(oLastTrans); } bool Simulator::runXCommands(unsigned int iCmds, TMLTransaction*& oLastTrans){ - RunXCommands aListener(_simComp,iCmds); - bool test=simulate(oLastTrans); - if (test) std::cout << "Simulate returned end" << std::endl; - return test; + RunXCommands aListener(_simComp,iCmds); + bool test=simulate(oLastTrans); + if (test) std::cout << "Simulate returned end" << std::endl; + return test; } bool Simulator::runTillTimeX(TMLTime iTime, TMLTransaction*& oLastTrans){ - RunXTimeUnits aListener(_simComp,iTime); - return simulate(oLastTrans); + RunXTimeUnits aListener(_simComp,iTime); + return simulate(oLastTrans); } bool Simulator::runXTimeUnits(TMLTime iTime, TMLTransaction*& oLastTrans){ - RunXTimeUnits aListener(_simComp,iTime+SchedulableDevice::getSimulatedTime()); - return simulate(oLastTrans); + RunXTimeUnits aListener(_simComp,iTime+SchedulableDevice::getSimulatedTime()); + return simulate(oLastTrans); } bool Simulator::runToBusTrans(SchedulableCommDevice* iBus, TMLTransaction*& oLastTrans){ - //ListenerSubject <TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iBus); - ListenerSubject <GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iBus); - RunTillTransOnDevice aListener(_simComp, aSubject); - return simulate(oLastTrans); + //ListenerSubject <TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iBus); + ListenerSubject <GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iBus); + RunTillTransOnDevice aListener(_simComp, aSubject); + return simulate(oLastTrans); } bool Simulator::runToCPUTrans(SchedulableDevice* iCPU, TMLTransaction*& oLastTrans){ - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iCPU); - ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iCPU); - RunTillTransOnDevice aListener(_simComp, aSubject); - return simulate(oLastTrans); + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iCPU); + ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iCPU); + RunTillTransOnDevice aListener(_simComp, aSubject); + return simulate(oLastTrans); } bool Simulator::runToTaskTrans(TMLTask* iTask, TMLTransaction*& oLastTrans){ - //ListenerSubject<TaskListener>* aSubject= static_cast<ListenerSubject<TaskListener>* > (iTask); - ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iTask); - RunTillTransOnTask aListener(_simComp, aSubject); - return simulate(oLastTrans); + //ListenerSubject<TaskListener>* aSubject= static_cast<ListenerSubject<TaskListener>* > (iTask); + ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iTask); + RunTillTransOnTask aListener(_simComp, aSubject); + return simulate(oLastTrans); } bool Simulator::runToSlaveTrans(Slave* iSlave, TMLTransaction*& oLastTrans){ - //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iSlave); - ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iSlave); - RunTillTransOnDevice aListener(_simComp, aSubject); - return simulate(oLastTrans); + //ListenerSubject<TransactionListener>* aSubject= static_cast<ListenerSubject<TransactionListener>* > (iSlave); + ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iSlave); + RunTillTransOnDevice aListener(_simComp, aSubject); + return simulate(oLastTrans); } bool Simulator::runToChannelTrans(TMLChannel* iChannel, TMLTransaction*& oLastTrans){ - //ListenerSubject<ChannelListener>* aSubject= static_cast<ListenerSubject<ChannelListener>* > (iChannel); - ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iChannel); - RunTillTransOnChannel aListener(_simComp, aSubject); - return simulate(oLastTrans); + //ListenerSubject<ChannelListener>* aSubject= static_cast<ListenerSubject<ChannelListener>* > (iChannel); + ListenerSubject<GeneralListener>* aSubject= static_cast<ListenerSubject<GeneralListener>* > (iChannel); + RunTillTransOnChannel aListener(_simComp, aSubject); + return simulate(oLastTrans); } bool Simulator::runToNextRandomCommand(TMLTransaction*& oLastTrans){ - _randChoiceBreak.setEnabled(true); - //_randChoiceBreak->setEnabled(true); - bool aSimTerminated=simulate(oLastTrans); - _randChoiceBreak.setEnabled(false); - //_randChoiceBreak->setEnabled(false); - return aSimTerminated; + _randChoiceBreak.setEnabled(true); + //_randChoiceBreak->setEnabled(true); + bool aSimTerminated=simulate(oLastTrans); + _randChoiceBreak.setEnabled(false); + //_randChoiceBreak->setEnabled(false); + return aSimTerminated; } bool Simulator::runUntilCondition(std::string& iCond, TMLTask* iTask, TMLTransaction*& oLastTrans, bool& oSuccess){ - CondBreakpoint aListener(_simComp, iCond, iTask); - oSuccess=aListener.conditionValid(); - //return simulate(oLastTrans); - //aListener.commandEntered(0); - if (oSuccess) return simulate(oLastTrans); else return false; + CondBreakpoint aListener(_simComp, iCond, iTask); + oSuccess=aListener.conditionValid(); + //return simulate(oLastTrans); + //aListener.commandEntered(0); + if (oSuccess) return simulate(oLastTrans); else return false; } void Simulator::exploreTree(unsigned int iDepth, ID iPrevID, std::ofstream& iDOTFile, std::ofstream& iAUTFile, unsigned int& oTransCounter){ - TMLTransaction* aLastTrans; - //if (iDepth<RECUR_DEPTH){ - ID aLastID; - bool aSimTerminated=false; - IndeterminismSource* aRandomCmd; - do{ - aSimTerminated=runToNextRandomCommand(aLastTrans); - aRandomCmd = _simComp->getCurrentRandomCmd(); - }while (!aSimTerminated && aRandomCmd==0 && _simComp->wasKnownStateReached()==0); + TMLTransaction* aLastTrans; + //if (iDepth<RECUR_DEPTH){ + ID aLastID; + bool aSimTerminated=false; + IndeterminismSource* aRandomCmd; + do{ + aSimTerminated=runToNextRandomCommand(aLastTrans); + aRandomCmd = _simComp->getCurrentRandomCmd(); + }while (!aSimTerminated && aRandomCmd==0 && _simComp->wasKnownStateReached()==0); #ifdef EXPLOGRAPH_ENABLED - aLastID = schedule2GraphDOT(iDOTFile, iAUTFile, iPrevID,oTransCounter); + aLastID = schedule2GraphDOT(iDOTFile, iAUTFile, iPrevID,oTransCounter); #endif - if(aSimTerminated){ - oTransCounter++; -//#ifdef DOT_GRAPH_ENABLED - iDOTFile << aLastID << " -> " << TMLTransaction::getID() << " [label = \"i(allCPUsTerminated<" << SchedulableDevice::getSimulatedTime() << ">)\"]\n"; -//#else - //(21,"i(allCPUsTerminated)", 25) - iAUTFile << "(" << aLastID << "," << "\"i(allCPUsTerminated<" << SchedulableDevice::getSimulatedTime() << ">)\"," << TMLTransaction::getID() << ")\n"; -//#endif - TMLTransaction::incID(); - - if(_commandCoverage <= TMLCommand::getCmdCoverage() && _branchCoverage <= TMLCommand::getBranchCoverage()){ - _simComp->setStopFlag(true, MSG_COVREACHED); - _terminateExplore=true; - //_syncInfo->_terminate=true; - } - }else if (_simComp->wasKnownStateReached()==0){ - if(aRandomCmd==0){ - std::cout << "We should never get here\n"; - }else{ - unsigned int aNbNextCmds; - std::stringstream aStreamBuffer; - std::string aStringBuffer; - aNbNextCmds = aRandomCmd->getRandomRange(); - //std::cout << "Simulation " << iPrevID << "_" << aMyID << "continued " << aNbNextCmds << std::endl; - _simComp->writeObject(aStreamBuffer); - aStringBuffer=aStreamBuffer.str(); - if ((aNbNextCmds & INT_MSB)==0){ - //for (unsigned int aBranch=0; aBranch<aNbNextCmds && !_syncInfo->_terminate; aBranch++){ - for (unsigned int aBranch=0; aBranch<aNbNextCmds && !_terminateExplore; aBranch++){ - _simComp->reset(); - aStreamBuffer.str(aStringBuffer); - //std::cout << "Read 1 in exploreTree\n"; - _simComp->readObject(aStreamBuffer); - aRandomCmd->setRandomValue(aBranch); - exploreTree(iDepth+1, aLastID, iDOTFile, iAUTFile, oTransCounter); - } - }else{ - unsigned int aBranch=0; - aNbNextCmds ^= INT_MSB; - //while (aNbNextCmds!=0 && !_syncInfo->_terminate){ - while (aNbNextCmds!=0 && !_terminateExplore){ - if ((aNbNextCmds & 1)!=0){ - _simComp->reset(); - aStreamBuffer.str(aStringBuffer); - //std::cout << "Read 2 in exploreTree\n"; - _simComp->readObject(aStreamBuffer); - aRandomCmd->setRandomValue(aBranch); - exploreTree(iDepth+1, aLastID, iDOTFile, iAUTFile, oTransCounter); - } - aBranch++; aNbNextCmds >>=1; - } - } - } - //}else{ - //iFile << "Simulation " << iPrevID << "_" << aMyID << " encountered known state " << aCurrState << std::endl; - //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; - //iFile << aLastID << " -> " << aLastID << " [label = \"i\"]\n"; - - /*ID aNewID = TMLTransaction::getID(); - TMLTransaction::incID(); - iFile << aLastID << " -> " << aNewID << " [label = \"option\"]\n"; - std::stringstream aStreamBuffer; - std::string aStringBuffer; - _simComp->writeObject(aStreamBuffer); - aStringBuffer=aStreamBuffer.str(); - _simComp->reset(); - aStreamBuffer.str(aStringBuffer); - _simComp->readObject(aStreamBuffer);*/ - //exploreTree(iDepth, aNewID, iFile/*, iFile2*/); - } - //} + if(aSimTerminated){ + oTransCounter++; + //#ifdef DOT_GRAPH_ENABLED + iDOTFile << aLastID << " -> " << TMLTransaction::getID() << " [label = \"i(allCPUsTerminated<" << SchedulableDevice::getSimulatedTime() << ">)\"]\n"; + //#else + //(21,"i(allCPUsTerminated)", 25) + iAUTFile << "(" << aLastID << "," << "\"i(allCPUsTerminated<" << SchedulableDevice::getSimulatedTime() << ">)\"," << TMLTransaction::getID() << ")\n"; + //#endif + TMLTransaction::incID(); + + if(_commandCoverage <= TMLCommand::getCmdCoverage() && _branchCoverage <= TMLCommand::getBranchCoverage()){ + _simComp->setStopFlag(true, MSG_COVREACHED); + _terminateExplore=true; + //_syncInfo->_terminate=true; + } + }else if (_simComp->wasKnownStateReached()==0){ + if(aRandomCmd==0){ + std::cout << "We should never get here\n"; + }else{ + unsigned int aNbNextCmds; + std::stringstream aStreamBuffer; + std::string aStringBuffer; + aNbNextCmds = aRandomCmd->getRandomRange(); + //std::cout << "Simulation " << iPrevID << "_" << aMyID << "continued " << aNbNextCmds << std::endl; + _simComp->writeObject(aStreamBuffer); + aStringBuffer=aStreamBuffer.str(); + if ((aNbNextCmds & INT_MSB)==0){ + //for (unsigned int aBranch=0; aBranch<aNbNextCmds && !_syncInfo->_terminate; aBranch++){ + for (unsigned int aBranch=0; aBranch<aNbNextCmds && !_terminateExplore; aBranch++){ + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + //std::cout << "Read 1 in exploreTree\n"; + _simComp->readObject(aStreamBuffer); + aRandomCmd->setRandomValue(aBranch); + exploreTree(iDepth+1, aLastID, iDOTFile, iAUTFile, oTransCounter); + } + }else{ + unsigned int aBranch=0; + aNbNextCmds ^= INT_MSB; + //while (aNbNextCmds!=0 && !_syncInfo->_terminate){ + while (aNbNextCmds!=0 && !_terminateExplore){ + if ((aNbNextCmds & 1)!=0){ + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + //std::cout << "Read 2 in exploreTree\n"; + _simComp->readObject(aStreamBuffer); + aRandomCmd->setRandomValue(aBranch); + exploreTree(iDepth+1, aLastID, iDOTFile, iAUTFile, oTransCounter); + } + aBranch++; aNbNextCmds >>=1; + } + } + } + //}else{ + //iFile << "Simulation " << iPrevID << "_" << aMyID << " encountered known state " << aCurrState << std::endl; + //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; + //iFile << aLastID << " -> " << aLastID << " [label = \"i\"]\n"; + + /*ID aNewID = TMLTransaction::getID(); + TMLTransaction::incID(); + iFile << aLastID << " -> " << aNewID << " [label = \"option\"]\n"; + std::stringstream aStreamBuffer; + std::string aStringBuffer; + _simComp->writeObject(aStreamBuffer); + aStringBuffer=aStreamBuffer.str(); + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + _simComp->readObject(aStreamBuffer);*/ + //exploreTree(iDepth, aNewID, iFile/*, iFile2*/); + } + //} } bool Simulator::execAsyncCmd(const std::string& iCmd){ - unsigned int aCmd; - std::istringstream aInpStream(iCmd); - std::string aStrParam; - aInpStream >> aCmd; - std::ostringstream aMessage; - switch (aCmd){ - case 0: //Quit simulation - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulator terminated" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl << TAG_STATUSo << SIM_BUSY << TAG_STATUSc << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - _syncInfo->_server->sendReply(aMessage.str()); - _simComp->setStopFlag(true, MSG_SIMSTOPPED); - _syncInfo->_terminate=true; - return false; - case 13://get current time - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_TIMEo << SchedulableDevice::getSimulatedTime() << TAG_TIMEc << std::endl << TAG_MSGo << "Simulation time" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; - //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; - writeSimState(aMessage); - aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - _syncInfo->_server->sendReply(aMessage.str()); - break; - case 14:{//get actual command, thread safeness, be careful! - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl; - aInpStream >> aStrParam; - if (aStrParam=="all"){ - //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i !=_simComp->getTaskIterator(true); ++i){ - for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i !=_simComp->getTaskList().end(); ++i){ - printCommandsOfTask(*i, aMessage); - } - aMessage << TAG_GLOBALo << std::endl << TAG_MSGo << "Current command" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; - }else{ - TMLTask* aTask = _simComp->getTaskByName(aStrParam); - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl; - if (aTask!=0){ - printCommandsOfTask(aTask, aMessage); - aMessage << TAG_GLOBALo << std::endl << TAG_MSGo << "Current command" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; - }else{ - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << TAG_ERRNOo << 2; - } - } - //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; - writeSimState(aMessage); - aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - std::cout << aMessage.str(); - _syncInfo->_server->sendReply(aMessage.str()); - break; - } - case 15://pause simulation - _simComp->setStopFlag(true, MSG_SIMPAUSED); - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulation stopped" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; - writeSimState(aMessage); - aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - _syncInfo->_server->sendReply(aMessage.str()); - break; - default: - return false; - } - return true; + unsigned int aCmd; + std::istringstream aInpStream(iCmd); + std::string aStrParam; + aInpStream >> aCmd; + std::ostringstream aMessage; + switch (aCmd){ + case 0: //Quit simulation + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulator terminated" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl << TAG_STATUSo << SIM_BUSY << TAG_STATUSc << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + _syncInfo->_server->sendReply(aMessage.str()); + _simComp->setStopFlag(true, MSG_SIMSTOPPED); + _syncInfo->_terminate=true; + return false; + case 13://get current time + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_TIMEo << SchedulableDevice::getSimulatedTime() << TAG_TIMEc << std::endl << TAG_MSGo << "Simulation time" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; + //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; + writeSimState(aMessage); + aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + _syncInfo->_server->sendReply(aMessage.str()); + break; + case 14:{//get actual command, thread safeness, be careful! + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl; + aInpStream >> aStrParam; + if (aStrParam=="all"){ + //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i !=_simComp->getTaskIterator(true); ++i){ + for(TaskList::const_iterator i=_simComp->getTaskList().begin(); i !=_simComp->getTaskList().end(); ++i){ + printCommandsOfTask(*i, aMessage); + } + aMessage << TAG_GLOBALo << std::endl << TAG_MSGo << "Current command" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; + }else{ + TMLTask* aTask = _simComp->getTaskByName(aStrParam); + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl; + if (aTask!=0){ + printCommandsOfTask(aTask, aMessage); + aMessage << TAG_GLOBALo << std::endl << TAG_MSGo << "Current command" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; + }else{ + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << TAG_ERRNOo << 2; + } + } + //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; + writeSimState(aMessage); + aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + std::cout << aMessage.str(); + _syncInfo->_server->sendReply(aMessage.str()); + break; + } + case 15://pause simulation + _simComp->setStopFlag(true, MSG_SIMPAUSED); + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulation stopped" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; + writeSimState(aMessage); + aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + _syncInfo->_server->sendReply(aMessage.str()); + break; + default: + return false; + } + return true; } void Simulator::printCommandsOfTask(TMLTask* iTask, std::ostream& ioMessage){ - ioMessage << TAG_TASKo << " id=\"" << iTask-> getID() << "\" name=\"" << iTask->toString() << "\">" << TAG_CURRCMDo << " id=\""; - TMLCommand* currCommand=iTask->getCurrCommand(); - //if (iTask->getCurrCommand()==0) - if (currCommand==0){ - ioMessage << 0 << "\">"; - }else{ - ioMessage << currCommand->getID() << "\">" << TAG_PROGRESSo << currCommand->getProgressInPercent() << TAG_PROGRESSc; - ioMessage << TAG_STARTTIMEo << currCommand->getCommandStartTime() << TAG_STARTTIMEc; - TMLTransaction* currTrans = currCommand->getCurrTransaction(); - if (currTrans==0 || currTrans->getOverallLength()==0 || currTrans->getVirtualLength()==0){ - ioMessage << TAG_FINISHTIMEo << "-1" << TAG_FINISHTIMEc; - ioMessage << TAG_FINISHTIMETRANSo << "-1" << TAG_FINISHTIMETRANSc; - ioMessage << TAG_STARTTIMETRANSo << "-1" << TAG_STARTTIMETRANSc; - }else{ - ioMessage << TAG_FINISHTIMEo << (currTrans->getEndTime() + currTrans->getOverallLength()*(currCommand->getLength()-currCommand->getProgress()-currTrans->getVirtualLength())/currTrans->getVirtualLength()) << TAG_FINISHTIMEc; - //if (currCommand->getLength()==currCommand->getProgress()) - //ioMessage << TAG_STARTTIMETRANSo << "99" << TAG_STARTTIMETRANSc; - //else - ioMessage << TAG_STARTTIMETRANSo << currTrans->getStartTime() << TAG_STARTTIMETRANSc; - ioMessage << TAG_FINISHTIMETRANSo << currTrans->getEndTime() << TAG_FINISHTIMETRANSc; - } - unsigned int aNbNextCmds; - TMLCommand** aNextCmds = currCommand->getNextCommands(aNbNextCmds); - for(unsigned int i=0; i<aNbNextCmds; i++){ - ioMessage << TAG_NEXTCMDo << aNextCmds[i]->getID() << TAG_NEXTCMDc; - } - } - ioMessage << TAG_CURRCMDc << TAG_TASKc << std::endl; + ioMessage << TAG_TASKo << " id=\"" << iTask-> getID() << "\" name=\"" << iTask->toString() << "\">" << TAG_CURRCMDo << " id=\""; + TMLCommand* currCommand=iTask->getCurrCommand(); + //if (iTask->getCurrCommand()==0) + if (currCommand==0){ + ioMessage << 0 << "\">"; + }else{ + ioMessage << currCommand->getID() << "\">" << TAG_PROGRESSo << currCommand->getProgressInPercent() << TAG_PROGRESSc; + ioMessage << TAG_STARTTIMEo << currCommand->getCommandStartTime() << TAG_STARTTIMEc; + TMLTransaction* currTrans = currCommand->getCurrTransaction(); + if (currTrans==0 || currTrans->getOverallLength()==0 || currTrans->getVirtualLength()==0){ + ioMessage << TAG_FINISHTIMEo << "-1" << TAG_FINISHTIMEc; + ioMessage << TAG_FINISHTIMETRANSo << "-1" << TAG_FINISHTIMETRANSc; + ioMessage << TAG_STARTTIMETRANSo << "-1" << TAG_STARTTIMETRANSc; + }else{ + ioMessage << TAG_FINISHTIMEo << (currTrans->getEndTime() + currTrans->getOverallLength()*(currCommand->getLength()-currCommand->getProgress()-currTrans->getVirtualLength())/currTrans->getVirtualLength()) << TAG_FINISHTIMEc; + //if (currCommand->getLength()==currCommand->getProgress()) + //ioMessage << TAG_STARTTIMETRANSo << "99" << TAG_STARTTIMETRANSc; + //else + ioMessage << TAG_STARTTIMETRANSo << currTrans->getStartTime() << TAG_STARTTIMETRANSc; + ioMessage << TAG_FINISHTIMETRANSo << currTrans->getEndTime() << TAG_FINISHTIMETRANSc; + } + unsigned int aNbNextCmds; + TMLCommand** aNextCmds = currCommand->getNextCommands(aNbNextCmds); + for(unsigned int i=0; i<aNbNextCmds; i++){ + ioMessage << TAG_NEXTCMDo << aNextCmds[i]->getID() << TAG_NEXTCMDc; + } + } + ioMessage << TAG_CURRCMDc << TAG_TASKc << std::endl; } void Simulator::sendStatus(){ - std::ostringstream aMessage; - aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulator status notification" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; - //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; - writeSimState(aMessage); - aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; - _syncInfo->_server->sendReply(aMessage.str()); + std::ostringstream aMessage; + aMessage << TAG_HEADER << std::endl << TAG_STARTo << std::endl << TAG_GLOBALo << std::endl << TAG_MSGo << "Simulator status notification" << TAG_MSGc << TAG_ERRNOo << 0 << TAG_ERRNOc << std::endl; + //if (_busy) aMessage << SIM_BUSY; else aMessage << SIM_READY; + writeSimState(aMessage); + aMessage << std::endl << TAG_GLOBALc << std::endl << TAG_STARTc << std::endl; + _syncInfo->_server->sendReply(aMessage.str()); } bool Simulator::isBusy(){ - return _busy; + return _busy; } void Simulator::writeSimState(std::ostream& ioMessage){ - ioMessage << TAG_STATUSo; - if (_busy){ - ioMessage << SIM_BUSY << TAG_STATUSc; - }else{ - if (_simTerm){ - ioMessage << SIM_TERM << TAG_STATUSc << TAG_REASONo << MSG_SIMENDED << TAG_REASONc; - }else{ - ioMessage << SIM_READY << TAG_STATUSc; - if (_simComp->getStopReason()!="") ioMessage << TAG_REASONo << _simComp->getStopReason() << TAG_REASONc; - } - } + ioMessage << TAG_STATUSo; + if (_busy){ + ioMessage << SIM_BUSY << TAG_STATUSc; + }else{ + if (_simTerm){ + ioMessage << SIM_TERM << TAG_STATUSc << TAG_REASONo << MSG_SIMENDED << TAG_REASONc; + }else{ + ioMessage << SIM_READY << TAG_STATUSc; + if (_simComp->getStopReason()!="") ioMessage << TAG_REASONo << _simComp->getStopReason() << TAG_REASONc; + } + } } diff --git a/simulators/c++2/src_simulator/sim/Simulator.h b/simulators/c++2/src_simulator/sim/Simulator.h index 7f7e1d92c6..d9dfb42c07 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.h +++ b/simulators/c++2/src_simulator/sim/Simulator.h @@ -244,7 +244,7 @@ public: /** \param glob Stream on which the XML answer shall be send to */ - void allTrans2XML(std::ostringstream& glob) const; + void allTrans2XML(std::ostringstream& glob, int maxNbOfTrans) const; ///Is true if the simulator is busy diff --git a/src/remotesimulation/CommandParser.java b/src/remotesimulation/CommandParser.java index 4e2e18f353..34ddae4618 100755 --- a/src/remotesimulation/CommandParser.java +++ b/src/remotesimulation/CommandParser.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -* -* ludovic.apvrille AT enst.fr -* -* This software is a computer program whose purpose is to allow the -* edition of TURTLE analysis, design and deployment diagrams, to -* allow the generation of RT-LOTOS or Java code from this diagram, -* and at last to allow the analysis of formal validation traces -* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -* from INRIA Rhone-Alpes. -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited -* liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* /** -* Class CommandParser -* For managing commands the C++ simulator -* Creation: 16/04/2009 -* @version 1.1 16/04/2009 -* @author Ludovic APVRILLE -* @see -*/ + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + * /** + * Class CommandParser + * For managing commands the C++ simulator + * Creation: 16/04/2009 + * @version 1.1 16/04/2009 + * @author Ludovic APVRILLE + * @see + */ package remotesimulation; @@ -54,426 +54,437 @@ import java.util.*; public class CommandParser { ArrayList<SimulationCommand> commandList; - - public CommandParser() { - commandList = new ArrayList<SimulationCommand>(); - fillCommandList(); - } - - public boolean isCommand(String cmd, String id) { - String s = cmd.trim(); - if (cmd.equals(id)) { - return true; - } - return s.startsWith(id + " "); - } - - public boolean isHelpCommand(String cmd) { - return isCommand(cmd, "help"); - } - - // Returns the command name for which help is required - public String getHelpWithCommand(String cmd) { - if (!isCommand(cmd, "help")) { - return null; - } - - String tmp = cmd.trim(); - - if (!(tmp.startsWith("help "))) { - return null; - } - - tmp = tmp.substring(5, tmp.length()).trim(); - - if (tmp.length() == 0) { - return null; - } - - return tmp; - - - } - - public String getHelp(String cmd) { - //System.out.println("calculating help on cmd"); - StringBuffer sb = new StringBuffer(""); - boolean commandFound = false; - int i; - - for(SimulationCommand sc: commandList) { - if (sc.userCommand.equals(cmd) || sc.alias.equals(cmd)) { - sb.append(sc.getSynopsis() + "\n" + sc.help + "\n"); - if (sc.hasAlias()) { - sb.append("alias: " + sc.alias + "\n"); - } - sb.append("code: " + sc.simulatorCommand); - //System.out.println("Command found" + sc.help); - commandFound = true; - } - } - if (commandFound) { - return sb.toString(); - } else { - return "Command not found"; - } - } - - public boolean isQuitCommand(String cmd) { - return isCommand(cmd, "quit"); - } - - public boolean isPicoCommand(String cmd) { - return isCommand(cmd, "pico"); - } - - public boolean isListCommand(String cmd) { - return isCommand(cmd, "list"); - } - - public int isAValidCommand(String cmd) { - int index = -1; - int cpt = 0; - - String cmds[] = cmd.split(" "); - //System.out.println("cmd " + cmd + " has " + cmds.length + " elements"); - - for(SimulationCommand sc: commandList) { - // Same command name? - if (sc.userCommand.equals(cmds[0]) || sc.alias.equals(cmds[0])) { - // Compatible arguments? - if (sc.areParametersCompatible(cmds)) { - index = cpt; - break; - } else { - index = -2; - } - } - cpt ++; - } - - if (index < 0) { - return index; - } - - return index; - } - - public String transformCommandFromUserToSimulator(String cmd) { - int index = isAValidCommand(cmd); - if (index < 0) { - return ""; - } - - SimulationCommand sc = commandList.get(index); - - return sc.translateCommand(cmd.split(" ")); - } - - // Returns the list of all commands - public String getCommandList() { - int cpt = 0; - StringBuffer sb = new StringBuffer(""); - for(SimulationCommand sc: commandList) { - if (cpt == 1) { - cpt = 0; - sb.append("\n"); - } - if (sc.userCommand.equals(sc.alias)) { - sb.append(sc.userCommand + " "); - } else { - sb.append(sc.userCommand + "/" + sc.alias + " "); - } - cpt ++; - } - return sb.toString(); - } - - - // Fill two arrays with information about commands - private void fillCommandList() { - SimulationCommand sc; - int[] params; - String[] paramNames; - int i; - - // active-breakpoints - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "0/1 (unactive / active)"; - sc = new SimulationCommand("active-breakpoints", "ab", "20", params, paramNames, "Active / unactive breakpoints"); - commandList.add(sc); - - // add-breakpoint - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "task ID"; - params[1] = 0; - paramNames[1] = "comamnd ID"; - sc = new SimulationCommand("add-breakpoint", "abp", "11", params, paramNames, "Set a breakpoint in task which id is the first parameter on the command provided as the second parameter"); - commandList.add(sc); - - // choose-branh - params = new int[3]; - paramNames = new String[3]; - params[0] = 1; - paramNames[0] = "task ID"; - params[1] = 0; - paramNames[1] = "command ID"; - params[2] = 0; - paramNames[2] = "branch ID"; - sc = new SimulationCommand("choose-branch", "cb", "12", params, paramNames, "Chooses the branch of the given command of a task"); - commandList.add(sc); - - - // get-breakpoint-list - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-breakpoint-list", "gbl", "18", params, paramNames, "Returns the list of breakpoints currently set"); - commandList.add(sc); - - // get-command-and-task - params = new int[1]; - paramNames = new String[1]; - params[0] = 0; - paramNames[0] = "Task id (or \"all\")"; - sc = new SimulationCommand("get-command-of-task", "gcot", "14", params, paramNames, "Returns the current command of the task provided as argument"); - commandList.add(sc); - - // get-benchmark - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "0: show benchmark; 1:save in file"; - params[1] = 0; - paramNames[1] = "Name of file"; - sc = new SimulationCommand("get-benchmark", "gb", "10", params, paramNames, "Returns information on hardware nodes of the architecture"); - commandList.add(sc); - - // get-executed-operators - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-executed-operators", "geo", "21", params, paramNames, "Returns the list of executed operators"); - commandList.add(sc); - - // get-hash-code - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-hashcode", "gh", "19", params, paramNames, "Returns the hashcode of the tmap under simulation"); - commandList.add(sc); - - // get-info-on-hw - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "0: CPU; 1:Bus; 2: Mem; 3: Bridge; 4: Channel"; - params[1] = 1; - paramNames[1] = "id"; - sc = new SimulationCommand("get-info-on-hw", "gioh", "4", params, paramNames, "Returns information on hardware nodes of the architecture"); - commandList.add(sc); - - // get-number-of-branches - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-numer-of-branches", "gnob", "17", params, paramNames, "Returns the number of branches the current command has"); - commandList.add(sc); - - // get-simulation-time - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("get-simulation-time", "time", "13", params, paramNames, "Returns the current absolute time unit of the simulation"); - commandList.add(sc); - - // get-variable-of-task - params = new int[2]; - paramNames = new String[2]; - params[0] = 0; - paramNames[0] = "Task id"; - params[1] = 0; - paramNames[1] = "Variable id"; - sc = new SimulationCommand("get-variable-of-task", "gvof", "3", params, paramNames, "Returns the value of a variable a a task"); - commandList.add(sc); - - // kill - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("kill", "kill", "0", params, paramNames, "Terminates the remote simulator"); - commandList.add(sc); - - // rm-breakpoint - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "task ID"; - params[1] = 0; - paramNames[1] = "comamnd ID"; - sc = new SimulationCommand("rm-breakpoint", "abp", "16", params, paramNames, "Remove a breakpoint in task which id is the first parameter on the command provided as the second parameter"); - commandList.add(sc); - - // reset - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("reset", "reset", "2", params, paramNames, "Resets the remote simulator"); - commandList.add(sc); - - // rawcmd - params = new int[5]; - paramNames = new String[5]; - for(i=0; i<5; i++) { - params[i] = 4; - paramNames[i] = "param #" + i; - } - sc = new SimulationCommand("raw-command", "rc", "", params, paramNames, "Sends a raw command to the remote simulator"); - commandList.add(sc); - - // restore-simulation-state-from-file - params = new int[1]; - paramNames = new String[1]; - params[0] = 2; - paramNames[0] = "File name"; - sc = new SimulationCommandSaveState("restore-simulation-state-from-file", "rssff", "9", params, paramNames, "Restores the simulation state from a file"); - commandList.add(sc); - - // run-exploration - params = new int[2]; - paramNames = new String[2]; - params[0] = 6; - params[1] = 6; - paramNames[0] = "Minimum number of explored commands"; - paramNames[1] = "Minimum number of explored branches"; - sc = new SimulationCommand("run-exploration", "re", "1 7", params, paramNames, "Runs the simulation in exploration mode"); - commandList.add(sc); - - // run-to-next-breakpoint - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("run-to-next-breakpoint", "rtnb", "1 0", params, paramNames, "Runs the simulation until a breakpoint is met"); - commandList.add(sc); - - // run-to-next-transfer-on-bus - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "bus id"; - sc = new SimulationCommand("run-to-next-transfer-on-bus", "rtntob", "1 8", params, paramNames, "Runs to the next transfer on bus which id is provided as argument"); - commandList.add(sc); - - // run-to-time - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "x: time value"; - sc = new SimulationCommand("run-to-time", "rtt", "1 5", params, paramNames, "Runs the simulation until time x is reached"); - commandList.add(sc); - - // run-until-channel-access - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "Channel id"; - sc = new SimulationCommand("run-until-channel-access", "ruca", "1 12", params, paramNames, "Run simulation until a operation is performed on the channel which ID is provided as parameter"); - commandList.add(sc); - - // run-until-cpu-executes - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "CPU id"; - sc = new SimulationCommand("run-until-cpu-executes", "ruce", "1 9", params, paramNames, "Run simulation until CPU which ID is provided as parameter executes"); - commandList.add(sc); - - // run-until-memory-access - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "Memory id"; - sc = new SimulationCommand("run-until-memory-access", "ruma", "1 11", params, paramNames, "Run simulation until the memory which ID is provided as parameter is accessed"); - commandList.add(sc); - - // run-until-task-executes - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "Task id"; - sc = new SimulationCommand("run-until-task-executes", "rute", "1 10", params, paramNames, "Run simulation until the task which ID is provided as parameter executes"); - commandList.add(sc); - - // run-x-commands - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "nb of commands"; - sc = new SimulationCommand("run-x-commands", "rxcomm", "1 4", params, paramNames, "Runs the simulation for x commands"); - commandList.add(sc); - - // run-x-time-units - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "nb of time units"; - sc = new SimulationCommand("run-x-time-units", "rxtu", "1 6", params, paramNames, "Runs the simulation for x units of time"); - commandList.add(sc); - - // run-x-transactions - params = new int[1]; - paramNames = new String[1]; - params[0] = 1; - paramNames[0] = "nb of transactions"; - sc = new SimulationCommand("run-x-transactions", "rxtr", "1 2", params, paramNames, "Runs the simulation for x transactions"); - commandList.add(sc); - - // save-simulation-state-in-file - params = new int[1]; - paramNames = new String[1]; - params[0] = 2; - paramNames[0] = "File name"; - sc = new SimulationCommandSaveState("save-simulation-state-in-file", "sssif", "8", params, paramNames, "Saves the current simulation state into a file"); - commandList.add(sc); - - // save-trace-in-file - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "File format: 0-> VCD, 1->HTML, 2->TXT"; - params[1] = 2; - paramNames[1] = "File name"; - sc = new SimulationCommand("save-trace-in-file", "stif", "7", params, paramNames, "Saves the current trace of the simulation in a VCD, HTML or TXT file"); - commandList.add(sc); - - // set-variable - params = new int[3]; - paramNames = new String[3]; - params[0] = 1; - paramNames[0] = "task ID"; - params[1] = 1; - paramNames[1] = "variable ID"; - params[2] = 1; - paramNames[2] = "variable value"; - sc = new SimulationCommand("set-variable", "sv", "5", params, paramNames, "Set the value of a variable"); - commandList.add(sc); - - // stop - params = new int[0]; - paramNames = new String[0]; - sc = new SimulationCommand("stop", "stop", "15", params, paramNames, "Stops the currently running simulation"); - commandList.add(sc); - - // write-in-channel - params = new int[2]; - paramNames = new String[2]; - params[0] = 1; - paramNames[0] = "Channel ID"; - params[1] = 2; - paramNames[1] = "Nb of samples"; - sc = new SimulationCommand("write-in-channel", "wic", "6", params, paramNames, "Writes y samples / events to channel / event x"); - commandList.add(sc); - } - - - - - + + public CommandParser() { + commandList = new ArrayList<SimulationCommand>(); + fillCommandList(); + } + + public boolean isCommand(String cmd, String id) { + String s = cmd.trim(); + if (cmd.equals(id)) { + return true; + } + return s.startsWith(id + " "); + } + + public boolean isHelpCommand(String cmd) { + return isCommand(cmd, "help"); + } + + // Returns the command name for which help is required + public String getHelpWithCommand(String cmd) { + if (!isCommand(cmd, "help")) { + return null; + } + + String tmp = cmd.trim(); + + if (!(tmp.startsWith("help "))) { + return null; + } + + tmp = tmp.substring(5, tmp.length()).trim(); + + if (tmp.length() == 0) { + return null; + } + + return tmp; + + + } + + public String getHelp(String cmd) { + //System.out.println("calculating help on cmd"); + StringBuffer sb = new StringBuffer(""); + boolean commandFound = false; + int i; + + for(SimulationCommand sc: commandList) { + if (sc.userCommand.equals(cmd) || sc.alias.equals(cmd)) { + sb.append(sc.getSynopsis() + "\n" + sc.help + "\n"); + if (sc.hasAlias()) { + sb.append("alias: " + sc.alias + "\n"); + } + sb.append("code: " + sc.simulatorCommand); + //System.out.println("Command found" + sc.help); + commandFound = true; + } + } + if (commandFound) { + return sb.toString(); + } else { + return "Command not found"; + } + } + + public boolean isQuitCommand(String cmd) { + return isCommand(cmd, "quit"); + } + + public boolean isPicoCommand(String cmd) { + return isCommand(cmd, "pico"); + } + + public boolean isListCommand(String cmd) { + return isCommand(cmd, "list"); + } + + public int isAValidCommand(String cmd) { + int index = -1; + int cpt = 0; + + String cmds[] = cmd.split(" "); + //System.out.println("cmd " + cmd + " has " + cmds.length + " elements"); + + for(SimulationCommand sc: commandList) { + // Same command name? + if (sc.userCommand.equals(cmds[0]) || sc.alias.equals(cmds[0])) { + // Compatible arguments? + if (sc.areParametersCompatible(cmds)) { + index = cpt; + break; + } else { + index = -2; + } + } + cpt ++; + } + + if (index < 0) { + return index; + } + + return index; + } + + public String transformCommandFromUserToSimulator(String cmd) { + int index = isAValidCommand(cmd); + if (index < 0) { + return ""; + } + + SimulationCommand sc = commandList.get(index); + + return sc.translateCommand(cmd.split(" ")); + } + + // Returns the list of all commands + public String getCommandList() { + int cpt = 0; + StringBuffer sb = new StringBuffer(""); + for(SimulationCommand sc: commandList) { + if (cpt == 1) { + cpt = 0; + sb.append("\n"); + } + if (sc.userCommand.equals(sc.alias)) { + sb.append(sc.userCommand + " "); + } else { + sb.append(sc.userCommand + "/" + sc.alias + " "); + } + cpt ++; + } + return sb.toString(); + } + + + // Fill two arrays with information about commands + private void fillCommandList() { + SimulationCommand sc; + int[] params; + String[] paramNames; + int i; + + // active-breakpoints + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "0/1 (unactive / active)"; + sc = new SimulationCommand("active-breakpoints", "ab", "20", params, paramNames, "Active / unactive breakpoints"); + commandList.add(sc); + + // add-breakpoint + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "task ID"; + params[1] = 0; + paramNames[1] = "comamnd ID"; + sc = new SimulationCommand("add-breakpoint", "abp", "11", params, paramNames, "Set a breakpoint in task which id is the first parameter on the command provided as the second parameter"); + commandList.add(sc); + + // choose-branh + params = new int[3]; + paramNames = new String[3]; + params[0] = 1; + paramNames[0] = "task ID"; + params[1] = 0; + paramNames[1] = "command ID"; + params[2] = 0; + paramNames[2] = "branch ID"; + sc = new SimulationCommand("choose-branch", "cb", "12", params, paramNames, "Chooses the branch of the given command of a task"); + commandList.add(sc); + + + // get-breakpoint-list + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("get-breakpoint-list", "gbl", "18", params, paramNames, "Returns the list of breakpoints currently set"); + commandList.add(sc); + + // get-command-and-task + params = new int[1]; + paramNames = new String[1]; + params[0] = 0; + paramNames[0] = "Task id (or \"all\")"; + sc = new SimulationCommand("get-command-of-task", "gcot", "14", params, paramNames, "Returns the current command of the task provided as argument"); + commandList.add(sc); + + // get-benchmark + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "0: show benchmark; 1:save in file"; + params[1] = 0; + paramNames[1] = "Name of file"; + sc = new SimulationCommand("get-benchmark", "gb", "10", params, paramNames, "Returns information on hardware nodes of the architecture"); + commandList.add(sc); + + // get-executed-operators + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("get-executed-operators", "geo", "21", params, paramNames, "Returns the list of executed operators"); + commandList.add(sc); + + // get-hash-code + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("get-hashcode", "gh", "19", params, paramNames, "Returns the hashcode of the tmap under simulation"); + commandList.add(sc); + + // get-info-on-hw + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "0: CPU; 1:Bus; 2: Mem; 3: Bridge; 4: Channel"; + params[1] = 1; + paramNames[1] = "id"; + sc = new SimulationCommand("get-info-on-hw", "gioh", "4", params, paramNames, "Returns information on hardware nodes of the architecture"); + commandList.add(sc); + + // get-number-of-branches + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("get-numer-of-branches", "gnob", "17", params, paramNames, "Returns the number of branches the current command has"); + commandList.add(sc); + + // get-simulation-time + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("get-simulation-time", "time", "13", params, paramNames, "Returns the current absolute time unit of the simulation"); + commandList.add(sc); + + // get-variable-of-task + params = new int[2]; + paramNames = new String[2]; + params[0] = 0; + paramNames[0] = "Task id"; + params[1] = 0; + paramNames[1] = "Variable id"; + sc = new SimulationCommand("get-variable-of-task", "gvof", "3", params, paramNames, "Returns the value of a variable a a task"); + commandList.add(sc); + + // kill + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("kill", "kill", "0", params, paramNames, "Terminates the remote simulator"); + commandList.add(sc); + + // rm-breakpoint + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "task ID"; + params[1] = 0; + paramNames[1] = "comamnd ID"; + sc = new SimulationCommand("rm-breakpoint", "abp", "16", params, paramNames, "Remove a breakpoint in task which id is the first parameter on the command provided as the second parameter"); + commandList.add(sc); + + // reset + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("reset", "reset", "2", params, paramNames, "Resets the remote simulator"); + commandList.add(sc); + + // rawcmd + params = new int[5]; + paramNames = new String[5]; + for(i=0; i<5; i++) { + params[i] = 4; + paramNames[i] = "param #" + i; + } + sc = new SimulationCommand("raw-command", "rc", "", params, paramNames, "Sends a raw command to the remote simulator"); + commandList.add(sc); + + // restore-simulation-state-from-file + params = new int[1]; + paramNames = new String[1]; + params[0] = 2; + paramNames[0] = "File name"; + sc = new SimulationCommandSaveState("restore-simulation-state-from-file", "rssff", "9", params, paramNames, "Restores the simulation state from a file"); + commandList.add(sc); + + // run-exploration + params = new int[2]; + paramNames = new String[2]; + params[0] = 6; + params[1] = 6; + paramNames[0] = "Minimum number of explored commands"; + paramNames[1] = "Minimum number of explored branches"; + sc = new SimulationCommand("run-exploration", "re", "1 7", params, paramNames, "Runs the simulation in exploration mode"); + commandList.add(sc); + + // run-to-next-breakpoint + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("run-to-next-breakpoint", "rtnb", "1 0", params, paramNames, "Runs the simulation until a breakpoint is met"); + commandList.add(sc); + + // run-to-next-transfer-on-bus + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "bus id"; + sc = new SimulationCommand("run-to-next-transfer-on-bus", "rtntob", "1 8", params, paramNames, "Runs to the next transfer on bus which id is provided as argument"); + commandList.add(sc); + + // run-to-time + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "x: time value"; + sc = new SimulationCommand("run-to-time", "rtt", "1 5", params, paramNames, "Runs the simulation until time x is reached"); + commandList.add(sc); + + // run-until-channel-access + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "Channel id"; + sc = new SimulationCommand("run-until-channel-access", "ruca", "1 12", params, paramNames, "Run simulation until a operation is performed on the channel which ID is provided as parameter"); + commandList.add(sc); + + // run-until-cpu-executes + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "CPU id"; + sc = new SimulationCommand("run-until-cpu-executes", "ruce", "1 9", params, paramNames, "Run simulation until CPU which ID is provided as parameter executes"); + commandList.add(sc); + + // run-until-memory-access + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "Memory id"; + sc = new SimulationCommand("run-until-memory-access", "ruma", "1 11", params, paramNames, "Run simulation until the memory which ID is provided as parameter is accessed"); + commandList.add(sc); + + // run-until-task-executes + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "Task id"; + sc = new SimulationCommand("run-until-task-executes", "rute", "1 10", params, paramNames, "Run simulation until the task which ID is provided as parameter executes"); + commandList.add(sc); + + // run-x-commands + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "nb of commands"; + sc = new SimulationCommand("run-x-commands", "rxcomm", "1 4", params, paramNames, "Runs the simulation for x commands"); + commandList.add(sc); + + // run-x-time-units + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "nb of time units"; + sc = new SimulationCommand("run-x-time-units", "rxtu", "1 6", params, paramNames, "Runs the simulation for x units of time"); + commandList.add(sc); + + // run-x-transactions + params = new int[1]; + paramNames = new String[1]; + params[0] = 1; + paramNames[0] = "nb of transactions"; + sc = new SimulationCommand("run-x-transactions", "rxtr", "1 2", params, paramNames, "Runs the simulation for x transactions"); + commandList.add(sc); + + // save-simulation-state-in-file + params = new int[1]; + paramNames = new String[1]; + params[0] = 2; + paramNames[0] = "File name"; + sc = new SimulationCommandSaveState("save-simulation-state-in-file", "sssif", "8", params, paramNames, "Saves the current simulation state into a file"); + commandList.add(sc); + + // save-trace-in-file + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "File format: 0-> VCD, 1->HTML, 2->TXT"; + params[1] = 2; + paramNames[1] = "File name"; + sc = new SimulationCommand("save-trace-in-file", "stif", "7", params, paramNames, "Saves the current trace of the simulation in a VCD, HTML or TXT file"); + commandList.add(sc); + + // set-variable + params = new int[3]; + paramNames = new String[3]; + params[0] = 1; + paramNames[0] = "task ID"; + params[1] = 1; + paramNames[1] = "variable ID"; + params[2] = 1; + paramNames[2] = "variable value"; + sc = new SimulationCommand("set-variable", "sv", "5", params, paramNames, "Set the value of a variable"); + commandList.add(sc); + + // stop + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("stop", "stop", "15", params, paramNames, "Stops the currently running simulation"); + commandList.add(sc); + + // write-in-channel + params = new int[2]; + paramNames = new String[2]; + params[0] = 1; + paramNames[0] = "Channel ID"; + params[1] = 2; + paramNames[1] = "Nb of samples"; + sc = new SimulationCommand("write-in-channel", "wic", "6", params, paramNames, "Writes y samples / events to channel / event x"); + commandList.add(sc); + + + // Get transactions + params = new int[1]; + paramNames = new String[1]; + params[0] = 2; + paramNames[0] = "Max. nb of transactions"; + sc = new SimulationCommand("list-transactions", "lt", "22", params, paramNames, "Get the most recent transactions"); + commandList.add(sc); + } + -} \ No newline at end of file + + + + + + +} diff --git a/src/remotesimulation/RemoteConnection.java b/src/remotesimulation/RemoteConnection.java index 6c0462bf06..9ec2856b4d 100755 --- a/src/remotesimulation/RemoteConnection.java +++ b/src/remotesimulation/RemoteConnection.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -* -* ludovic.apvrille AT enst.fr -* -* This software is a computer program whose purpose is to allow the -* edition of TURTLE analysis, design and deployment diagrams, to -* allow the generation of RT-LOTOS or Java code from this diagram, -* and at last to allow the analysis of formal validation traces -* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -* from INRIA Rhone-Alpes. -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited -* liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* /** -* Class RemoteConnection -* For remote control of the simulator -* Creation: 16/04/2009 -* @version 1.1 16/04/2009 -* @author Ludovic APVRILLE -* @see -*/ + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + * /** + * Class RemoteConnection + * For remote control of the simulator + * Creation: 16/04/2009 + * @version 1.1 16/04/2009 + * @author Ludovic APVRILLE + * @see + */ package remotesimulation; @@ -52,12 +52,12 @@ import javax.swing.*; public class RemoteConnection { - + private static String NO_HOST = "Application has no execution host"; private static String INET = "Bad internet address for host "; private static String SERV_NOT_RESP = "Server not responding on "; private static String IO_ERROR = "Communication pb with server "; - + private String host; //private String cmd; private static int port = 3490; @@ -68,39 +68,39 @@ public class RemoteConnection { //private DataInputStream in2; private PrintStream out; //private int offset = 0; - + private boolean go; - + public RemoteConnection(String _host, int _port) { host = _host; - port = _port; + port = _port; } - - public RemoteConnection(String _host) { + + public RemoteConnection(String _host) { host = _host; } - - public void connect() throws RemoteConnectionException { + + public void connect() throws RemoteConnectionException { InetAddress ina = null; - + //System.out.println("Connecting on port " + portNet); - + if (host == null) { throw new RemoteConnectionException(NO_HOST); } - + try { ina = InetAddress.getByName(host); } catch (UnknownHostException e) { throw new RemoteConnectionException(INET + host); } - + try { clientSocket = new Socket(ina, port); } catch (IOException io) { throw new RemoteConnectionException(SERV_NOT_RESP+host); } - + try { in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); //in2 = new DataInputStream(clientSocket.getInputStream()); @@ -110,20 +110,22 @@ public class RemoteConnection { throw new RemoteConnectionException(SERV_NOT_RESP+host); } } - - public void disconnect() throws RemoteConnectionException { - try { - clientSocket.close(); - } catch (IOException io) { + + public void disconnect() throws RemoteConnectionException { + try { + clientSocket.close(); + } catch (IOException io) { throw new RemoteConnectionException(IO_ERROR + host); - } + } catch (NullPointerException npe) { + throw new RemoteConnectionException(SERV_NOT_RESP + host); } - - public void send(String s) throws RemoteConnectionException { - s = s .trim() + " \n"; - if (s.length() == 0) { - return; - } + } + + public void send(String s) throws RemoteConnectionException { + s = s .trim() + " \n"; + if (s.length() == 0) { + return; + } //System.out.println("Sending: " + s); try { out.print(s); @@ -132,8 +134,8 @@ public class RemoteConnection { throw new RemoteConnectionException(IO_ERROR); } } - - public String readOneLine() throws RemoteConnectionException { + + public String readOneLine() throws RemoteConnectionException { int nb; String s = null; try { @@ -141,16 +143,16 @@ public class RemoteConnection { } catch(IOException io) { throw new RemoteConnectionException(IO_ERROR); } - - if (s == null) { - throw new RemoteConnectionException(IO_ERROR); - } - - if (s.equals("null")) { - throw new RemoteConnectionException(IO_ERROR); - } - + + if (s == null) { + throw new RemoteConnectionException(IO_ERROR); + } + + if (s.equals("null")) { + throw new RemoteConnectionException(IO_ERROR); + } + return s; } - -} \ No newline at end of file + +} diff --git a/src/ui/interactivesimulation/GenericTransaction.java b/src/ui/interactivesimulation/GenericTransaction.java index 7a3b7d9a89..771dfaa6d2 100755 --- a/src/ui/interactivesimulation/GenericTransaction.java +++ b/src/ui/interactivesimulation/GenericTransaction.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class GenericTransaction - * Transaction as used - * Creation: 26/05/2011 - * @version 1.0 26/05/2011 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class GenericTransaction + * Transaction as used + * Creation: 26/05/2011 + * @version 1.0 26/05/2011 + * @author Ludovic APVRILLE + * @see + */ package ui.interactivesimulation; @@ -53,33 +53,33 @@ import myutil.*; import tmltranslator.*; public class GenericTransaction { - + public final static int NOT_DEFINED = 0; public final static int FUNCTION_CALL = 1; public final static int STATE_ENTERING = 2; public final static int VAR_MODIFICATION = 3; public final static int SEND_SYNCHRO = 4; - public final static int SYNCHRO = 5; - public final static int SEND_ASYNCHRO = 6; - public final static int RECEIVE_ASYNCHRO = 7; - - public int ID; + public final static int SYNCHRO = 5; + public final static int SEND_ASYNCHRO = 6; + public final static int RECEIVE_ASYNCHRO = 7; + + public int ID; public int type; public String entityName; public String otherEntityName; /* name of destination in synchro, etc. */ public String name; /* Used for channel names */ public String params; /* values separated with commas */ - public String messageID; /* Used for identifiying asynchronous messages */ + public String messageID; /* Used for identifiying asynchronous messages */ public String action; public long startingTime; public long finishTime; - + public long stamp; - - - - public GenericTransaction() { - } -} \ No newline at end of file + + public GenericTransaction() { + } + + +} diff --git a/src/ui/interactivesimulation/InteractiveSimulationActions.java b/src/ui/interactivesimulation/InteractiveSimulationActions.java index 582295b71b..96affc9394 100755 --- a/src/ui/interactivesimulation/InteractiveSimulationActions.java +++ b/src/ui/interactivesimulation/InteractiveSimulationActions.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class InteractiveSimulationActions - * - * Creation: 26/05/2009 - * @version 1.0 26/05/2009 - * @author Ludovic APVRILLE - * @see TGComponent - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class InteractiveSimulationActions + * + * Creation: 26/05/2009 + * @version 1.0 26/05/2009 + * @author Ludovic APVRILLE + * @see TGComponent + */ package ui.interactivesimulation; @@ -58,61 +58,62 @@ import ui.*; public class InteractiveSimulationActions extends AbstractAction { // Actions public static final int ACT_RUN_SIMU = 0; - public static final int ACT_STOP_SIMU = 1; - public static final int ACT_RESET_SIMU = 2; - public static final int ACT_RUN_X_TIME_UNITS = 6; - public static final int ACT_RUN_TO_TIME = 7; - public static final int ACT_RUN_X_TRANSACTIONS = 8; - public static final int ACT_RUN_X_COMMANDS = 9; - - public static final int ACT_RUN_EXPLORATION = 20; - public static final int ACT_RUN_TO_NEXT_BUS_TRANSFER = 21; - public static final int ACT_RUN_UNTIL_CPU_EXECUTES = 22; - public static final int ACT_RUN_UNTIL_TASK_EXECUTES = 23; - public static final int ACT_RUN_UNTIL_MEMORY_ACCESS = 24; - public static final int ACT_RUN_UNTIL_CHANNEL_ACCESS = 25; - - public static final int ACT_SAVE_VCD = 10; - public static final int ACT_SAVE_HTML = 11; - public static final int ACT_SAVE_TXT = 12; - - public static final int ACT_PRINT_BENCHMARK = 26; - public static final int ACT_SAVE_BENCHMARK = 27; - - public static final int ACT_SAVE_STATE = 13; - public static final int ACT_RESTORE_STATE = 14; - - public static final int ACT_START_ALL = 3; - public static final int ACT_STOP_ALL = 4; - public static final int ACT_STOP_AND_CLOSE_ALL = 5; - - public static final int ACT_UPDATE_VARIABLES = 15; - public static final int ACT_UPDATE_CPUS = 16; - public static final int ACT_UPDATE_MEMS = 17; - public static final int ACT_UPDATE_BUS = 18; - public static final int ACT_UPDATE_TASKS = 19; - - public static final int ACT_REFRESH = 32; - - public static final int ACT_PRINT_CPUS = 28; - public static final int ACT_PRINT_BUS = 29; - - public static final int ACT_ANALYSIS_RG = 30; - public static final int ACT_VIEW_RG = 31; - - public static final int NB_ACTION = 33; + public static final int ACT_STOP_SIMU = 1; + public static final int ACT_RESET_SIMU = 2; + public static final int ACT_RUN_X_TIME_UNITS = 6; + public static final int ACT_RUN_TO_TIME = 7; + public static final int ACT_RUN_X_TRANSACTIONS = 8; + public static final int ACT_RUN_X_COMMANDS = 9; + + public static final int ACT_RUN_EXPLORATION = 20; + public static final int ACT_RUN_TO_NEXT_BUS_TRANSFER = 21; + public static final int ACT_RUN_UNTIL_CPU_EXECUTES = 22; + public static final int ACT_RUN_UNTIL_TASK_EXECUTES = 23; + public static final int ACT_RUN_UNTIL_MEMORY_ACCESS = 24; + public static final int ACT_RUN_UNTIL_CHANNEL_ACCESS = 25; + + public static final int ACT_SAVE_VCD = 10; + public static final int ACT_SAVE_HTML = 11; + public static final int ACT_SAVE_TXT = 12; + + public static final int ACT_PRINT_BENCHMARK = 26; + public static final int ACT_SAVE_BENCHMARK = 27; + + public static final int ACT_SAVE_STATE = 13; + public static final int ACT_RESTORE_STATE = 14; + + public static final int ACT_START_ALL = 3; + public static final int ACT_STOP_ALL = 4; + public static final int ACT_STOP_AND_CLOSE_ALL = 5; + + public static final int ACT_UPDATE_VARIABLES = 15; + public static final int ACT_UPDATE_CPUS = 16; + public static final int ACT_UPDATE_MEMS = 17; + public static final int ACT_UPDATE_BUS = 18; + public static final int ACT_UPDATE_TASKS = 19; + public static final int ACT_UPDATE_TRANSACTIONS = 33; + + public static final int ACT_REFRESH = 32; + + public static final int ACT_PRINT_CPUS = 28; + public static final int ACT_PRINT_BUS = 29; + + public static final int ACT_ANALYSIS_RG = 30; + public static final int ACT_VIEW_RG = 31; + + public static final int NB_ACTION = 34; private static final TAction [] actions = new TAction[NB_ACTION]; - + private EventListenerList listeners; - + public static final String JLF_IMAGE_DIR = ""; - + public static final String LARGE_ICON = "LargeIcon"; - - + + public InteractiveSimulationActions(int id) { if (actions[0] == null) { init(); @@ -120,7 +121,7 @@ public class InteractiveSimulationActions extends AbstractAction { if (actions[id] == null) { return ; } - + putValue(Action.NAME, actions[id].NAME); putValue(Action.SMALL_ICON, actions[id].SMALL_ICON); putValue(LARGE_ICON, actions[id].LARGE_ICON); @@ -131,61 +132,62 @@ public class InteractiveSimulationActions extends AbstractAction { putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(actions[id].MNEMONIC_KEY, java.awt.event.InputEvent.CTRL_MASK)); } putValue(Action.ACTION_COMMAND_KEY, actions[id].ACTION_COMMAND_KEY); - + } - + public void setName(int index, String name) { actions[index].NAME = name; putValue(Action.NAME, actions[index].NAME); } - + public void init() { actions[ACT_RUN_SIMU] = new TAction("run-simu", "Run simulation", IconManager.imgic1302, IconManager.imgic1302, "Run simulation", "Run simulation until next breakpoint. Works only if the simulator is \"ready\"", 'R'); actions[ACT_STOP_SIMU] = new TAction("stop-simu", "Stop simulation", IconManager.imgic55, IconManager.imgic55, "Stop simulation", "Stop simulation. Works only if the simulator is \"busy\"", 'S'); - actions[ACT_RESET_SIMU] = new TAction("reset-simu", "Reset simulation", IconManager.imgic45, IconManager.imgic45, "Reset simulation", "Reset simulation", 'T'); - actions[ACT_RUN_X_TIME_UNITS] = new TAction("run-x-time-units", "Run x time units", IconManager.imgic1300, IconManager.imgic1300, "Run x time units", "Run simulation for x units of time. Works only if the simulator is \"ready\"", 'R'); + actions[ACT_RESET_SIMU] = new TAction("reset-simu", "Reset simulation", IconManager.imgic45, IconManager.imgic45, "Reset simulation", "Reset simulation", 'T'); + actions[ACT_RUN_X_TIME_UNITS] = new TAction("run-x-time-units", "Run x time units", IconManager.imgic1300, IconManager.imgic1300, "Run x time units", "Run simulation for x units of time. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_TO_TIME] = new TAction("run-to-time", "Run to time x", IconManager.imgic1304, IconManager.imgic1304, "Run to time x", "Run simulation until time x is reached. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_X_TRANSACTIONS] = new TAction("run-x-transactions", "Run x transactions", IconManager.imgic1306, IconManager.imgic1306, "Run x transactions", "Run simulation for x transactions. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_X_COMMANDS] = new TAction("run-x-commands", "Run x commands", IconManager.imgic1308, IconManager.imgic1308, "Run x commands", "Run simulation for x commands. Works only if the simulator is \"ready\"", 'R'); - - actions[ACT_RUN_EXPLORATION] = new TAction("run-exploration", "Run exploration", IconManager.imgic1326, IconManager.imgic1326, "Run exploration", "Explore branches of the simulation", 'R'); + + actions[ACT_RUN_EXPLORATION] = new TAction("run-exploration", "Run exploration", IconManager.imgic1326, IconManager.imgic1326, "Run exploration", "Explore branches of the simulation", 'R'); actions[ACT_RUN_TO_NEXT_BUS_TRANSFER] = new TAction("run-until-bus-transfer", "Run until bus transfer", IconManager.imgic1316, IconManager.imgic1316, "Run until transfer on bus", "Run until a transfer on the indicated bus is performed. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_UNTIL_CPU_EXECUTES] = new TAction("run-to-cpu", "Run until CPU executes", IconManager.imgic1320, IconManager.imgic1320, "Run until CPU executes", "Run until a CPU, given as parameter, executes. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_UNTIL_TASK_EXECUTES] = new TAction("run-to-task", "Run until a task executes", IconManager.imgic1318, IconManager.imgic1318, "Run until a task executes", "Run until a task executes. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_UNTIL_MEMORY_ACCESS] = new TAction("run-to-memory-accessd", "Run until a memory access is performed", IconManager.imgic1322, IconManager.imgic1322, "Run until a memory access is performed", "Run simulation until a memory access is performed on selected memory. Works only if the simulator is \"ready\"", 'R'); actions[ACT_RUN_UNTIL_CHANNEL_ACCESS] = new TAction("run--to-channel-access", "Run until a channel is accessed", IconManager.imgic1324, IconManager.imgic1324, "Run until a channel is accessed", "Run until a channel is accessed. Works only if the simulator is \"ready\"", 'R'); - - actions[ACT_SAVE_VCD] = new TAction("save-vcd", "Save trace in VCD format", IconManager.imgic1310, IconManager.imgic1310, "Save trace in VCD format", "Save trace in VCD format", 'R'); + + actions[ACT_SAVE_VCD] = new TAction("save-vcd", "Save trace in VCD format", IconManager.imgic1310, IconManager.imgic1310, "Save trace in VCD format", "Save trace in VCD format", 'R'); actions[ACT_SAVE_HTML] = new TAction("save-html", "Save trace in HTML format", IconManager.imgic1312, IconManager.imgic1312, "Save trace in HTML format", "Save trace in HTML format", 'R'); actions[ACT_SAVE_TXT] = new TAction("save-txt", "Save trace in TXT format", IconManager.imgic1314, IconManager.imgic1314, "Save trace in TXT format", "Save trace in TXT format", 'R'); - - actions[ACT_SAVE_STATE] = new TAction("save-state", "Save simulation state in File", IconManager.imgic341, IconManager.imgic341, "Save simulation state in File", "Save simulation state in File", 'R'); + + actions[ACT_SAVE_STATE] = new TAction("save-state", "Save simulation state in File", IconManager.imgic341, IconManager.imgic341, "Save simulation state in File", "Save simulation state in File", 'R'); actions[ACT_RESTORE_STATE] = new TAction("restore-state", "Restore simulation state from File", IconManager.imgic339, IconManager.imgic339, "Restore simulation state from File", "Restore simulation state from File", 'R'); - - actions[ACT_START_ALL] = new TAction("start-all", "Connect to simulator", IconManager.imgic53, IconManager.imgic53, "Connect", "Start the server - if it is not yet running - and connect to it", 'C'); + + actions[ACT_START_ALL] = new TAction("start-all", "Connect to simulator", IconManager.imgic53, IconManager.imgic53, "Connect", "Start the server - if it is not yet running - and connect to it", 'C'); actions[ACT_STOP_ALL] = new TAction("stop-all", "Quit simulation window", IconManager.imgic27, IconManager.imgic27, "Quit simulation window", "Quit the simulation window without terminating the simulation", 'Q'); actions[ACT_STOP_AND_CLOSE_ALL] = new TAction("stop-and-close-all", "Terminate simulation and quit", IconManager.imgic27, IconManager.imgic27, "Terminate simulation and quit", "Terminate the simulation and quit the simulation window", 'T'); - - actions[ACT_UPDATE_VARIABLES] = new TAction("update-variables", "Update variables", IconManager.imgic75, IconManager.imgic75, "Update variables", "Update variables", 'R'); + + actions[ACT_UPDATE_VARIABLES] = new TAction("update-variables", "Update variables", IconManager.imgic75, IconManager.imgic75, "Update variables", "Update variables", 'R'); actions[ACT_UPDATE_CPUS] = new TAction("update-cpus", "Update CPU info", IconManager.imgic75, IconManager.imgic75, "Update CPU information", "Update information on CPUs", 'R'); actions[ACT_UPDATE_MEMS] = new TAction("update-mems", "Update Memories information", IconManager.imgic75, IconManager.imgic75, "Update Memories information", "Update information on Memories", 'R'); - actions[ACT_UPDATE_BUS] = new TAction("update-bus", "Update bus info", IconManager.imgic75, IconManager.imgic75, "Update bus information", "Update information on busses", 'R'); + actions[ACT_UPDATE_BUS] = new TAction("update-bus", "Update bus info", IconManager.imgic75, IconManager.imgic75, "Update bus information", "Update information on buses", 'R'); actions[ACT_UPDATE_TASKS] = new TAction("update-tasks", "Update task information", IconManager.imgic75, IconManager.imgic75, "Update task information", "Update information on tasks", 'R'); - actions[ACT_REFRESH] = new TAction("refresh", "Refresh transactions", IconManager.imgic75, IconManager.imgic75, "Refresh", "Refresh the Sequence Diagram representing transactions", 'R'); - - actions[ACT_PRINT_CPUS] = new TAction("print-cpus", "Print CPU info", IconManager.imgic75, IconManager.imgic75, "Print CPU information", "Print information on CPUs", 'R'); - actions[ACT_PRINT_BUS] = new TAction("print-bus", "Print Bus info", IconManager.imgic75, IconManager.imgic75, "Print Bus information", "Print information on Busses", 'R'); - - actions[ACT_PRINT_BENCHMARK] = new TAction("print-benchmark", "Print benchmark", IconManager.imgic29, IconManager.imgic29, "Print benchmark", "Print benchmark at simulator side", 'R'); + actions[ACT_UPDATE_TRANSACTIONS] = new TAction("update-transactions", "Update transactions", IconManager.imgic75, IconManager.imgic75, "Update the list of recent transactions", "Update information on recent transactions", 'T'); + actions[ACT_REFRESH] = new TAction("refresh", "Refresh transactions", IconManager.imgic75, IconManager.imgic75, "Refresh", "Refresh the Sequence Diagram representing transactions", 'R'); + + actions[ACT_PRINT_CPUS] = new TAction("print-cpus", "Print CPU info", IconManager.imgic75, IconManager.imgic75, "Print CPU information", "Print information on CPUs", 'R'); + actions[ACT_PRINT_BUS] = new TAction("print-bus", "Print Bus info", IconManager.imgic75, IconManager.imgic75, "Print Bus information", "Print information on Busses", 'R'); + + actions[ACT_PRINT_BENCHMARK] = new TAction("print-benchmark", "Print benchmark", IconManager.imgic29, IconManager.imgic29, "Print benchmark", "Print benchmark at simulator side", 'R'); actions[ACT_SAVE_BENCHMARK] = new TAction("save-benchmark", "Save benchmark", IconManager.imgic25, IconManager.imgic25, "Save benchmark", "Save benchmark at simulator side", 'R'); - - actions[ACT_ANALYSIS_RG] = new TAction("analysis-rg", "Analysis of last RG", IconManager.imgic29, IconManager.imgic29, "Analysis of last RG", "Analyzis of the lastly generated RG", '0'); + + actions[ACT_ANALYSIS_RG] = new TAction("analysis-rg", "Analysis of last RG", IconManager.imgic29, IconManager.imgic29, "Analysis of last RG", "Analyzis of the lastly generated RG", '0'); actions[ACT_VIEW_RG] = new TAction("view-rg", "View last RG", IconManager.imgic344, IconManager.imgic344, "View last RG", "View last RG with Dotty (note: Dotty must be installed and configured to do so)", '0'); - - + + } - - + + public String getActionCommand() { return (String)getValue(Action.ACTION_COMMAND_KEY); } @@ -193,7 +195,7 @@ public class InteractiveSimulationActions extends AbstractAction { public String getShortDescription() { return (String)getValue(Action.SHORT_DESCRIPTION); } - + public String getLongDescription() { return (String)getValue(Action.LONG_DESCRIPTION); } @@ -202,27 +204,27 @@ public class InteractiveSimulationActions extends AbstractAction { //System.out.println("Action performed"); if (listeners != null) { Object[] listenerList = listeners.getListenerList(); - + // Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY ActionEvent e = new ActionEvent(evt.getSource(), evt.getID(), - (String)getValue(Action.ACTION_COMMAND_KEY)); + (String)getValue(Action.ACTION_COMMAND_KEY)); for (int i = 0; i <= listenerList.length-2; i += 2) { ((ActionListener)listenerList[i+1]).actionPerformed(e); } } } - + public void addActionListener(ActionListener l) { if (listeners == null) { listeners = new EventListenerList(); } listeners.add(ActionListener.class, l); } - + public void removeActionListener(ActionListener l) { if (listeners == null) { return; } listeners.remove(ActionListener.class, l); - } + } } diff --git a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java index 4adb469b40..957a84fdea 100755 --- a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -1,2381 +1,2474 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** -* Class JFrameInteractiveSimulation -* Creation: 21/04/2009 -* version 1.0 21/04/2009 -* @author Ludovic APVRILLE -* @see -*/ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class JFrameInteractiveSimulation + * Creation: 21/04/2009 + * version 1.0 21/04/2009 + * @author Ludovic APVRILLE + * @see + */ package ui.interactivesimulation; -//import java.io.*; -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.table.*; -import java.awt.*; -import java.awt.event.*; -import java.io.*; -import java.util.*; +//import java.io.*; +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.util.*; + + + +import myutil.*; +import ui.*; +import ui.file.*; + +import tmltranslator.*; + +import launcher.*; +import remotesimulation.*; + +import org.w3c.dom.*; +import org.xml.sax.*; +import javax.xml.parsers.*; + + +public class JFrameInteractiveSimulation extends JFrame implements ActionListener, Runnable, MouseListener, ItemListener, ChangeListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { + + protected static final String SIMULATION_HEADER = "siminfo"; + protected static final String SIMULATION_GLOBAL = "global"; + protected static final String SIMULATION_TASK = "task"; + protected static final String SIMULATION_CPU = "cpu"; + protected static final String SIMULATION_BUS = "bus"; + protected static final String SIMULATION_TRANS = "transinfo"; + protected static final String SIMULATION_COMMAND = "cmd"; + + private static String buttonStartS = "Start simulator"; + private static String buttonCloseS = "Close"; + private static String buttonStopAndCloseS = "Stop simulator and close"; + + private static int NOT_STARTED = 0; + private static int STARTING = 1; + private static int STARTED_NOT_CONNECTED = 2; + private static int STARTED_AND_CONNECTED = 3; + + private Frame f; + private MainGUI mgui; + private String title; + private String hostSystemC; + private String pathExecute; + + protected JButton buttonClose, buttonStart, buttonStopAndClose; + protected JTextArea jta; + protected JScrollPane jsp; + + protected Thread t; + protected int threadMode = 0; + protected boolean go; + protected RshClient rshc; + protected RemoteConnection rc; + protected CommandParser cp; + protected String ssxml; + + // Text commands + protected JTextField textCommand; + protected JButton sendTextCommand, printHelpTextCommands, listTextCommands; + //private static String sendTextCommandS = "Send Command"; + + // Control command + protected JButton resetCommand, runCommand, StopCommand; + protected MainCommandsToolBar mctb; + protected SaveCommandsToolBar sctb; + protected StateCommandsToolBar stctb; + protected BenchmarkCommandsToolBar bctb; + protected FormalVerificationToolBar fvtb; + + + // Commands + JPanel main, mainTop, commands, save, state, infos, outputs, cpuPanel, variablePanel, transactionPanel; // from MGUI + JCheckBox latex, debug, animate, diploids, update, openDiagram, animateWithInfo; + JTabbedPane commandTab, infoTab; + protected JTextField paramMainCommand; + protected JTextField saveDirName; + protected JTextField saveFileName; + protected JTextField stateFileName; + protected JTextField benchmarkFileName; + protected JComboBox cpus, busses, mems, tasks, chans; + + + private String[] cpuIDs, busIDs, memIDs, taskIDs, chanIDs; + + // Status elements + JLabel status, time, info; + + // Task elements + TaskVariableTableModel tvtm; + JButton updateTaskVariableInformationButton; + private JScrollPane jspTaskVariableInfo; + + // Last transactions elements + TransactionTableModel ttm; + JButton updateTransactionInformationButton; + private JScrollPane jspTransactionInfo; + private Vector<SimulationTransaction> trans; + + // Breakpoints + JPanelBreakPoints jpbp; + + // Set variables + JPanelSetVariables jpsv; + + // Formal verification + JSlider minimalCommandCoverage, minimalBranchCoverage; + JLabel labelMinimalCommandCoverage, labelMinimalBranchCoverage; + + // Tasks + JPanel taskPanel; + TaskTableModel tasktm; + JButton updateTaskInformationButton; + private JScrollPane jspTaskInfo; + + // CPU + CPUTableModel cputm; + JButton updateCPUInformationButton, printCPUInfo; + private JScrollPane jspCPUInfo; + private JPanel panelCPU; + + // Memories + JPanel memPanel; + MemTableModel memtm; + JButton updateMemoryInformationButton, printBusInfo; + private JScrollPane jspMemInfo; + + // Bus + JPanel busPanel; + BusTableModel bustm; + JButton updateBusInformationButton; + private JScrollPane jspBusInfo; + private JPanel panelBus; + + + private int mode = 0; + //private boolean busyStatus = false; + private int busyMode = 0; // 0: unknown; 1: ready; 2:busy; 3:term + private boolean threadStarted = false; + private boolean gotTimeAnswerFromServer = false; + + // For managing actions + public InteractiveSimulationActions [] actions; + public MouseHandler mouseHandler; + public KeyListener keyHandler; + + private TMLMapping tmap; + private int hashCode; + private boolean hashOK = true; + + private Hashtable <Integer, String> valueTable; + private Hashtable <Integer, Integer> rowTable; + + private Hashtable <Integer, Integer> runningTable; + private Hashtable <String, String> diagramTable; + + private ArrayList<Point> points; + + public JFrameInteractiveSimulation(Frame _f, MainGUI _mgui, String _title, String _hostSystemC, String _pathExecute, TMLMapping _tmap, ArrayList<Point> _points) { + super(_title); + + f = _f; + mgui = _mgui; + title = _title; + hostSystemC = _hostSystemC; + pathExecute = _pathExecute; + + mode = NOT_STARTED; + + tmap = _tmap; + if (tmap != null) { + tmap.makeMinimumMapping(); + hashCode = tmap.getHashCode(); + tmap.getTMLModeling().computeCorrespondance(); + } else { + hashOK = false; + } + + points = _points; + + //System.out.println("Tmap=" + tmap); + + valueTable = new Hashtable<Integer, String>(); + rowTable = new Hashtable<Integer, Integer>(); + runningTable = new Hashtable<Integer, Integer>(); + diagramTable = new Hashtable<String, String>(); + + + mgui.resetRunningID(); + mgui.resetLoadID(); + + setBackground(new Color(50, 40, 40)); + + initActions(); + makeComponents(); + setComponents(); + } + + private JLabel createStatusBar() { + status = new JLabel("Ready..."); + status.setForeground(ColorManager.InteractiveSimulationText); + status.setBorder(BorderFactory.createEtchedBorder()); + return status; + } + + public void makeComponents() { + JPanel jp01, jp02; + //jp01.setPreferredSize(new Dimension(375, 400)); + GridBagLayout gridbag01; + GridBagConstraints c01 ; + + cp = new CommandParser(); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Container framePanel = getContentPane(); + framePanel.setLayout(new BorderLayout()); + //framePanel.setBackground(ColorManager.InteractiveSimulationBackground); + //framePanel.setForeground(new Color(255, 166, 38)); + + //System.out.println("Button start created"); + buttonStart = new JButton(actions[InteractiveSimulationActions.ACT_START_ALL]); + buttonClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_ALL]); + buttonStopAndClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_AND_CLOSE_ALL]); + //buttonStopAndClose = new JButton(buttonStopAndCloseS, IconManager.imgic27); + + + + + + // statusBar + status = createStatusBar(); + framePanel.add(status, BorderLayout.SOUTH); + + // Mouse handler + mouseHandler = new MouseHandler(status); + + JPanel mainpanel = new JPanel(new BorderLayout()); + //mainpanel.setBackground(ColorManager.InteractiveSimulationBackground); + framePanel.add(mainpanel, BorderLayout.NORTH); + + JPanel jp = new JPanel(); + //jp.setBackground(ColorManager.InteractiveSimulationBackground); + //jp.setPreferredSize(new Dimension(800, 75)); + jp.add(buttonStart); + jp.add(buttonStopAndClose); + jp.add(buttonClose); + mainpanel.add(jp, BorderLayout.NORTH); + + + GridBagLayout gridbag02 = new GridBagLayout(); + GridBagConstraints c02 = new GridBagConstraints(); + mainTop = new JPanel(gridbag02); + //mainTop.setPreferredSize(new Dimension(800, 375)); + c02.gridheight = 1; + c02.weighty = 1.0; + c02.weightx = 1.0; + c02.gridwidth = 1; + c02.fill = GridBagConstraints.BOTH; + c02.gridheight = 1; + + // Ouput textArea + jta = new ScrolledJTextArea(); + jta.setBackground(ColorManager.InteractiveSimulationJTABackground); + jta.setForeground(ColorManager.InteractiveSimulationJTAForeground); + jta.setMinimumSize(new Dimension(800, 400)); + jta.setRows(15); + //jta.setMaximumSize(new Dimension(800, 500)); + jta.setEditable(false); + jta.setMargin(new Insets(10, 10, 10, 10)); + jta.setTabSize(3); + jta.append("Click on \"Connect\" to start the remote simulator and connect to it\n"); + Font f = new Font("Courrier", Font.BOLD, 12); + jta.setFont(f); + jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + jsp.setViewportBorder(BorderFactory.createLineBorder(ColorManager.InteractiveSimulationBackground)); + + //jsp.setColumnHeaderView(100); + //jsp.setRowHeaderView(30); + + + jsp.setMaximumSize(new Dimension(800, 500)); + JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, mainTop, jsp); + //split.setBackground(ColorManager.InteractiveSimulationBackground); + mainpanel.add(split, BorderLayout.CENTER); + + // Commands + commands = new JPanel(); + //commands.setFloatable(true); + //commands.setMinimumSize(new Dimension(300, 250)); + commands.setBorder(new javax.swing.border.TitledBorder("Commands")); + + + mainTop.add(commands, c02); + + commandTab = new JTabbedPane(); + //commandTab.setBackground(ColorManager.InteractiveSimulationBackground); + + // Control commands + jp01 = new JPanel(new BorderLayout()); + //jp01.setMinimumSize(new Dimension(375, 400)); + //gridbag01 = new GridBagLayout(); + //c01 = new GridBagConstraints(); + //jp01.setLayout(gridbag01); + + commandTab.addTab("Control", null, jp01, "Main control commands"); + + + mctb = new MainCommandsToolBar(this); + jp01.add(mctb, BorderLayout.NORTH); + + jp02 = new JPanel(); + //jp01.setPreferredSize(new Dimension(375, 400)); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp02.setLayout(gridbag01); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = 1; + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + jp02.add(new JLabel("Command parameter: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + paramMainCommand = new JTextField("1", 30); + jp02.add(paramMainCommand, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("CPUs and HwA: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + if (cpuIDs == null) { + cpus = new JComboBox(); + } else { + cpus = new JComboBox(cpuIDs); + } + jp02.add(cpus, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("Busses: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + if (busIDs == null) { + busses = new JComboBox(); + } else { + busses = new JComboBox(busIDs); + } + jp02.add(busses, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("Memories: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + if (memIDs == null) { + mems = new JComboBox(); + } else { + mems = new JComboBox(memIDs); + } + jp02.add(mems, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("Tasks: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + if (taskIDs == null) { + tasks = new JComboBox(); + } else { + tasks = new JComboBox(taskIDs); + } + jp02.add(tasks, c01); + + c01.gridwidth = 1; + jp02.add(new JLabel("Channels: "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + if (chanIDs == null) { + chans = new JComboBox(); + } else { + chans = new JComboBox(chanIDs); + } + jp02.add(chans, c01); + + jp01.add(jp02, BorderLayout.CENTER); + + + // Text commands + jp01 = new JPanel(); + //jp01.setPreferredSize(new Dimension(375, 400)); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp01.setLayout(gridbag01); + + commandTab.addTab("Text commands", null, jp01, "Sending text commands to simulator"); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + c01.gridheight = 2; + jp01.add(new JLabel("Enter a text command:"), c01); + textCommand = new JTextField(30); + jp01.add(textCommand, c01); + c01.gridheight = 1; + jp01.add(new JLabel(" "), c01); + c01.gridheight = 2; + sendTextCommand = new JButton("Send Command", IconManager.imgic71); + sendTextCommand.addMouseListener(this); + jp01.add(sendTextCommand, c01); + c01.gridheight = 1; + jp01.add(new JLabel(" "), c01); + c01.gridheight = 2; + printHelpTextCommands = new JButton("Help on a text command", IconManager.imgic33); + printHelpTextCommands.addMouseListener(this); + jp01.add(printHelpTextCommands, c01); + c01.gridheight = 1; + jp01.add(new JLabel(" "), c01); + c01.gridheight = 2; + listTextCommands = new JButton("List all text commands", IconManager.imgic29); + listTextCommands.addMouseListener(this); + jp01.add(listTextCommands, c01); + + commands.add(commandTab); + + // Set variables + jpsv = new JPanelSetVariables(this, valueTable); + commandTab.addTab("Set variables", null, jpsv, "Set variables"); + + // Save commands + jp01 = new JPanel(new BorderLayout()); + + commandTab.addTab("Save trace", null, jp01, "Save commands"); + + sctb = new SaveCommandsToolBar(this); + jp01.add(sctb, BorderLayout.NORTH); + + jp02 = new JPanel(); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp02.setLayout(gridbag01); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + jp02.add(new JLabel("Directory:"), c01); + saveDirName = new JTextField(30); + if (ConfigurationTTool.SystemCCodeDirectory != null) { + saveDirName.setText(ConfigurationTTool.SystemCCodeDirectory); + } + jp02.add(saveDirName, c01); + jp02.add(new JLabel("File name:"), c01); + saveFileName = new JTextField(30); + jp02.add(saveFileName, c01); + + jp01.add(jp02, BorderLayout.CENTER); + + // State commands + jp01 = new JPanel(new BorderLayout()); + + commandTab.addTab("Save / restore state", null, jp01, "Save commands"); + + stctb = new StateCommandsToolBar(this); + jp01.add(stctb, BorderLayout.NORTH); + + jp02 = new JPanel(); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp02.setLayout(gridbag01); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + jp02.add(new JLabel("File name:"), c01); + stateFileName = new JTextField(30); + jp02.add(stateFileName, c01); + + jp01.add(jp02, BorderLayout.CENTER); + + // Benchmark commands + jp01 = new JPanel(new BorderLayout()); + + commandTab.addTab("Benchmarks", null, jp01, "Benchmarks"); + + bctb = new BenchmarkCommandsToolBar(this); + jp01.add(bctb, BorderLayout.NORTH); + + jp02 = new JPanel(); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp02.setLayout(gridbag01); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + jp02.add(new JLabel("File name:"), c01); + benchmarkFileName = new JTextField(30); + jp02.add(benchmarkFileName, c01); + + jp01.add(jp02, BorderLayout.CENTER); + + // Formal verification + jp01 = new JPanel(new BorderLayout()); + + commandTab.addTab("Formal verification", null, jp01, "Formal verification"); + + fvtb = new FormalVerificationToolBar(this); + jp01.add(fvtb, BorderLayout.NORTH); + + jp02 = new JPanel(); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp02.setLayout(gridbag01); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + // First empty line + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01); + + // Line minimum command: labels + c01.gridwidth = 1; + jp02.add(new JLabel("minimum COMMAND coverage"), c01); + labelMinimalCommandCoverage = new JLabel("100%"); + c01.fill = GridBagConstraints.CENTER; + jp02.add(labelMinimalCommandCoverage, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + jp02.add(new JLabel(" "), c01); + + // Line minimum command: slider + c01.gridwidth = 1; + jp02.add(new JLabel(" "), c01); + minimalCommandCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); + minimalCommandCoverage.setValue(100); + minimalCommandCoverage.setMajorTickSpacing(10); + minimalCommandCoverage.setMinorTickSpacing(1); + minimalCommandCoverage.setPaintTicks(true); + minimalCommandCoverage.setPaintLabels(true); + minimalCommandCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); + minimalCommandCoverage.addChangeListener(this); + Font font = new Font("Serif", Font.ITALIC, 10); + minimalCommandCoverage.setFont(font); + jp02.add(minimalCommandCoverage, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01); + + // One empty line + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01); + + // Line minimum command: labels + c01.gridwidth = 1; + jp02.add(new JLabel("minimum BRANCH coverage"), c01); + labelMinimalBranchCoverage = new JLabel("100%"); + c01.fill = GridBagConstraints.CENTER; + jp02.add(labelMinimalBranchCoverage, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + jp02.add(new JLabel(" "), c01); + + // Line minimum branch: slider + c01.gridwidth = 1; + jp02.add(new JLabel(" "), c01); + minimalBranchCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); + minimalBranchCoverage.setValue(100); + minimalBranchCoverage.setMajorTickSpacing(10); + minimalBranchCoverage.setMinorTickSpacing(1); + minimalBranchCoverage.setPaintTicks(true); + minimalBranchCoverage.setPaintLabels(true); + minimalBranchCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); + minimalBranchCoverage.addChangeListener(this); + minimalBranchCoverage.setFont(font); + jp02.add(minimalBranchCoverage, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01); + + // Last empty line + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01); + + /*c01.gridwidth = 1; + jp02.add(new JLabel("minimum BRANCH coverage"), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + labelMinimalBranchCoverage = new JLabel("100%"); + c01.fill = GridBagConstraints.EAST; + jp02.add(labelMinimalBranchCoverage, c01); + c01.fill = GridBagConstraints.BOTH; + minimalBranchCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); + minimalBranchCoverage.setValue(100); + minimalBranchCoverage.setMajorTickSpacing(10); + minimalBranchCoverage.setMinorTickSpacing(1); + minimalBranchCoverage.setPaintTicks(true); + minimalBranchCoverage.setPaintLabels(true); + minimalBranchCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); + minimalBranchCoverage.addChangeListener(this); + minimalBranchCoverage.setFont(font); + c01.gridwidth = 1; //end row + jp02.add(new JLabel(" "), c01); + jp02.add(minimalBranchCoverage, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + jp02.add(new JLabel(" "), c01);*/ + jp01.add(jp02, BorderLayout.CENTER); + + + //Info + infos = new JPanel(new BorderLayout()); + infos.setMinimumSize(new Dimension(300, 250)); + //infos.setPreferredSize(new Dimension(400, 450)); + infos.setBorder(new javax.swing.border.TitledBorder("Simulation information")); + c02.gridwidth = GridBagConstraints.REMAINDER; //end row + mainTop.add(infos, c02); + + infoTab = new JTabbedPane(); + infoTab.setMinimumSize(new Dimension(300, 250)); + infos.add(infoTab, BorderLayout.NORTH); + + // Simulation time + jp02 = new JPanel(); + infos.add(jp02, BorderLayout.SOUTH); + jp02.add(new JLabel("Status:")); + status = new JLabel("Unknown"); + status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + jp02.add(status); + jp02.add(new JLabel(" ")); + jp02.add(new JLabel("Time:")); + time = new JLabel("Unknown"); + time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + jp02.add(time); + jp02.add(new JLabel(" ")); + jp02.add(new JLabel("Sim. interrupt reason:")); + info = new JLabel("Unknown"); + info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + jp02.add(info); + + // Options + jp01 = new JPanel(); + //jp01.setMinimumSize(new Dimension(375, 400)); + //jp01.setPreferredSize(new Dimension(375, 400)); + gridbag01 = new GridBagLayout(); + c01 = new GridBagConstraints(); + jp01.setLayout(gridbag01); + + + // INFORMATION + + infoTab.addTab("Options", null, jp01, "Options on simulation"); + + c01.gridheight = 1; + c01.weighty = 1.0; + c01.weightx = 1.0; + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + c01.fill = GridBagConstraints.BOTH; + c01.gridheight = 1; + + jp01.add(new JLabel(" "), c01); + latex = new JCheckBox("Generate info in Latex format"); + jp01.add(latex, c01); + debug = new JCheckBox("Print messages received from server"); + jp01.add(debug, c01); + animate = new JCheckBox("Animate UML diagrams"); + jp01.add(animate, c01); + diploids = new JCheckBox("Show DIPLO IDs on UML diagrams"); + jp01.add(diploids, c01); + diploids.addItemListener(this); + diploids.setSelected(false); + animateWithInfo = new JCheckBox("Show transaction progression on UML diagrams"); + jp01.add(animateWithInfo, c01); + animateWithInfo.addItemListener(this); + animateWithInfo.setSelected(true); + openDiagram = new JCheckBox("Automatically open active task diagram"); + jp01.add(openDiagram, c01); + openDiagram.setSelected(true); + update = new JCheckBox("Automatically update information (task, CPU, etc.)"); + jp01.add(update, c01); + update.addItemListener(this); + update.setSelected(true); + + animate.addItemListener(this); + animate.setSelected(true); + + + TableSorter sorterPI; + JTable jtablePI; + + // Breakpoints + jpbp = new JPanelBreakPoints(this, points); + infoTab.addTab("Breakpoints", null, jpbp, "List of active breakpoints"); + + // Tasks + taskPanel = new JPanel(); + taskPanel.setLayout(new BorderLayout()); + infoTab.addTab("Tasks", IconManager.imgic1202, taskPanel, "Current state of tasks"); + if (tmap == null) { + tasktm = new TaskTableModel(null, valueTable, rowTable); + } else { + tasktm = new TaskTableModel(tmap.getTMLModeling(), valueTable, rowTable); + } + + sorterPI = new TableSorter(tasktm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(80); + ((jtablePI.getColumnModel()).getColumn(3)).setPreferredWidth(300); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspTaskInfo = new JScrollPane(jtablePI); + jspTaskInfo.setWheelScrollingEnabled(true); + jspTaskInfo.getVerticalScrollBar().setUnitIncrement(10); + jspTaskInfo.setPreferredSize(new Dimension(500, 300)); + taskPanel.add(jspTaskInfo, BorderLayout.NORTH); + updateTaskInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_TASKS]); + taskPanel.add(updateTaskInformationButton, BorderLayout.SOUTH); + + // Variables + variablePanel = new JPanel(); + variablePanel.setLayout(new BorderLayout()); + infoTab.addTab("Tasks variables", null, variablePanel, "Current value of variables"); + if (tmap == null) { + tvtm = new TaskVariableTableModel(null, valueTable, rowTable); + } else { + tvtm = new TaskVariableTableModel(tmap.getTMLModeling(), valueTable, rowTable); + } + sorterPI = new TableSorter(tvtm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(60); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(3)).setPreferredWidth(60); + ((jtablePI.getColumnModel()).getColumn(4)).setPreferredWidth(100); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspTaskVariableInfo = new JScrollPane(jtablePI); + jspTaskVariableInfo.setWheelScrollingEnabled(true); + jspTaskVariableInfo.getVerticalScrollBar().setUnitIncrement(10); + jspTaskVariableInfo.setPreferredSize(new Dimension(500, 300)); + variablePanel.add(jspTaskVariableInfo, BorderLayout.NORTH); + updateTaskVariableInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_VARIABLES]); + variablePanel.add(updateTaskVariableInformationButton, BorderLayout.SOUTH); + + // Transactions + transactionPanel = new JPanel(); + transactionPanel.setLayout(new BorderLayout()); + infoTab.addTab("Transactions", null, transactionPanel, "Recent transactions"); + ttm = new TransactionTableModel(this); + sorterPI = new TableSorter(ttm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(150); + ((jtablePI.getColumnModel()).getColumn(3)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(4)).setPreferredWidth(100); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspTransactionInfo = new JScrollPane(jtablePI); + jspTransactionInfo.setWheelScrollingEnabled(true); + jspTransactionInfo.getVerticalScrollBar().setUnitIncrement(10); + jspTransactionInfo.setPreferredSize(new Dimension(500, 300)); + transactionPanel.add(jspTransactionInfo, BorderLayout.NORTH); + updateTransactionInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_TRANSACTIONS]); + transactionPanel.add(updateTransactionInformationButton, BorderLayout.SOUTH); + + // CPUs + cpuPanel = new JPanel(); + cpuPanel.setLayout(new BorderLayout()); + infoTab.addTab("CPUs/HwA", IconManager.imgic1100, cpuPanel, "Current state of CPUs and hardware accelerators"); + cputm = new CPUTableModel(tmap, valueTable, rowTable); + sorterPI = new TableSorter(cputm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(700); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspCPUInfo = new JScrollPane(jtablePI); + jspCPUInfo.setWheelScrollingEnabled(true); + jspCPUInfo.getVerticalScrollBar().setUnitIncrement(10); + jspCPUInfo.setPreferredSize(new Dimension(500, 300)); + cpuPanel.add(jspCPUInfo, BorderLayout.NORTH); + panelCPU = new JPanel(new FlowLayout()); + updateCPUInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_CPUS]); + panelCPU.add(updateCPUInformationButton); + printCPUInfo = new JButton(actions[InteractiveSimulationActions.ACT_PRINT_CPUS]); + panelCPU.add(printCPUInfo); + cpuPanel.add(panelCPU, BorderLayout.SOUTH); + + // Memories + memPanel = new JPanel(); + memPanel.setLayout(new BorderLayout()); + infoTab.addTab("Memories", IconManager.imgic1108, memPanel, "Current state of Memories"); + MemTableModel memtm = new MemTableModel(tmap, valueTable, rowTable); + sorterPI = new TableSorter(memtm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(300); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspMemInfo = new JScrollPane(jtablePI); + jspMemInfo.setWheelScrollingEnabled(true); + jspMemInfo.getVerticalScrollBar().setUnitIncrement(10); + jspMemInfo.setPreferredSize(new Dimension(500, 300)); + memPanel.add(jspMemInfo, BorderLayout.NORTH); + updateMemoryInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_MEMS]); + memPanel.add(updateMemoryInformationButton, BorderLayout.SOUTH); + + // Busses + busPanel = new JPanel(); + busPanel.setLayout(new BorderLayout()); + infoTab.addTab("Bus", IconManager.imgic1102, busPanel, "Current state of busses"); + bustm = new BusTableModel(tmap, valueTable, rowTable); + sorterPI = new TableSorter(bustm); + jtablePI = new JTable(sorterPI); + sorterPI.setTableHeader(jtablePI.getTableHeader()); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); + ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(300); + jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + jspBusInfo = new JScrollPane(jtablePI); + jspBusInfo.setWheelScrollingEnabled(true); + jspBusInfo.getVerticalScrollBar().setUnitIncrement(10); + jspBusInfo.setPreferredSize(new Dimension(500, 300)); + busPanel.add(jspBusInfo, BorderLayout.NORTH); + panelBus = new JPanel(new FlowLayout()); + updateBusInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_BUS]); + panelBus.add(updateBusInformationButton); + printBusInfo = new JButton(actions[InteractiveSimulationActions.ACT_PRINT_BUS]); + panelBus.add(printBusInfo); + busPanel.add(panelBus, BorderLayout.SOUTH); + + + if (!hashOK) { + wrongHashCode(); + } + pack(); + + //System.out.println("Row table:" + rowTable.toString()); + //System.out.println("Value table:" + valueTable.toString()); + } + + private void initActions() { + actions = new InteractiveSimulationActions[InteractiveSimulationActions.NB_ACTION]; + for(int i=0; i<InteractiveSimulationActions.NB_ACTION; i++) { + actions[i] = new InteractiveSimulationActions(i); + actions[i].addActionListener(this); + //actions[i].addKeyListener(this); + } + + cpuIDs = makeCPUIDs(); + busIDs = makeBusIDs(); + memIDs = makeMemIDs(); + taskIDs = makeTasksIDs(); + chanIDs = makeChanIDs(); + } + + + + public void setComponents() { + if (mode == NOT_STARTED) { + buttonStart.setEnabled(true); + } else { + buttonStart.setEnabled(false); + } + + if ((mode == STARTED_NOT_CONNECTED) || (mode == STARTED_AND_CONNECTED)) { + buttonStopAndClose.setEnabled(true); + } else { + buttonStopAndClose.setEnabled(false); + } + + boolean b = (mode == STARTED_AND_CONNECTED); + sendTextCommand.setEnabled(b); + setAll(); + //resetCommand.setEnabled(b); + //runCommand.setEnabled(b); + //StopCommand.setEnabled(b); + } + + public void close() { + if(mode != NOT_STARTED) { + go = false; + if (rc != null) { + try { + rc.disconnect(); + } catch (RemoteConnectionException rce) { + } + //System.out.println("Disconnected"); + rc = null; + } + } + mgui.resetRunningID(); + mgui.resetLoadID(); + mgui.setDiploAnimate(false); + dispose(); + setVisible(false); + + } + + public void killSimulator() { + if (mode == STARTED_AND_CONNECTED) { + if (rc != null) { + try { + rc.send("0"); + } catch (RemoteConnectionException rce) { + jta.append("Exception: " + rce.getMessage()); + jta.append("Could not kill simulator\n"); + } + } + rshc = null; + } else { + if (rshc != null) { + try { + rshc.sendKillProcessRequest(); + } catch (LauncherException le) { + jta.append("Exception: " + le.getMessage() + "\n"); + } + } + } + } + + public void startSimulation() { + mode = STARTING; + setComponents(); + go = true; + + startThread(0); + //t = new Thread(this); + //go = true; + //threadMode = 0; + //t.start(); + } + + private void testGo() throws InterruptedException { + if (go == false) { + throw new InterruptedException("Stopped by user"); + } + } + + // Must first start the remote server + // Then, must start + + public void run() { + String s; + TraceManager.addDev("mode=" + threadMode); + + try { + if (threadMode == 0) { + threadStarted(); + testGo(); + rc = new RemoteConnection(hostSystemC); + + if (!connect()) { + rshc = new RshClient(hostSystemC); + try { + jta.append("\nStarting simulation server\n"); + processCmd(pathExecute); + //jta.append(data + "\n"); + } catch (LauncherException le) { + jta.append("Error: " + le.getMessage() + "\n"); + mode = NOT_STARTED; + setComponents(); + return; + } catch (Exception e) { + mode = NOT_STARTED; + setComponents(); + return; + } + testGo(); + + // Wait for the server to start + Thread.currentThread().sleep(1000); + + //jta.append("Simulator started\n\n"); + jta.append("Connecting to simulation server ...\n"); + mode = STARTED_NOT_CONNECTED; + if (!connect()) { + jta.append("Could not connect to server... Aborting\n"); + mode = NOT_STARTED; + setComponents(); + return; + } + } + + testGo(); + + jta.append("Connected to simulation server ...\n"); + mode = STARTED_AND_CONNECTED; + + startThread(2); + + setComponents(); + + if (tmap != null) { + sendCommand("get-hashcode"); + } else { + sendCommand("time"); + } + + + try { + while(true) { + testGo(); + s = rc.readOneLine(); + if (debug.isSelected()) { + jta.append("\nFrom server: " + s + "\n"); + } + analyzeServerAnswer(s); + } + } catch (RemoteConnectionException rce) { + jta.append("Exception: " + rce.getMessage()); + jta.append("Could not read data from host: " + hostSystemC + ".... Aborting\n"); + busyMode = 0; + setLabelColors(); + //System.out.println("rc left"); + } + } else if (threadMode == 1) { + threadStarted(); + try { + while(true) { + testGo(); + s = rshc.getDataFromProcess(); + jta.append("\nFrom launcher: " + s + "\n"); + } + } catch (LauncherException le) { + jta.append("Exception: " + le.getMessage() + "\n"); + } + } else if (threadMode == 2) { + threadStarted(); + while(true) { + testGo(); + Thread.currentThread().sleep(500); + if (busyMode == 2 && gotTimeAnswerFromServer) { + gotTimeAnswerFromServer = false; + askForUpdate(); + + } + } + } + } catch (InterruptedException ie) { + jta.append("Interrupted\n"); + } + + //System.out.println("rc left threadMode=" + threadMode); + + } + + protected boolean connect() { + try { + rc.connect(); + return true; + } catch (RemoteConnectionException rce) { + return false; + } + } + + protected void processCmd(String cmd) throws LauncherException { + rshc.setCmd(cmd); + rshc.sendProcessRequest(); + startThread(1); + //t = new Thread(this); + ////go = true; + //threadMode = 1; + //t.start(); + } + + public void mouseClicked(MouseEvent e) {} + + public void mouseEntered(MouseEvent e) {} + + public void mouseExited(MouseEvent e) {} + + public void mousePressed(MouseEvent e){ + if (e.getSource() == sendTextCommand) { + if (sendTextCommand.isEnabled()) { + sendCommand(); + } + } else if (e.getSource() == printHelpTextCommands) { + helpOnCommand(); + } else if (e.getSource() == listTextCommands) { + listTextCommands(); + } /*else if (e.getSource() == resetCommand) { + sendCommand("reset"); + } else if (e.getSource() == runCommand) { + sendCommand("run-to-next-breakpoint"); + } else if (e.getSource() == StopCommand) { + sendCommand("stop"); + }*/ + } + + // Command management + + public void printSeparator() { + jta.append("-------------------------------------------------------------\n"); + } + + protected void listTextCommands() { + String text = cp.getCommandList(); + append("Available commands", text); + } + + protected void helpOnCommand() { + String text = textCommand.getText().trim(); + String texts[] = text.split(" "); + text = texts[0]; + String result = cp.getHelp(text); + append("Help on command: " + text, result); + } + + protected void sendCommand() { + String text = textCommand.getText().trim(); + sendCommand(text); + } + + protected void sendCommand(String text) { + jta.append(">" + text + "\n"); + String command = cp.transformCommandFromUserToSimulator(text); + if (command.length() == 0) { + jta.append("** Wrong command / parameters **\n"); + return; + } + + try { + rc.send(command); + } catch (RemoteConnectionException rce) { + jta.append("** Sending command failed **\n"); + return ; + } catch (Exception e) {} + } + + protected void append(String info, String list) { + jta.append("\n"); + jta.append(info + "\n"); + printSeparator(); + jta.append(list); + jta.append("\n"); + printSeparator(); + } + + protected void analyzeServerAnswer(String s) { + //System.out.println("From server:" + s); + int index0 = s.indexOf("<?xml"); + + if (index0 != -1) { + //System.out.println("toto1"); + ssxml = s.substring(index0, s.length()) + "\n"; + } else { + //System.out.println("toto2"); + ssxml = ssxml + s + "\n"; + } + + index0 = ssxml.indexOf("</siminfo>"); + + if (index0 != -1) { + //System.out.println("toto3"); + ssxml = ssxml.substring(0, index0+10); + loadXMLInfoFromServer(ssxml); + ssxml = ""; + } + //System.out.println("toto4"); + + } + + protected boolean loadXMLInfoFromServer(String xmldata) { + //jta.append("XML from server:" + xmldata + "\n\n"); + + DocumentBuilderFactory dbf; + DocumentBuilder db; + + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + dbf = null; + db = null; + } + + if ((dbf == null) || (db == null)) { + return false; + } + + ByteArrayInputStream bais = new ByteArrayInputStream(decodeString(xmldata).getBytes()); + int i; + + try { + // building nodes from xml String + Document doc = db.parse(bais); + NodeList nl; + Node node; + + nl = doc.getElementsByTagName(SIMULATION_HEADER); + + if (nl == null) { + return false; + } + + for(i=0; i<nl.getLength(); i++) { + node = nl.item(i); + //System.out.println("Node = " + dnd); + if (node.getNodeType() == Node.ELEMENT_NODE) { + // create design, and get an index for it + return loadConfiguration(node); + } + } + + } catch (IOException e) { + TraceManager.addError("Error when parsing server info:" + e.getMessage()); + return false; + } catch (SAXException saxe) { + TraceManager.addError("Error when parsing server info:" + saxe.getMessage()); + TraceManager.addError("xml:" + xmldata); + return false; + } + return true; + + } + + protected boolean loadConfiguration(Node node1) { + NodeList diagramNl = node1.getChildNodes(); + if (diagramNl == null) { + return false; + } + Element elt, elt0; + Node node, node0, node00; + NodeList nl, nl0; + + + String tmp; + int val; + + int[] colors; + String msg = null; + String error = null; + String hash = null; + + String id, idvar; + String name; + String command; + String startTime="", finishTime=""; + String progression="", nextCommand=""; + String transStartTime="", transFinishTime=""; + String util = null; + String value; + String extime; + String contdel; + String busname; + String busid; + String state; + String usedEnergy; + + int k; + + //System.out.println("toto0"); + + try { + for(int j=0; j<diagramNl.getLength(); j++) { + //System.out.println("Ndes: " + j); + node = diagramNl.item(j); + + if (node == null) { + TraceManager.addDev("null node"); + return false; + } + + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + + // Status + if (elt.getTagName().compareTo(SIMULATION_GLOBAL) == 0) { + + nl = elt.getElementsByTagName("status"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + + makeStatus(node0.getTextContent()); + } + + nl = elt.getElementsByTagName("brkreason"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + + makeBrkReason(node0.getTextContent()); + } + + nl = elt.getElementsByTagName("simtime"); + if ((nl != null) && (nl.getLength() > 0)) { + gotTimeAnswerFromServer = true; + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + time.setText(node0.getTextContent()); + } + + nl = elt.getElementsByTagName("msg"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + msg = node0.getTextContent(); + } + + nl = elt.getElementsByTagName("error"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + error = node0.getTextContent(); + } + + nl = elt.getElementsByTagName("hashval"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + hash = node0.getTextContent(); + } + + nl = elt.getElementsByTagName(SIMULATION_COMMAND); + for(int kk=0; kk<nl.getLength(); kk++) { + node0 = nl.item(kk); + elt0 = (Element)node0; + id = null; + name = null; + command = null; + id = elt0.getAttribute("id"); + //TraceManager.addDev("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + nl0 = elt0.getElementsByTagName("exectimes"); + if ((nl0 != null) && (nl0.getLength() > 0)) { + node00 = nl0.item(0); + //TraceManager.addDev("nl0:" + nl0 + " value=" + node00.getNodeValue() + " content=" + node00.getTextContent()); + util = node00.getTextContent(); + } + + //TraceManager.addDev("Got info on command " + id + " util=" + util); + + if ((id != null) && (util != null)) { + //TraceManager.addDev("Updating command"); + updateCommandExecutionState(id, util); + } + } + + nl = elt.getElementsByTagName(SIMULATION_TRANS); + for(int kk=0; kk<nl.getLength(); kk++) { + node0 = nl.item(kk); + elt0 = (Element)node0; + + if (elt0 != null) { + //TraceManager.addDev("transinfo found: " + elt0); + SimulationTransaction st = new SimulationTransaction(); + st.nodeType = elt0.getAttribute("deviceid"); + + st.deviceName = elt0.getAttribute("devicename"); + String commandT = elt0.getAttribute("command"); + //TraceManager.addDev("command found: " + commandT); + if (commandT != null) { + int index = commandT.indexOf(": "); + if (index == -1){ + st.taskName = "Unknown"; + st.command = commandT; + } else { + st.taskName = commandT.substring(0, index).trim(); + st.command = commandT.substring(index+1, commandT.length()).trim(); + } + } + //TraceManager.addDev("Command handled"); + st.startTime = elt0.getAttribute("starttime"); + st.length = elt0.getAttribute("length"); + st.virtualLength = elt0.getAttribute("virtuallength"); + st.channelName = elt0.getAttribute("ch"); + + if (trans == null) { + trans = new Vector<SimulationTransaction>(); + } + + trans.add(st); + + TraceManager.addDev("Nb of trans:" + trans.size()); + + } + } + if (nl.getLength() > 0) { + updateTableOfTransactions(); + } + + } + + if (hashOK) { + if (elt.getTagName().compareTo(SIMULATION_TASK) == 0) { + id = null; + name = null; + command = null; + nextCommand = null; + progression = null; + startTime = null; finishTime = null; + transStartTime = null; transFinishTime = null; + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + nl = elt.getElementsByTagName("currcmd"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + if (node0.getNodeType() == Node.ELEMENT_NODE) { + elt0 = (Element)node0; + command = elt0.getAttribute("id"); + } + nl = elt.getElementsByTagName("progr"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + progression = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + nl = elt.getElementsByTagName("starttime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + startTime = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + nl = elt.getElementsByTagName("finishtime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + finishTime = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + nl = elt.getElementsByTagName("transstarttime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + transStartTime = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + nl = elt.getElementsByTagName("transfinishtime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + transFinishTime = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + nl = elt.getElementsByTagName("nextcmd"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + nextCommand = node0.getTextContent(); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + } + + } + + //System.out.println("Got info on task " + id + " command=" + command); + extime = null; + nl = elt.getElementsByTagName("extime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + extime = node0.getTextContent(); + } + + state = null; + nl = elt.getElementsByTagName("tskstate"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + state = node0.getTextContent(); + //TraceManager.addDev("TASK STATE: " + state); + } + + if ((id != null) && ((extime != null) || (state != null))) { + updateTaskCyclesAndState(id, extime, state); + } + + + if ((id != null) && (command != null)) { + if (nextCommand ==null) { + nextCommand = "-1"; + } + updateRunningCommand(id, command, progression, startTime, finishTime, nextCommand, transStartTime, transFinishTime, state); + } + + if (openDiagram.isEnabled() && openDiagram.isSelected() && (name != null) && (command != null)) { + updateOpenDiagram(name, command, progression, startTime, finishTime, transStartTime, transFinishTime); + } + + + + + nl = elt.getElementsByTagName("var"); + if ((nl != null) && (nl.getLength() > 0)) { + idvar = null; + value = null; + for(k=0; k<nl.getLength(); k++) { + node0 = nl.item(k); + value = node0.getTextContent(); + if (node0.getNodeType() == Node.ELEMENT_NODE) { + elt0 = (Element)node0; + idvar = elt0.getAttribute("id"); + } + if ((value != null) && (idvar != null)) { + updateVariableState(idvar, value); + jpsv.updateOnVariableValue(idvar); + } + } + } + } + + //System.out.println("toto1"); + + if (elt.getTagName().compareTo(SIMULATION_CPU) == 0) { + id = null; + name = null; + command = null; + contdel = null; + busname = null; + busid = null; + usedEnergy = null; + + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + nl = elt.getElementsByTagName("util"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + util = node0.getTextContent(); + } + nl = elt.getElementsByTagName("energy"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("energy NL? nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + usedEnergy = node0.getTextContent(); + } + + //System.out.println("toto12"); + nl = elt.getElementsByTagName("contdel"); + if ((nl != null) && (nl.getLength() > 0)) { + nl = elt.getElementsByTagName("contdel"); + node0 = nl.item(0); + elt0 = (Element)node0; + busid = elt0.getAttribute("busID"); + busname = elt0.getAttribute("busName"); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + contdel = node0.getTextContent(); + } + + //System.out.println("contdel: " + contdel + " busID:" + busid + " busName:" + busname); + + + if ((id != null) && (util != null)) { + updateCPUState(id, util, usedEnergy, contdel, busname, busid); + } + } + + //TraceManager.addDev("toto2"); + + if (elt.getTagName().compareTo(SIMULATION_BUS) == 0) { + id = null; + name = null; + command = null; + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + nl = elt.getElementsByTagName("util"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + util = node0.getTextContent(); + } + + //System.out.println("Got info on bus " + id + " util=" + util); + + if ((id != null) && (util != null)) { + updateBusState(id, util); + } + } + + //TraceManager.addDev("toto3 " + elt.getTagName()); + + + + + + } + } + } + } catch (Exception e) { + TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); + return false; + } + + if ((msg != null) && (error != null)) { + if (error.trim().equals("0")) { + printFromServer(msg + ": command successful"); + if (msg.indexOf("reset") != -1) { + time.setText("0"); + } + } else { + printFromServer(msg + ": command failed (error=" + error + ")"); + } + } else if (msg != null) { + printFromServer("Server: " + msg); + } else { + //TraceManager.addDev("Node: " +node1 + " diagramNL=" + diagramNl); + //printFromServer("Server: error " + error); + } + + if ((hash != null) && (tmap != null)) { + try { + int thehash = Integer.decode(hash).intValue(); + + if (thehash != hashCode) { + jta.append("\n*** Simulated model is not the model currently loaded under TTool ***\n"); + jta.append("*** Some features are therefore deactivated ***\n\n"); + hashOK = false; + wrongHashCode(); + } else { + askForUpdate(); + sendBreakPointList(); + jta.append("\n*** Simulated model is the one currently loaded under TTool ***\n"); + hashOK = true; + animate.setSelected(true); + animate.setEnabled(true); + diploids.setEnabled(true); + animateWithInfo.setSelected(true); + animateWithInfo.setEnabled(true); + openDiagram.setEnabled(true); + cpus.setEnabled(true); + busses.setEnabled(true); + mems.setEnabled(true); + tasks.setEnabled(true); + chans.setEnabled(true); + } + } catch (Exception e) { + } + } + + return true; + } + + private void wrongHashCode() { + TraceManager.addDev("Wrong hash code"); + + cpuPanel.setVisible(false); + variablePanel.setVisible(false); + openDiagram.setSelected(false); + openDiagram.setEnabled(false); + animate.setEnabled(false); + diploids.setEnabled(false); + animate.setSelected(false); + diploids.setSelected(false); + animateWithInfo.setSelected(false); + animateWithInfo.setEnabled(false); + update.setEnabled(false); + update.setSelected(false); + + cpus.setEnabled(false); + busses.setEnabled(false); + mems.setEnabled(false); + tasks.setEnabled(false); + chans.setEnabled(false); + cpus.removeAllItems(); + busses.removeAllItems(); + mems.removeAllItems(); + tasks.removeAllItems(); + chans.removeAllItems(); + + jpsv.setEnabled(false); + jpsv.unsetElements(); + + actions[InteractiveSimulationActions.ACT_RUN_TO_NEXT_BUS_TRANSFER].setEnabled(false); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CPU_EXECUTES].setEnabled(false); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_TASK_EXECUTES].setEnabled(false); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_MEMORY_ACCESS].setEnabled(false); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CHANNEL_ACCESS].setEnabled(false); + + // Set variable tab is removed + // + commandTab.removeTabAt(2); + jpsv = null; + + while(infoTab.getTabCount() > 2) { + infoTab.removeTabAt(2); + } + jpbp.unsetElements(); + + } + + public synchronized void startThread(int mode) { + threadMode = mode; + t = new Thread(this); + t.start(); + threadStarted = false; + //System.out.println("thread of mode:" + threadMode); + while(threadStarted == false) { + try { + wait(); + } catch (InterruptedException ie) {} + } + } + + public synchronized void threadStarted() { + TraceManager.addDev("thread started"); + threadStarted = true; + notify(); + } + + public void makeBrkReason(String s) { + info.setText(s); + } + + public void makeStatus(String s) { + //System.out.println("busystatus=" + busyStatus); + + if (s.equals("busy")) { + status.setText("Busy"); + setBusyStatus(); + busyMode = 2; + //busyStatus = true; + } + if (s.equals("ready")) { + status.setText("Ready"); + if (busyMode == 2) { + //System.out.println("Sending time command"); + askForUpdate(); + //sendCommand("time"); + } + busyMode = 1; + setBusyStatus(); + } + + if (s.equals("term")) { + status.setText("Terminated"); + if (busyMode == 2) { + askForUpdate(); + } + busyMode = 3; + setBusyStatus(); + + //System.out.println("**** TERM ****"); + } + setLabelColors(); + } + + public void setBusyStatus() { + setAll(); + actions[InteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(busyMode == 2); + } + + public void setLabelColors() { + switch(busyMode) { + case 0: + status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); + break; + case 1: + status.setForeground(ColorManager.InteractiveSimulationText_READY); + time.setForeground(ColorManager.InteractiveSimulationText_READY); + info.setForeground(ColorManager.InteractiveSimulationText_READY); + break; + case 2: + status.setForeground(ColorManager.InteractiveSimulationText_BUSY); + time.setForeground(ColorManager.InteractiveSimulationText_BUSY); + info.setForeground(ColorManager.InteractiveSimulationText_BUSY); + break; + case 3: + status.setForeground(ColorManager.InteractiveSimulationText_TERM); + time.setForeground(ColorManager.InteractiveSimulationText_TERM); + info.setForeground(ColorManager.InteractiveSimulationText_TERM); + break; + } + + + } + + public void setAll() { + boolean b = false;; + if (busyMode == 1) { + b = true; + } + actions[InteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_X_TIME_UNITS].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_TO_TIME].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_X_TRANSACTIONS].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(b); + actions[InteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_EXPLORATION].setEnabled(b); + + if (jpsv != null) { + jpsv.setVariableButton(b); + } + + if(busyMode == 3) { + actions[InteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true); + } + + if (!hashOK) { + b = false; + } + + actions[InteractiveSimulationActions.ACT_RUN_TO_NEXT_BUS_TRANSFER].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CPU_EXECUTES].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_TASK_EXECUTES].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_MEMORY_ACCESS].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CHANNEL_ACCESS].setEnabled(b); + + if((busyMode == 0) || (busyMode == 2)) { + b = false; + } else { + b = true; + } + + actions[InteractiveSimulationActions.ACT_SAVE_VCD].setEnabled(b); + actions[InteractiveSimulationActions.ACT_SAVE_HTML].setEnabled(b); + actions[InteractiveSimulationActions.ACT_SAVE_TXT].setEnabled(b); + actions[InteractiveSimulationActions.ACT_PRINT_BENCHMARK].setEnabled(b); + actions[InteractiveSimulationActions.ACT_SAVE_BENCHMARK].setEnabled(b); + actions[InteractiveSimulationActions.ACT_SAVE_STATE].setEnabled(b); + actions[InteractiveSimulationActions.ACT_RESTORE_STATE].setEnabled(b); + } + + public static String decodeString(String s) { + if (s == null) + return s; + byte b[] = null; + try { + b = s.getBytes("ISO-8859-1"); + return new String(b); + } catch (Exception e) { + return null; + } + } + + public void printFromServer(String s) { + jta.append("Server> " + s + "\n"); + } + + + // Mouse management + public void mouseReleased(MouseEvent e) {} + + + + /** + * This adapter is constructed to handle mouse over component events. + */ + private class MouseHandler extends MouseAdapter { + + private JLabel label; + + /** + * ctor for the adapter. + * @param label the JLabel which will recieve value of the + * Action.LONG_DESCRIPTION key. + */ + public MouseHandler(JLabel label) { + setLabel(label); + } + + public void setLabel(JLabel label) { + this.label = label; + } + + public void mouseEntered(MouseEvent evt) { + if (evt.getSource() instanceof AbstractButton) { + AbstractButton button = (AbstractButton)evt.getSource(); + Action action = button.getAction(); + if (action != null) { + String message = (String)action.getValue(Action.LONG_DESCRIPTION); + label.setText(message); + } + } + } + } + + public void sendCommandWithPositiveInt(String command) { + String param = paramMainCommand.getText().trim(); + if (isAPositiveInt(param)) { + sendCommand(command + " " + param); + } else { + error("Wrong parameter: must be a positive int"); + } + } + + public void sendSaveTraceCommand(String format) { + String param = saveFileName.getText().trim(); + if (saveDirName.getText().length() > 0) { + param = saveDirName.getText() + File.separator + param; + } + if (param.length() >0) { + sendCommand("save-trace-in-file" + " " + format + " " + param); + } else { + error("Wrong parameter: must be a file name"); + } + } + + public void sendSaveStateCommand() { + String param = stateFileName.getText().trim(); + if (param.length() >0) { + sendCommand("save-simulation-state-in-file " + param); + } else { + error("Wrong parameter: must be a file name"); + } + } + + public void sendRestoreStateCommand() { + String param = stateFileName.getText().trim(); + if (param.length() >0) { + sendCommand("restore-simulation-state-from-file " + param); + } else { + error("Wrong parameter: must be a file name"); + } + } + + public void sendSaveBenchmarkCommand() { + String param = benchmarkFileName.getText().trim(); + if (param.length() >0) { + sendCommand("get-benchmark 1 " + param); + } else { + error("Wrong benchmark parameter: must be a file name"); + } + } + + private void runExploration() { + animate.setSelected(false); + mgui.setDiploAnimate(animate.isSelected()); + diploids.setEnabled(animate.isSelected()); + animateWithInfo.setEnabled(animate.isSelected()); + openDiagram.setEnabled(animate.isSelected()); + update.setSelected(false); + sendCommand("run-exploration " + minimalCommandCoverage.getValue() + " " + minimalBranchCoverage.getValue()); + } + + + + private void updateVariables() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + sendCommand("get-variable-of-task all all\n"); + + /*for(TMLTask task: tmap.getTMLModeling().getTasks()) { + for(TMLAttribute tmla: task.getAttributes()) { + sendCommand("get-variable-of-task " + task.getID() + " " + tmla.getID()); + } + }*/ + } + + private void updateCPUs() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { + if ((node instanceof HwCPU) || (node instanceof HwA)){ + sendCommand("get-info-on-hw 0 " + node.getID()); + } + } + } + + private void updateMemories() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwMemory) { + sendCommand("get-info-on-hw 2 " + node.getID()); + } + } + } + + private void updateBus() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwBus) { + sendCommand("get-info-on-hw 1 " + node.getID()); + } + } + } + + private void updateTasks() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + for(TMLTask task: tmap.getTMLModeling().getTasks()) { + sendCommand("get-info-on-hw 5 " + task.getID()); + } + } + + private void updateTransactions() { + if (mode != STARTED_AND_CONNECTED) { + return; + } + + trans = null; + sendCommand("lt 10"); + } + + private void updateTaskCommands() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + sendCommand("get-command-of-task all"); + + /*for(TMLTask task: tmap.getTMLModeling().getTasks()) { + sendCommand("get-command-of-task " + task.getID()); + }*/ + } + + private void updateExecutedCommands() { + if (tmap == null) { + return; + } + + if (mode != STARTED_AND_CONNECTED) { + return; + } + + sendCommand("get-executed-operators"); + } + + + + private void updateRunningCommand(String id, String command, String progression, String startTime, String finishTime, String nextCommand, String transStartTime, String transFinishTime, String _state) { + Integer i = getInteger(id); + Integer c = getInteger(command); + Integer nc = getInteger(nextCommand); + + if (_state == null) { + _state = tasktm.getState(valueTable.get(new Integer(id))); + } + + TraceManager.addDev("state:" + _state); + + if ((i != null) && (c != null)) { + try { + //System.out.println("Searching for old value"); + Integer old = runningTable.get(i); + if(old != null) { + mgui.removeRunningId(old); + runningTable.remove(old); + } + + runningTable.put(i, c); + //System.out.println("Adding running command: " +c); + mgui.addRunningID(c, nc, progression, startTime, finishTime, transStartTime, transFinishTime, _state); + } catch (Exception e) { + TraceManager.addDev("Exception updateRunningCommand: " + e.getMessage()); + } + } + + } + + private void updateOpenDiagram(String name, String _command, String _progression, String _startTime, String _finishTime, String _transStartTime, String _transFinishTime) { + //System.out.println("UpdateOpenDiagram name=" + name + " for command:" + command); + if (tmap == null) { + return; + } + + String command = _command; + if (_progression != null) { + command += _progression; + } + if (_startTime != null) { + command += _startTime; + } + if (_finishTime != null) { + command += _finishTime; + } + if (_transStartTime != null) { + command += _transStartTime; + } + if (_transFinishTime != null) { + command += _transFinishTime; + } + + String cmd = diagramTable.get(name); + if (cmd == null) { + diagramTable.put(name, command); + //return; + } + + if ((cmd == null) || (!(cmd.equals(command)))) { + diagramTable.remove(name); + diagramTable.put(name, command); + + String diag = ""; + String tab = name; + int index = tab.indexOf("__"); + if (index != -1) { + diag = tab.substring(0, index); + tab = tab.substring(index+2, tab.length()); + } + //System.out.println("Opening diagram " + tab + " for command:" + command); + + mgui.openTMLTaskActivityDiagram(diag, tab); + } + } + + + + private void printCPUs() { + if (latex.isSelected()) { + String name; + String tmp, tmp1; + int index, index1; + jta.append("\\begin{tabular}{|l|c|c|}\n"); + jta.append("\\hline\n"); + jta.append("\\texbf{CPU} & \\textbf{Load} & \\textbf{Contention delay}\n"); + jta.append("\\hline\n"); + for(int i=0; i<cputm.getRowCount(); i++) { + name = (String)(cputm.getValueAt(i, 0)); + tmp = (String)(cputm.getValueAt(i, 2)); + jta.append(Conversion.toLatex(name) + " &"); + index = tmp.indexOf(';'); + if (index == -1) { + jta.append(" - & - \\\\\n"); + } else { + + + tmp1 = tmp.substring(0, index); + index1 = tmp1.indexOf(':'); + if (index1 != -1) { + tmp1 = tmp1.substring(index1 + 2, tmp1.length()); + } + jta.append("" + tmp1 + " &"); + tmp1 = tmp.substring(index+1, tmp.length()); + index1 = tmp1.indexOf(':'); + if (index1 != -1) { + tmp1 = tmp1.substring(index1 + 2, tmp1.length()); + } + jta.append("" + tmp1 + "\\\\\n"); + } + } + jta.append("\\hline\n"); + } else { + String name; + String tmp, tmp1; + int index, index1; + jta.append("\nCPUs:\n"); + for(int i=0; i<cputm.getRowCount(); i++) { + name = (String)(cputm.getValueAt(i, 0)); + tmp = (String)(cputm.getValueAt(i, 2)); + jta.append("* " + name + "\n"); + index = tmp.indexOf(';'); + if (index == -1) { + jta.append("\t - \n"); + } else { + jta.append("\t" + tmp.substring(0, index) + "\n"); + jta.append("\t" + tmp.substring(index+1, tmp.length()) + "\n"); + } + } + } + } + + private void printBuses() { + if (latex.isSelected()) { + String name; + String tmp, tmp1; + int index, index1; + jta.append("\\begin{tabular}{|l|c|c|}\n"); + jta.append("\\hline\n"); + jta.append("\\texbf{CPU} & \\textbf{Load} & \\textbf{Contention delay}\n"); + jta.append("\\hline\n"); + for(int i=0; i<bustm.getRowCount(); i++) { + name = (String)(bustm.getValueAt(i, 0)); + tmp = (String)(bustm.getValueAt(i, 2)); + jta.append(Conversion.toLatex(name) + " &"); + index = tmp.indexOf(':'); + if (index == -1) { + jta.append(" - \\\\\n"); + } else { + tmp1 = tmp.substring(index+2, tmp.length()); + jta.append("" + tmp1 + "\\\\\n"); + } + } + jta.append("\\hline\n"); + } else { + String name; + String tmp; + jta.append("\nBuses:\n"); + for(int i=0; i<bustm.getRowCount(); i++) { + name = (String)(bustm.getValueAt(i, 0)); + tmp = (String)(bustm.getValueAt(i, 2)); + jta.append("* " + name + "\n"); + jta.append("\t" + tmp + "\n"); + } + } + } + + private void updateVariableState(String _idvar, String _value) { + Integer i = getInteger(_idvar); + int row; + if (i != null) { + try { + valueTable.remove(i); + valueTable.put(i, _value); + //System.out.println("Searching for old row"); + row = (Integer)(rowTable.get(i)).intValue(); + tvtm.fireTableCellUpdated(row, 4); + } catch (Exception e) { + TraceManager.addDev("Exception updateVariableState: " + e.getMessage() + " idvar=" + _idvar + " val=" + _value); + } + } + } -import myutil.*; -import ui.*; -import ui.file.*; + private void updateTaskCyclesAndState(String _id, String _extime, String _state) { + Integer i = getInteger(_id); + Integer ex = getInteger(_extime); + int row; -import tmltranslator.*; + String s = ""; + if (_state != null) { + s += _state; + } + s += ";"; + if (_extime != null) { + s+= _extime; + } -import launcher.*; -import remotesimulation.*; -import org.w3c.dom.*; -import org.xml.sax.*; -import javax.xml.parsers.*; + if ((i != null) && (ex != null)) { + try { + valueTable.remove(i); + valueTable.put(i, s); + //System.out.println("Searching for old row"); + row = rowTable.get(i).intValue(); + if (_state != null) { + tasktm.fireTableCellUpdated(row, 2); + } + if (_extime != null) { + tasktm.fireTableCellUpdated(row, 3); + } -public class JFrameInteractiveSimulation extends JFrame implements ActionListener, Runnable, MouseListener, ItemListener, ChangeListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { - - protected static final String SIMULATION_HEADER = "siminfo"; - protected static final String SIMULATION_GLOBAL = "global"; - protected static final String SIMULATION_TASK = "task"; - protected static final String SIMULATION_CPU = "cpu"; - protected static final String SIMULATION_BUS = "bus"; - protected static final String SIMULATION_COMMAND = "cmd"; - - private static String buttonStartS = "Start simulator"; - private static String buttonCloseS = "Close"; - private static String buttonStopAndCloseS = "Stop simulator and close"; - - private static int NOT_STARTED = 0; - private static int STARTING = 1; - private static int STARTED_NOT_CONNECTED = 2; - private static int STARTED_AND_CONNECTED = 3; - - private Frame f; - private MainGUI mgui; - private String title; - private String hostSystemC; - private String pathExecute; - - protected JButton buttonClose, buttonStart, buttonStopAndClose; - protected JTextArea jta; - protected JScrollPane jsp; - - protected Thread t; - protected int threadMode = 0; - protected boolean go; - protected RshClient rshc; - protected RemoteConnection rc; - protected CommandParser cp; - protected String ssxml; - - // Text commands - protected JTextField textCommand; - protected JButton sendTextCommand, printHelpTextCommands, listTextCommands; - //private static String sendTextCommandS = "Send Command"; - - // Control command - protected JButton resetCommand, runCommand, StopCommand; - protected MainCommandsToolBar mctb; - protected SaveCommandsToolBar sctb; - protected StateCommandsToolBar stctb; - protected BenchmarkCommandsToolBar bctb; - protected FormalVerificationToolBar fvtb; - - - // Commands - JPanel main, mainTop, commands, save, state, infos, outputs, cpuPanel, variablePanel; // from MGUI - JCheckBox latex, debug, animate, diploids, update, openDiagram, animateWithInfo; - JTabbedPane commandTab, infoTab; - protected JTextField paramMainCommand; - protected JTextField saveDirName; - protected JTextField saveFileName; - protected JTextField stateFileName; - protected JTextField benchmarkFileName; - protected JComboBox cpus, busses, mems, tasks, chans; - - - private String[] cpuIDs, busIDs, memIDs, taskIDs, chanIDs; - - // Status elements - JLabel status, time, info; - - // Task elements - TaskVariableTableModel tvtm; - JButton updateTaskVariableInformationButton; - private JScrollPane jspTaskVariableInfo; - - // Breakpoints - JPanelBreakPoints jpbp; - - // Set variables - JPanelSetVariables jpsv; - - // Formal verification - JSlider minimalCommandCoverage, minimalBranchCoverage; - JLabel labelMinimalCommandCoverage, labelMinimalBranchCoverage; - - // Tasks - JPanel taskPanel; - TaskTableModel tasktm; - JButton updateTaskInformationButton; - private JScrollPane jspTaskInfo; - - // CPU - CPUTableModel cputm; - JButton updateCPUInformationButton, printCPUInfo; - private JScrollPane jspCPUInfo; - private JPanel panelCPU; - - // Memories - JPanel memPanel; - MemTableModel memtm; - JButton updateMemoryInformationButton, printBusInfo; - private JScrollPane jspMemInfo; - - // Bus - JPanel busPanel; - BusTableModel bustm; - JButton updateBusInformationButton; - private JScrollPane jspBusInfo; - private JPanel panelBus; - - - private int mode = 0; - //private boolean busyStatus = false; - private int busyMode = 0; // 0: unknown; 1: ready; 2:busy; 3:term - private boolean threadStarted = false; - private boolean gotTimeAnswerFromServer = false; - - // For managing actions - public InteractiveSimulationActions [] actions; - public MouseHandler mouseHandler; - public KeyListener keyHandler; - - private TMLMapping tmap; - private int hashCode; - private boolean hashOK = true; - - private Hashtable <Integer, String> valueTable; - private Hashtable <Integer, Integer> rowTable; - - private Hashtable <Integer, Integer> runningTable; - private Hashtable <String, String> diagramTable; - - private ArrayList<Point> points; - - public JFrameInteractiveSimulation(Frame _f, MainGUI _mgui, String _title, String _hostSystemC, String _pathExecute, TMLMapping _tmap, ArrayList<Point> _points) { - super(_title); - - f = _f; - mgui = _mgui; - title = _title; - hostSystemC = _hostSystemC; - pathExecute = _pathExecute; - - mode = NOT_STARTED; - - tmap = _tmap; - if (tmap != null) { - tmap.makeMinimumMapping(); - hashCode = tmap.getHashCode(); - tmap.getTMLModeling().computeCorrespondance(); - } else { - hashOK = false; - } - - points = _points; - - //System.out.println("Tmap=" + tmap); - - valueTable = new Hashtable<Integer, String>(); - rowTable = new Hashtable<Integer, Integer>(); - runningTable = new Hashtable<Integer, Integer>(); - diagramTable = new Hashtable<String, String>(); - - - mgui.resetRunningID(); - mgui.resetLoadID(); - - setBackground(new Color(50, 40, 40)); - - initActions(); - makeComponents(); - setComponents(); - } - - private JLabel createStatusBar() { - status = new JLabel("Ready..."); - status.setForeground(ColorManager.InteractiveSimulationText); - status.setBorder(BorderFactory.createEtchedBorder()); - return status; - } - - public void makeComponents() { - JPanel jp01, jp02; - //jp01.setPreferredSize(new Dimension(375, 400)); - GridBagLayout gridbag01; - GridBagConstraints c01 ; - - cp = new CommandParser(); - - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - Container framePanel = getContentPane(); - framePanel.setLayout(new BorderLayout()); - //framePanel.setBackground(ColorManager.InteractiveSimulationBackground); - //framePanel.setForeground(new Color(255, 166, 38)); - - //System.out.println("Button start created"); - buttonStart = new JButton(actions[InteractiveSimulationActions.ACT_START_ALL]); - buttonClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_ALL]); - buttonStopAndClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_AND_CLOSE_ALL]); - //buttonStopAndClose = new JButton(buttonStopAndCloseS, IconManager.imgic27); - - - - - - // statusBar - status = createStatusBar(); - framePanel.add(status, BorderLayout.SOUTH); - - // Mouse handler - mouseHandler = new MouseHandler(status); - - JPanel mainpanel = new JPanel(new BorderLayout()); - //mainpanel.setBackground(ColorManager.InteractiveSimulationBackground); - framePanel.add(mainpanel, BorderLayout.NORTH); - - JPanel jp = new JPanel(); - //jp.setBackground(ColorManager.InteractiveSimulationBackground); - //jp.setPreferredSize(new Dimension(800, 75)); - jp.add(buttonStart); - jp.add(buttonStopAndClose); - jp.add(buttonClose); - mainpanel.add(jp, BorderLayout.NORTH); - - - GridBagLayout gridbag02 = new GridBagLayout(); - GridBagConstraints c02 = new GridBagConstraints(); - mainTop = new JPanel(gridbag02); - //mainTop.setPreferredSize(new Dimension(800, 375)); - c02.gridheight = 1; - c02.weighty = 1.0; - c02.weightx = 1.0; - c02.gridwidth = 1; - c02.fill = GridBagConstraints.BOTH; - c02.gridheight = 1; - - // Ouput textArea - jta = new ScrolledJTextArea(); - jta.setBackground(ColorManager.InteractiveSimulationJTABackground); - jta.setForeground(ColorManager.InteractiveSimulationJTAForeground); - jta.setMinimumSize(new Dimension(800, 400)); - jta.setRows(15); - //jta.setMaximumSize(new Dimension(800, 500)); - jta.setEditable(false); - jta.setMargin(new Insets(10, 10, 10, 10)); - jta.setTabSize(3); - jta.append("Click on \"Connect\" to start the remote simulator and connect to it\n"); - Font f = new Font("Courrier", Font.BOLD, 12); - jta.setFont(f); - jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - jsp.setViewportBorder(BorderFactory.createLineBorder(ColorManager.InteractiveSimulationBackground)); - - //jsp.setColumnHeaderView(100); - //jsp.setRowHeaderView(30); - - - jsp.setMaximumSize(new Dimension(800, 500)); - JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, mainTop, jsp); - //split.setBackground(ColorManager.InteractiveSimulationBackground); - mainpanel.add(split, BorderLayout.CENTER); - - // Commands - commands = new JPanel(); - //commands.setFloatable(true); - //commands.setMinimumSize(new Dimension(300, 250)); - commands.setBorder(new javax.swing.border.TitledBorder("Commands")); - - - mainTop.add(commands, c02); - - commandTab = new JTabbedPane(); - //commandTab.setBackground(ColorManager.InteractiveSimulationBackground); - - // Control commands - jp01 = new JPanel(new BorderLayout()); - //jp01.setMinimumSize(new Dimension(375, 400)); - //gridbag01 = new GridBagLayout(); - //c01 = new GridBagConstraints(); - //jp01.setLayout(gridbag01); - - commandTab.addTab("Control", null, jp01, "Main control commands"); - - - mctb = new MainCommandsToolBar(this); - jp01.add(mctb, BorderLayout.NORTH); - - jp02 = new JPanel(); - //jp01.setPreferredSize(new Dimension(375, 400)); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp02.setLayout(gridbag01); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = 1; - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - jp02.add(new JLabel("Command parameter: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - paramMainCommand = new JTextField("1", 30); - jp02.add(paramMainCommand, c01); - - c01.gridwidth = 1; - jp02.add(new JLabel("CPUs and HwA: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - if (cpuIDs == null) { - cpus = new JComboBox(); - } else { - cpus = new JComboBox(cpuIDs); - } - jp02.add(cpus, c01); - - c01.gridwidth = 1; - jp02.add(new JLabel("Busses: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - if (busIDs == null) { - busses = new JComboBox(); - } else { - busses = new JComboBox(busIDs); - } - jp02.add(busses, c01); - - c01.gridwidth = 1; - jp02.add(new JLabel("Memories: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - if (memIDs == null) { - mems = new JComboBox(); - } else { - mems = new JComboBox(memIDs); - } - jp02.add(mems, c01); - - c01.gridwidth = 1; - jp02.add(new JLabel("Tasks: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - if (taskIDs == null) { - tasks = new JComboBox(); - } else { - tasks = new JComboBox(taskIDs); - } - jp02.add(tasks, c01); - - c01.gridwidth = 1; - jp02.add(new JLabel("Channels: "), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - if (chanIDs == null) { - chans = new JComboBox(); - } else { - chans = new JComboBox(chanIDs); - } - jp02.add(chans, c01); - - jp01.add(jp02, BorderLayout.CENTER); - - - // Text commands - jp01 = new JPanel(); - //jp01.setPreferredSize(new Dimension(375, 400)); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp01.setLayout(gridbag01); - - commandTab.addTab("Text commands", null, jp01, "Sending text commands to simulator"); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - c01.gridheight = 2; - jp01.add(new JLabel("Enter a text command:"), c01); - textCommand = new JTextField(30); - jp01.add(textCommand, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - sendTextCommand = new JButton("Send Command", IconManager.imgic71); - sendTextCommand.addMouseListener(this); - jp01.add(sendTextCommand, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - printHelpTextCommands = new JButton("Help on a text command", IconManager.imgic33); - printHelpTextCommands.addMouseListener(this); - jp01.add(printHelpTextCommands, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - listTextCommands = new JButton("List all text commands", IconManager.imgic29); - listTextCommands.addMouseListener(this); - jp01.add(listTextCommands, c01); - - commands.add(commandTab); - - // Set variables - jpsv = new JPanelSetVariables(this, valueTable); - commandTab.addTab("Set variables", null, jpsv, "Set variables"); - - // Save commands - jp01 = new JPanel(new BorderLayout()); - - commandTab.addTab("Save trace", null, jp01, "Save commands"); - - sctb = new SaveCommandsToolBar(this); - jp01.add(sctb, BorderLayout.NORTH); - - jp02 = new JPanel(); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp02.setLayout(gridbag01); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - jp02.add(new JLabel("Directory:"), c01); - saveDirName = new JTextField(30); - if (ConfigurationTTool.SystemCCodeDirectory != null) { - saveDirName.setText(ConfigurationTTool.SystemCCodeDirectory); - } - jp02.add(saveDirName, c01); - jp02.add(new JLabel("File name:"), c01); - saveFileName = new JTextField(30); - jp02.add(saveFileName, c01); - - jp01.add(jp02, BorderLayout.CENTER); - - // State commands - jp01 = new JPanel(new BorderLayout()); - - commandTab.addTab("Save / restore state", null, jp01, "Save commands"); - - stctb = new StateCommandsToolBar(this); - jp01.add(stctb, BorderLayout.NORTH); - - jp02 = new JPanel(); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp02.setLayout(gridbag01); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - jp02.add(new JLabel("File name:"), c01); - stateFileName = new JTextField(30); - jp02.add(stateFileName, c01); - - jp01.add(jp02, BorderLayout.CENTER); - - // Benchmark commands - jp01 = new JPanel(new BorderLayout()); - - commandTab.addTab("Benchmarks", null, jp01, "Benchmarks"); - - bctb = new BenchmarkCommandsToolBar(this); - jp01.add(bctb, BorderLayout.NORTH); - - jp02 = new JPanel(); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp02.setLayout(gridbag01); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - jp02.add(new JLabel("File name:"), c01); - benchmarkFileName = new JTextField(30); - jp02.add(benchmarkFileName, c01); - - jp01.add(jp02, BorderLayout.CENTER); - - // Formal verification - jp01 = new JPanel(new BorderLayout()); - - commandTab.addTab("Formal verification", null, jp01, "Formal verification"); - - fvtb = new FormalVerificationToolBar(this); - jp01.add(fvtb, BorderLayout.NORTH); - - jp02 = new JPanel(); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp02.setLayout(gridbag01); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - // First empty line - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01); - - // Line minimum command: labels - c01.gridwidth = 1; - jp02.add(new JLabel("minimum COMMAND coverage"), c01); - labelMinimalCommandCoverage = new JLabel("100%"); - c01.fill = GridBagConstraints.CENTER; - jp02.add(labelMinimalCommandCoverage, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - jp02.add(new JLabel(" "), c01); - - // Line minimum command: slider - c01.gridwidth = 1; - jp02.add(new JLabel(" "), c01); - minimalCommandCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); - minimalCommandCoverage.setValue(100); - minimalCommandCoverage.setMajorTickSpacing(10); - minimalCommandCoverage.setMinorTickSpacing(1); - minimalCommandCoverage.setPaintTicks(true); - minimalCommandCoverage.setPaintLabels(true); - minimalCommandCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); - minimalCommandCoverage.addChangeListener(this); - Font font = new Font("Serif", Font.ITALIC, 10); - minimalCommandCoverage.setFont(font); - jp02.add(minimalCommandCoverage, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01); - - // One empty line - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01); - - // Line minimum command: labels - c01.gridwidth = 1; - jp02.add(new JLabel("minimum BRANCH coverage"), c01); - labelMinimalBranchCoverage = new JLabel("100%"); - c01.fill = GridBagConstraints.CENTER; - jp02.add(labelMinimalBranchCoverage, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - jp02.add(new JLabel(" "), c01); - - // Line minimum branch: slider - c01.gridwidth = 1; - jp02.add(new JLabel(" "), c01); - minimalBranchCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); - minimalBranchCoverage.setValue(100); - minimalBranchCoverage.setMajorTickSpacing(10); - minimalBranchCoverage.setMinorTickSpacing(1); - minimalBranchCoverage.setPaintTicks(true); - minimalBranchCoverage.setPaintLabels(true); - minimalBranchCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); - minimalBranchCoverage.addChangeListener(this); - minimalBranchCoverage.setFont(font); - jp02.add(minimalBranchCoverage, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01); - - // Last empty line - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01); - - /*c01.gridwidth = 1; - jp02.add(new JLabel("minimum BRANCH coverage"), c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - labelMinimalBranchCoverage = new JLabel("100%"); - c01.fill = GridBagConstraints.EAST; - jp02.add(labelMinimalBranchCoverage, c01); - c01.fill = GridBagConstraints.BOTH; - minimalBranchCoverage = new JSlider(JSlider.HORIZONTAL, 0, 100, 100); - minimalBranchCoverage.setValue(100); - minimalBranchCoverage.setMajorTickSpacing(10); - minimalBranchCoverage.setMinorTickSpacing(1); - minimalBranchCoverage.setPaintTicks(true); - minimalBranchCoverage.setPaintLabels(true); - minimalBranchCoverage.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); - minimalBranchCoverage.addChangeListener(this); - minimalBranchCoverage.setFont(font); - c01.gridwidth = 1; //end row - jp02.add(new JLabel(" "), c01); - jp02.add(minimalBranchCoverage, c01); - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - jp02.add(new JLabel(" "), c01);*/ - jp01.add(jp02, BorderLayout.CENTER); - - - //Info - infos = new JPanel(new BorderLayout()); - infos.setMinimumSize(new Dimension(300, 250)); - //infos.setPreferredSize(new Dimension(400, 450)); - infos.setBorder(new javax.swing.border.TitledBorder("Simulation information")); - c02.gridwidth = GridBagConstraints.REMAINDER; //end row - mainTop.add(infos, c02); - - infoTab = new JTabbedPane(); - infoTab.setMinimumSize(new Dimension(300, 250)); - infos.add(infoTab, BorderLayout.NORTH); - - // Simulation time - jp02 = new JPanel(); - infos.add(jp02, BorderLayout.SOUTH); - jp02.add(new JLabel("Status:")); - status = new JLabel("Unknown"); - status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - jp02.add(status); - jp02.add(new JLabel(" ")); - jp02.add(new JLabel("Time:")); - time = new JLabel("Unknown"); - time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - jp02.add(time); - jp02.add(new JLabel(" ")); - jp02.add(new JLabel("Sim. interrupt reason:")); - info = new JLabel("Unknown"); - info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - jp02.add(info); - - // Options - jp01 = new JPanel(); - //jp01.setMinimumSize(new Dimension(375, 400)); - //jp01.setPreferredSize(new Dimension(375, 400)); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp01.setLayout(gridbag01); - - - // INFORMATION - - infoTab.addTab("Options", null, jp01, "Options on simulation"); - - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - - jp01.add(new JLabel(" "), c01); - latex = new JCheckBox("Generate info in Latex format"); - jp01.add(latex, c01); - debug = new JCheckBox("Print messages received from server"); - jp01.add(debug, c01); - animate = new JCheckBox("Animate UML diagrams"); - jp01.add(animate, c01); - diploids = new JCheckBox("Show DIPLO IDs on UML diagrams"); - jp01.add(diploids, c01); - diploids.addItemListener(this); - diploids.setSelected(false); - animateWithInfo = new JCheckBox("Show transaction progression on UML diagrams"); - jp01.add(animateWithInfo, c01); - animateWithInfo.addItemListener(this); - animateWithInfo.setSelected(true); - openDiagram = new JCheckBox("Automatically open active task diagram"); - jp01.add(openDiagram, c01); - openDiagram.setSelected(true); - update = new JCheckBox("Automatically update information (task, CPU, etc.)"); - jp01.add(update, c01); - update.addItemListener(this); - update.setSelected(true); - - animate.addItemListener(this); - animate.setSelected(true); - - - TableSorter sorterPI; - JTable jtablePI; - - // Breakpoints - jpbp = new JPanelBreakPoints(this, points); - infoTab.addTab("Breakpoints", null, jpbp, "List of active breakpoints"); - - // Tasks - taskPanel = new JPanel(); - taskPanel.setLayout(new BorderLayout()); - infoTab.addTab("Tasks", IconManager.imgic1202, taskPanel, "Current state of tasks"); - if (tmap == null) { - tasktm = new TaskTableModel(null, valueTable, rowTable); - } else { - tasktm = new TaskTableModel(tmap.getTMLModeling(), valueTable, rowTable); - } - - sorterPI = new TableSorter(tasktm); - jtablePI = new JTable(sorterPI); - sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); - ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(80); - ((jtablePI.getColumnModel()).getColumn(3)).setPreferredWidth(300); - jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - jspTaskInfo = new JScrollPane(jtablePI); - jspTaskInfo.setWheelScrollingEnabled(true); - jspTaskInfo.getVerticalScrollBar().setUnitIncrement(10); - jspTaskInfo.setPreferredSize(new Dimension(500, 300)); - taskPanel.add(jspTaskInfo, BorderLayout.NORTH); - updateTaskInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_TASKS]); - taskPanel.add(updateTaskInformationButton, BorderLayout.SOUTH); - - // Variables - variablePanel = new JPanel(); - variablePanel.setLayout(new BorderLayout()); - infoTab.addTab("Tasks variables", null, variablePanel, "Current value of variables"); - if (tmap == null) { - tvtm = new TaskVariableTableModel(null, valueTable, rowTable); - } else { - tvtm = new TaskVariableTableModel(tmap.getTMLModeling(), valueTable, rowTable); - } - sorterPI = new TableSorter(tvtm); - jtablePI = new JTable(sorterPI); - sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(60); - ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(3)).setPreferredWidth(60); - ((jtablePI.getColumnModel()).getColumn(4)).setPreferredWidth(100); - jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - jspTaskVariableInfo = new JScrollPane(jtablePI); - jspTaskVariableInfo.setWheelScrollingEnabled(true); - jspTaskVariableInfo.getVerticalScrollBar().setUnitIncrement(10); - jspTaskVariableInfo.setPreferredSize(new Dimension(500, 300)); - variablePanel.add(jspTaskVariableInfo, BorderLayout.NORTH); - updateTaskVariableInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_VARIABLES]); - variablePanel.add(updateTaskVariableInformationButton, BorderLayout.SOUTH); - - // CPUs - cpuPanel = new JPanel(); - cpuPanel.setLayout(new BorderLayout()); - infoTab.addTab("CPUs/HwA", IconManager.imgic1100, cpuPanel, "Current state of CPUs and hardware accelerators"); - cputm = new CPUTableModel(tmap, valueTable, rowTable); - sorterPI = new TableSorter(cputm); - jtablePI = new JTable(sorterPI); - sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); - ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(700); - jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - jspCPUInfo = new JScrollPane(jtablePI); - jspCPUInfo.setWheelScrollingEnabled(true); - jspCPUInfo.getVerticalScrollBar().setUnitIncrement(10); - jspCPUInfo.setPreferredSize(new Dimension(500, 300)); - cpuPanel.add(jspCPUInfo, BorderLayout.NORTH); - panelCPU = new JPanel(new FlowLayout()); - updateCPUInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_CPUS]); - panelCPU.add(updateCPUInformationButton); - printCPUInfo = new JButton(actions[InteractiveSimulationActions.ACT_PRINT_CPUS]); - panelCPU.add(printCPUInfo); - cpuPanel.add(panelCPU, BorderLayout.SOUTH); - - // Memories - memPanel = new JPanel(); - memPanel.setLayout(new BorderLayout()); - infoTab.addTab("Memories", IconManager.imgic1108, memPanel, "Current state of Memories"); - MemTableModel memtm = new MemTableModel(tmap, valueTable, rowTable); - sorterPI = new TableSorter(memtm); - jtablePI = new JTable(sorterPI); - sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); - ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(300); - jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - jspMemInfo = new JScrollPane(jtablePI); - jspMemInfo.setWheelScrollingEnabled(true); - jspMemInfo.getVerticalScrollBar().setUnitIncrement(10); - jspMemInfo.setPreferredSize(new Dimension(500, 300)); - memPanel.add(jspMemInfo, BorderLayout.NORTH); - updateMemoryInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_MEMS]); - memPanel.add(updateMemoryInformationButton, BorderLayout.SOUTH); - - // Busses - busPanel = new JPanel(); - busPanel.setLayout(new BorderLayout()); - infoTab.addTab("Bus", IconManager.imgic1102, busPanel, "Current state of busses"); - bustm = new BusTableModel(tmap, valueTable, rowTable); - sorterPI = new TableSorter(bustm); - jtablePI = new JTable(sorterPI); - sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(75); - ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(300); - jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - jspBusInfo = new JScrollPane(jtablePI); - jspBusInfo.setWheelScrollingEnabled(true); - jspBusInfo.getVerticalScrollBar().setUnitIncrement(10); - jspBusInfo.setPreferredSize(new Dimension(500, 300)); - busPanel.add(jspBusInfo, BorderLayout.NORTH); - panelBus = new JPanel(new FlowLayout()); - updateBusInformationButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_BUS]); - panelBus.add(updateBusInformationButton); - printBusInfo = new JButton(actions[InteractiveSimulationActions.ACT_PRINT_BUS]); - panelBus.add(printBusInfo); - busPanel.add(panelBus, BorderLayout.SOUTH); - - - if (!hashOK) { - wrongHashCode(); - } - pack(); - - //System.out.println("Row table:" + rowTable.toString()); - //System.out.println("Value table:" + valueTable.toString()); - } - - private void initActions() { - actions = new InteractiveSimulationActions[InteractiveSimulationActions.NB_ACTION]; - for(int i=0; i<InteractiveSimulationActions.NB_ACTION; i++) { - actions[i] = new InteractiveSimulationActions(i); - actions[i].addActionListener(this); - //actions[i].addKeyListener(this); + Integer c = runningTable.get(i); + if (c != null) { + mgui.addRunningIDTaskState(c, _state); + } + } catch (Exception e) { + TraceManager.addDev("Exception updateTaskCyclesAndStates: " + e.getMessage()); + } } - - cpuIDs = makeCPUIDs(); - busIDs = makeBusIDs(); - memIDs = makeMemIDs(); - taskIDs = makeTasksIDs(); - chanIDs = makeChanIDs(); - } - - - - public void setComponents() { - if (mode == NOT_STARTED) { - buttonStart.setEnabled(true); - } else { - buttonStart.setEnabled(false); - } - - if ((mode == STARTED_NOT_CONNECTED) || (mode == STARTED_AND_CONNECTED)) { - buttonStopAndClose.setEnabled(true); - } else { - buttonStopAndClose.setEnabled(false); - } - - boolean b = (mode == STARTED_AND_CONNECTED); - sendTextCommand.setEnabled(b); - setAll(); - //resetCommand.setEnabled(b); - //runCommand.setEnabled(b); - //StopCommand.setEnabled(b); - } - - public void close() { - if(mode != NOT_STARTED) { - go = false; - if (rc != null) { - try { - rc.disconnect(); - } catch (RemoteConnectionException rce) { - } - //System.out.println("Disconnected"); - rc = null; - } - } - mgui.resetRunningID(); - mgui.resetLoadID(); - mgui.setDiploAnimate(false); - dispose(); - setVisible(false); - - } - - public void killSimulator() { - if (mode == STARTED_AND_CONNECTED) { - if (rc != null) { - try { - rc.send("0"); - } catch (RemoteConnectionException rce) { - jta.append("Exception: " + rce.getMessage()); - jta.append("Could not kill simulator\n"); - } - } - rshc = null; - } else { - if (rshc != null) { - try { - rshc.sendKillProcessRequest(); - } catch (LauncherException le) { - jta.append("Exception: " + le.getMessage() + "\n"); - } - } - } - } - - public void startSimulation() { - mode = STARTING; - setComponents(); - go = true; - - startThread(0); - //t = new Thread(this); - //go = true; - //threadMode = 0; - //t.start(); - } - - private void testGo() throws InterruptedException { - if (go == false) { - throw new InterruptedException("Stopped by user"); - } - } - - // Must first start the remote server - // Then, must start - - public void run() { - String s; - TraceManager.addDev("mode=" + threadMode); - - try { - if (threadMode == 0) { - threadStarted(); - testGo(); - rc = new RemoteConnection(hostSystemC); - - if (!connect()) { - rshc = new RshClient(hostSystemC); - try { - jta.append("\nStarting simulation server\n"); - processCmd(pathExecute); - //jta.append(data + "\n"); - } catch (LauncherException le) { - jta.append("Error: " + le.getMessage() + "\n"); - mode = NOT_STARTED; - setComponents(); - return; - } catch (Exception e) { - mode = NOT_STARTED; - setComponents(); - return; - } - testGo(); - - // Wait for the server to start - Thread.currentThread().sleep(1000); - - //jta.append("Simulator started\n\n"); - jta.append("Connecting to simulation server ...\n"); - mode = STARTED_NOT_CONNECTED; - if (!connect()) { - jta.append("Could not connect to server... Aborting\n"); - mode = NOT_STARTED; - setComponents(); - return; - } - } - - testGo(); - - jta.append("Connected to simulation server ...\n"); - mode = STARTED_AND_CONNECTED; - - startThread(2); - - setComponents(); - - if (tmap != null) { - sendCommand("get-hashcode"); - } else { - sendCommand("time"); - } - - - try { - while(true) { - testGo(); - s = rc.readOneLine(); - if (debug.isSelected()) { - jta.append("\nFrom server: " + s + "\n"); - } - analyzeServerAnswer(s); - } - } catch (RemoteConnectionException rce) { - jta.append("Exception: " + rce.getMessage()); - jta.append("Could not read data from host: " + hostSystemC + ".... Aborting\n"); - busyMode = 0; - setLabelColors(); - //System.out.println("rc left"); - } - } else if (threadMode == 1) { - threadStarted(); - try { - while(true) { - testGo(); - s = rshc.getDataFromProcess(); - jta.append("\nFrom launcher: " + s + "\n"); - } - } catch (LauncherException le) { - jta.append("Exception: " + le.getMessage() + "\n"); - } - } else if (threadMode == 2) { - threadStarted(); - while(true) { - testGo(); - Thread.currentThread().sleep(500); - if (busyMode == 2 && gotTimeAnswerFromServer) { - gotTimeAnswerFromServer = false; - askForUpdate(); - - } - } - } - } catch (InterruptedException ie) { - jta.append("Interrupted\n"); - } - - //System.out.println("rc left threadMode=" + threadMode); - - } - - protected boolean connect() { - try { - rc.connect(); - return true; - } catch (RemoteConnectionException rce) { - return false; - } - } - - protected void processCmd(String cmd) throws LauncherException { - rshc.setCmd(cmd); - rshc.sendProcessRequest(); - startThread(1); - //t = new Thread(this); - ////go = true; - //threadMode = 1; - //t.start(); - } - - public void mouseClicked(MouseEvent e) {} - - public void mouseEntered(MouseEvent e) {} - - public void mouseExited(MouseEvent e) {} - - public void mousePressed(MouseEvent e){ - if (e.getSource() == sendTextCommand) { - if (sendTextCommand.isEnabled()) { - sendCommand(); - } - } else if (e.getSource() == printHelpTextCommands) { - helpOnCommand(); - } else if (e.getSource() == listTextCommands) { - listTextCommands(); - } /*else if (e.getSource() == resetCommand) { - sendCommand("reset"); - } else if (e.getSource() == runCommand) { - sendCommand("run-to-next-breakpoint"); - } else if (e.getSource() == StopCommand) { - sendCommand("stop"); - }*/ - } - - // Command management - - public void printSeparator() { - jta.append("-------------------------------------------------------------\n"); - } - - protected void listTextCommands() { - String text = cp.getCommandList(); - append("Available commands", text); - } - - protected void helpOnCommand() { - String text = textCommand.getText().trim(); - String texts[] = text.split(" "); - text = texts[0]; - String result = cp.getHelp(text); - append("Help on command: " + text, result); - } - - protected void sendCommand() { - String text = textCommand.getText().trim(); - sendCommand(text); - } - - protected void sendCommand(String text) { - jta.append(">" + text + "\n"); - String command = cp.transformCommandFromUserToSimulator(text); - if (command.length() == 0) { - jta.append("** Wrong command / parameters **\n"); - return; - } - - try { - rc.send(command); - } catch (RemoteConnectionException rce) { - jta.append("** Sending command failed **\n"); - return ; - } catch (Exception e) {} - } - - protected void append(String info, String list) { - jta.append("\n"); - jta.append(info + "\n"); - printSeparator(); - jta.append(list); - jta.append("\n"); - printSeparator(); - } - - protected void analyzeServerAnswer(String s) { - //System.out.println("From server:" + s); - int index0 = s.indexOf("<?xml"); - - if (index0 != -1) { - //System.out.println("toto1"); - ssxml = s.substring(index0, s.length()) + "\n"; - } else { - //System.out.println("toto2"); - ssxml = ssxml + s + "\n"; - } - - index0 = ssxml.indexOf("</siminfo>"); - - if (index0 != -1) { - //System.out.println("toto3"); - ssxml = ssxml.substring(0, index0+10); - loadXMLInfoFromServer(ssxml); - ssxml = ""; - } - //System.out.println("toto4"); - - } - - protected boolean loadXMLInfoFromServer(String xmldata) { - //jta.append("XML from server:" + xmldata + "\n\n"); - - DocumentBuilderFactory dbf; - DocumentBuilder db; - - try { - dbf = DocumentBuilderFactory.newInstance(); - db = dbf.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - dbf = null; - db = null; - } - - if ((dbf == null) || (db == null)) { - return false; - } - - ByteArrayInputStream bais = new ByteArrayInputStream(decodeString(xmldata).getBytes()); - int i; - - try { - // building nodes from xml String - Document doc = db.parse(bais); - NodeList nl; - Node node; - - nl = doc.getElementsByTagName(SIMULATION_HEADER); - - if (nl == null) { - return false; - } - - for(i=0; i<nl.getLength(); i++) { - node = nl.item(i); - //System.out.println("Node = " + dnd); - if (node.getNodeType() == Node.ELEMENT_NODE) { - // create design, and get an index for it - return loadConfiguration(node); - } - } - - } catch (IOException e) { - TraceManager.addError("Error when parsing server info:" + e.getMessage()); - return false; - } catch (SAXException saxe) { - TraceManager.addError("Error when parsing server info:" + saxe.getMessage()); - TraceManager.addError("xml:" + xmldata); - return false; - } - return true; - - } - - protected boolean loadConfiguration(Node node1) { - NodeList diagramNl = node1.getChildNodes(); - if (diagramNl == null) { - return false; - } - Element elt, elt0; - Node node, node0, node00; - NodeList nl, nl0; - - - String tmp; - int val; - - int[] colors; - String msg = null; - String error = null; - String hash = null; - - String id, idvar; - String name; - String command; - String startTime="", finishTime=""; - String progression="", nextCommand=""; - String transStartTime="", transFinishTime=""; - String util = null; - String value; - String extime; - String contdel; - String busname; - String busid; - String state; - String usedEnergy; - - int k; - - //System.out.println("toto0"); - - try { - for(int j=0; j<diagramNl.getLength(); j++) { - //System.out.println("Ndes: " + j); - node = diagramNl.item(j); - - if (node == null) { - TraceManager.addDev("null node"); - return false; - } - - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - - // Status - if (elt.getTagName().compareTo(SIMULATION_GLOBAL) == 0) { - - nl = elt.getElementsByTagName("status"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - - makeStatus(node0.getTextContent()); - } - - nl = elt.getElementsByTagName("brkreason"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - - makeBrkReason(node0.getTextContent()); - } - - nl = elt.getElementsByTagName("simtime"); - if ((nl != null) && (nl.getLength() > 0)) { - gotTimeAnswerFromServer = true; - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - time.setText(node0.getTextContent()); - } - - nl = elt.getElementsByTagName("msg"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - msg = node0.getTextContent(); - } - - nl = elt.getElementsByTagName("error"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - error = node0.getTextContent(); - } - - nl = elt.getElementsByTagName("hashval"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - hash = node0.getTextContent(); - } - - nl = elt.getElementsByTagName(SIMULATION_COMMAND); - for(int kk=0; kk<nl.getLength(); kk++) { - node0 = nl.item(kk); - elt0 = (Element)node0; - id = null; - name = null; - command = null; - id = elt0.getAttribute("id"); - //TraceManager.addDev("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - nl0 = elt0.getElementsByTagName("exectimes"); - if ((nl0 != null) && (nl0.getLength() > 0)) { - node00 = nl0.item(0); - //TraceManager.addDev("nl0:" + nl0 + " value=" + node00.getNodeValue() + " content=" + node00.getTextContent()); - util = node00.getTextContent(); - } - - //TraceManager.addDev("Got info on command " + id + " util=" + util); - - if ((id != null) && (util != null)) { - //TraceManager.addDev("Updating command"); - updateCommandExecutionState(id, util); - } - } - - } - - if (hashOK) { - if (elt.getTagName().compareTo(SIMULATION_TASK) == 0) { - id = null; - name = null; - command = null; - nextCommand = null; - progression = null; - startTime = null; finishTime = null; - transStartTime = null; transFinishTime = null; - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - nl = elt.getElementsByTagName("currcmd"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - if (node0.getNodeType() == Node.ELEMENT_NODE) { - elt0 = (Element)node0; - command = elt0.getAttribute("id"); - } - nl = elt.getElementsByTagName("progr"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - progression = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - nl = elt.getElementsByTagName("starttime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - startTime = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - nl = elt.getElementsByTagName("finishtime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - finishTime = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - nl = elt.getElementsByTagName("transstarttime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - transStartTime = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - nl = elt.getElementsByTagName("transfinishtime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - transFinishTime = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - nl = elt.getElementsByTagName("nextcmd"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - nextCommand = node0.getTextContent(); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - } - - } - - //System.out.println("Got info on task " + id + " command=" + command); - extime = null; - nl = elt.getElementsByTagName("extime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - extime = node0.getTextContent(); - } - - state = null; - nl = elt.getElementsByTagName("tskstate"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - state = node0.getTextContent(); - //TraceManager.addDev("TASK STATE: " + state); - } - - if ((id != null) && ((extime != null) || (state != null))) { - updateTaskCyclesAndState(id, extime, state); - } - - - if ((id != null) && (command != null)) { - if (nextCommand ==null) { - nextCommand = "-1"; - } - updateRunningCommand(id, command, progression, startTime, finishTime, nextCommand, transStartTime, transFinishTime, state); - } - - if (openDiagram.isEnabled() && openDiagram.isSelected() && (name != null) && (command != null)) { - updateOpenDiagram(name, command, progression, startTime, finishTime, transStartTime, transFinishTime); - } - - - - - nl = elt.getElementsByTagName("var"); - if ((nl != null) && (nl.getLength() > 0)) { - idvar = null; - value = null; - for(k=0; k<nl.getLength(); k++) { - node0 = nl.item(k); - value = node0.getTextContent(); - if (node0.getNodeType() == Node.ELEMENT_NODE) { - elt0 = (Element)node0; - idvar = elt0.getAttribute("id"); - } - if ((value != null) && (idvar != null)) { - updateVariableState(idvar, value); - jpsv.updateOnVariableValue(idvar); - } - } - } - } - - //System.out.println("toto1"); - - if (elt.getTagName().compareTo(SIMULATION_CPU) == 0) { - id = null; - name = null; - command = null; - contdel = null; - busname = null; - busid = null; - usedEnergy = null; - - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - nl = elt.getElementsByTagName("util"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - util = node0.getTextContent(); - } - nl = elt.getElementsByTagName("energy"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("energy NL? nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - usedEnergy = node0.getTextContent(); - } - - //System.out.println("toto12"); - nl = elt.getElementsByTagName("contdel"); - if ((nl != null) && (nl.getLength() > 0)) { - nl = elt.getElementsByTagName("contdel"); - node0 = nl.item(0); - elt0 = (Element)node0; - busid = elt0.getAttribute("busID"); - busname = elt0.getAttribute("busName"); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - contdel = node0.getTextContent(); - } - - //System.out.println("contdel: " + contdel + " busID:" + busid + " busName:" + busname); - - - if ((id != null) && (util != null)) { - updateCPUState(id, util, usedEnergy, contdel, busname, busid); - } - } - - //System.out.println("toto2"); - - if (elt.getTagName().compareTo(SIMULATION_BUS) == 0) { - id = null; - name = null; - command = null; - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - nl = elt.getElementsByTagName("util"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - util = node0.getTextContent(); - } - - //System.out.println("Got info on bus " + id + " util=" + util); - - if ((id != null) && (util != null)) { - updateBusState(id, util); - } - } - - - } - } - } - } catch (Exception e) { - TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); - return false; - } - - if ((msg != null) && (error != null)) { - if (error.trim().equals("0")) { - printFromServer(msg + ": command successful"); - if (msg.indexOf("reset") != -1) { - time.setText("0"); - } - } else { - printFromServer(msg + ": command failed (error=" + error + ")"); - } - } else if (msg != null) { - printFromServer("Server: " + msg); - } else { - //TraceManager.addDev("Node: " +node1 + " diagramNL=" + diagramNl); - //printFromServer("Server: error " + error); - } - - if ((hash != null) && (tmap != null)) { - try { - int thehash = Integer.decode(hash).intValue(); - - if (thehash != hashCode) { - jta.append("\n*** Simulated model is not the model currently loaded under TTool ***\n"); - jta.append("*** Some features are therefore deactivated ***\n\n"); - hashOK = false; - wrongHashCode(); - } else { - askForUpdate(); - sendBreakPointList(); - jta.append("\n*** Simulated model is the one currently loaded under TTool ***\n"); - hashOK = true; - animate.setSelected(true); - animate.setEnabled(true); - diploids.setEnabled(true); - animateWithInfo.setSelected(true); - animateWithInfo.setEnabled(true); - openDiagram.setEnabled(true); - cpus.setEnabled(true); - busses.setEnabled(true); - mems.setEnabled(true); - tasks.setEnabled(true); - chans.setEnabled(true); - } - } catch (Exception e) { - } - } - - return true; - } - - private void wrongHashCode() { - TraceManager.addDev("Wrong hash code"); - - cpuPanel.setVisible(false); - variablePanel.setVisible(false); - openDiagram.setSelected(false); - openDiagram.setEnabled(false); - animate.setEnabled(false); - diploids.setEnabled(false); - animate.setSelected(false); - diploids.setSelected(false); - animateWithInfo.setSelected(false); - animateWithInfo.setEnabled(false); - update.setEnabled(false); - update.setSelected(false); - - cpus.setEnabled(false); - busses.setEnabled(false); - mems.setEnabled(false); - tasks.setEnabled(false); - chans.setEnabled(false); - cpus.removeAllItems(); - busses.removeAllItems(); - mems.removeAllItems(); - tasks.removeAllItems(); - chans.removeAllItems(); - - jpsv.setEnabled(false); - jpsv.unsetElements(); - - actions[InteractiveSimulationActions.ACT_RUN_TO_NEXT_BUS_TRANSFER].setEnabled(false); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CPU_EXECUTES].setEnabled(false); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_TASK_EXECUTES].setEnabled(false); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_MEMORY_ACCESS].setEnabled(false); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CHANNEL_ACCESS].setEnabled(false); - - // Set variable tab is removed - // - commandTab.removeTabAt(2); - jpsv = null; - - while(infoTab.getTabCount() > 2) { - infoTab.removeTabAt(2); - } - jpbp.unsetElements(); - - } - - public synchronized void startThread(int mode) { - threadMode = mode; - t = new Thread(this); - t.start(); - threadStarted = false; - //System.out.println("thread of mode:" + threadMode); - while(threadStarted == false) { - try { - wait(); - } catch (InterruptedException ie) {} - } - } - - public synchronized void threadStarted() { - TraceManager.addDev("thread started"); - threadStarted = true; - notify(); - } - - public void makeBrkReason(String s) { - info.setText(s); - } - - public void makeStatus(String s) { - //System.out.println("busystatus=" + busyStatus); - - if (s.equals("busy")) { - status.setText("Busy"); - setBusyStatus(); - busyMode = 2; - //busyStatus = true; - } - if (s.equals("ready")) { - status.setText("Ready"); - if (busyMode == 2) { - //System.out.println("Sending time command"); - askForUpdate(); - //sendCommand("time"); - } - busyMode = 1; - setBusyStatus(); - } - - if (s.equals("term")) { - status.setText("Terminated"); - if (busyMode == 2) { - askForUpdate(); - } - busyMode = 3; - setBusyStatus(); - - //System.out.println("**** TERM ****"); - } - setLabelColors(); - } - - public void setBusyStatus() { - setAll(); - actions[InteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(busyMode == 2); - } - - public void setLabelColors() { - switch(busyMode) { - case 0: - status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN); - break; - case 1: - status.setForeground(ColorManager.InteractiveSimulationText_READY); - time.setForeground(ColorManager.InteractiveSimulationText_READY); - info.setForeground(ColorManager.InteractiveSimulationText_READY); - break; - case 2: - status.setForeground(ColorManager.InteractiveSimulationText_BUSY); - time.setForeground(ColorManager.InteractiveSimulationText_BUSY); - info.setForeground(ColorManager.InteractiveSimulationText_BUSY); - break; - case 3: - status.setForeground(ColorManager.InteractiveSimulationText_TERM); - time.setForeground(ColorManager.InteractiveSimulationText_TERM); - info.setForeground(ColorManager.InteractiveSimulationText_TERM); - break; - } - - - } - - public void setAll() { - boolean b = false;; - if (busyMode == 1) { - b = true; - } - actions[InteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_X_TIME_UNITS].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_TO_TIME].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_X_TRANSACTIONS].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(b); - actions[InteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_EXPLORATION].setEnabled(b); - - if (jpsv != null) { - jpsv.setVariableButton(b); - } - - if(busyMode == 3) { - actions[InteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true); - } - - if (!hashOK) { - b = false; - } - - actions[InteractiveSimulationActions.ACT_RUN_TO_NEXT_BUS_TRANSFER].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CPU_EXECUTES].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_TASK_EXECUTES].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_MEMORY_ACCESS].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CHANNEL_ACCESS].setEnabled(b); - - if((busyMode == 0) || (busyMode == 2)) { - b = false; - } else { - b = true; - } - - actions[InteractiveSimulationActions.ACT_SAVE_VCD].setEnabled(b); - actions[InteractiveSimulationActions.ACT_SAVE_HTML].setEnabled(b); - actions[InteractiveSimulationActions.ACT_SAVE_TXT].setEnabled(b); - actions[InteractiveSimulationActions.ACT_PRINT_BENCHMARK].setEnabled(b); - actions[InteractiveSimulationActions.ACT_SAVE_BENCHMARK].setEnabled(b); - actions[InteractiveSimulationActions.ACT_SAVE_STATE].setEnabled(b); - actions[InteractiveSimulationActions.ACT_RESTORE_STATE].setEnabled(b); - } - - public static String decodeString(String s) { - if (s == null) - return s; - byte b[] = null; - try { - b = s.getBytes("ISO-8859-1"); - return new String(b); - } catch (Exception e) { - return null; - } - } - - public void printFromServer(String s) { - jta.append("Server> " + s + "\n"); - } - - - // Mouse management - public void mouseReleased(MouseEvent e) {} - - - - /** - * This adapter is constructed to handle mouse over component events. - */ - private class MouseHandler extends MouseAdapter { - - private JLabel label; - - /** - * ctor for the adapter. - * @param label the JLabel which will recieve value of the - * Action.LONG_DESCRIPTION key. - */ - public MouseHandler(JLabel label) { - setLabel(label); + + } + + private void updateCPUState(String _id, String _utilization, String _usedEnergy, String contdel, String busName, String busID) { + Integer i = getInteger(_id); + int row; + String info; + + if (i != null) { + try { + valueTable.remove(i); + info = "Utilization: " + _utilization; + if (_usedEnergy != null) { + info += "; used energy: " + _usedEnergy; + } + if ((contdel != null) && (busName != null) && (busID != null)) { + info += "; Cont. delay on " + busName + " (" + busID + "): " + contdel; + } + valueTable.put(i, info); + //System.out.println("Searching for old row"); + row = (Integer)(rowTable.get(i)).intValue(); + cputm.fireTableCellUpdated(row, 2); + if (_usedEnergy == null) { + mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), -1); + } else { + mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), getLong(_usedEnergy).longValue()); + } + } catch (Exception e) { + TraceManager.addDev("Exception updateCPUState: " + e.getMessage() + " id=" + _id + " util=" + _utilization); + } } - - public void setLabel(JLabel label) { - this.label = label; + } + + private void updateTableOfTransactions() { + jspTransactionInfo.repaint(); + } + + + private void updateBusState(String _id, String _utilization) { + Integer i = getInteger(_id); + int row; + + if (i != null) { + try { + valueTable.remove(i); + valueTable.put(i, "Utilization: " + _utilization); + //TraceManager.addDev("Searching for old row"); + row = rowTable.get(i).intValue(); + bustm.fireTableCellUpdated(row, 2); + mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), -1); + } catch (Exception e) { + System.err.println("Exception updateBusState: " + e.getMessage()); + } } - - public void mouseEntered(MouseEvent evt) { - if (evt.getSource() instanceof AbstractButton) { - AbstractButton button = (AbstractButton)evt.getSource(); - Action action = button.getAction(); - if (action != null) { - String message = (String)action.getValue(Action.LONG_DESCRIPTION); - label.setText(message); + } + + private void updateCommandExecutionState(String _id, String _nbOfExec) { + Integer id = getInteger(_id); + Integer nbOfExec = getInteger(_nbOfExec); + + //TraceManager.addDev("Updating execution of command " + _id + " to " + _nbOfExec); + + if (tmap != null) { + TMLElement tmle = tmap.getTMLModeling().getCorrespondance(id); + if (tmle != null) { + Object o = tmle.getReferenceObject(); + if ((o != null) && (o instanceof TGComponent)) { + //TraceManager.addDev("Setting met DIPLO = " + o); + ((TGComponent)o).setDIPLOMet(nbOfExec); } } } + + //tmap.getElementByID(); } - - public void sendCommandWithPositiveInt(String command) { - String param = paramMainCommand.getText().trim(); - if (isAPositiveInt(param)) { - sendCommand(command + " " + param); - } else { - error("Wrong parameter: must be a positive int"); - } - } - - public void sendSaveTraceCommand(String format) { - String param = saveFileName.getText().trim(); - if (saveDirName.getText().length() > 0) { - param = saveDirName.getText() + File.separator + param; + + public void askForUpdate() { + sendCommand("time"); + if (hashOK) { + if (animate.isSelected()) { + updateTaskCommands(); + updateExecutedCommands(); + } + if (update.isSelected()) { + updateTasks(); + updateVariables(); + updateCPUs(); + updateBus(); + trans = null; + updateTransactions(); + } } - if (param.length() >0) { - sendCommand("save-trace-in-file" + " " + format + " " + param); - } else { - error("Wrong parameter: must be a file name"); - } - } - - public void sendSaveStateCommand() { - String param = stateFileName.getText().trim(); - if (param.length() >0) { - sendCommand("save-simulation-state-in-file " + param); - } else { - error("Wrong parameter: must be a file name"); - } - } - - public void sendRestoreStateCommand() { - String param = stateFileName.getText().trim(); - if (param.length() >0) { - sendCommand("restore-simulation-state-from-file " + param); - } else { - error("Wrong parameter: must be a file name"); - } - } - - public void sendSaveBenchmarkCommand() { - String param = benchmarkFileName.getText().trim(); - if (param.length() >0) { - sendCommand("get-benchmark 1 " + param); - } else { - error("Wrong benchmark parameter: must be a file name"); - } - } - - private void runExploration() { - animate.setSelected(false); - mgui.setDiploAnimate(animate.isSelected()); - diploids.setEnabled(animate.isSelected()); - animateWithInfo.setEnabled(animate.isSelected()); - openDiagram.setEnabled(animate.isSelected()); - update.setSelected(false); - sendCommand("run-exploration " + minimalCommandCoverage.getValue() + " " + minimalBranchCoverage.getValue()); - } - - - - private void updateVariables() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - sendCommand("get-variable-of-task all all\n"); - - /*for(TMLTask task: tmap.getTMLModeling().getTasks()) { - for(TMLAttribute tmla: task.getAttributes()) { - sendCommand("get-variable-of-task " + task.getID() + " " + tmla.getID()); - } - }*/ - } - - private void updateCPUs() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { - if ((node instanceof HwCPU) || (node instanceof HwA)){ - sendCommand("get-info-on-hw 0 " + node.getID()); - } - } - } - - private void updateMemories() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwMemory) { - sendCommand("get-info-on-hw 2 " + node.getID()); - } - } - } - - private void updateBus() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - for(HwNode node: tmap.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwBus) { - sendCommand("get-info-on-hw 1 " + node.getID()); - } - } - } - - private void updateTasks() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - for(TMLTask task: tmap.getTMLModeling().getTasks()) { - sendCommand("get-info-on-hw 5 " + task.getID()); - } - } - - private void updateTaskCommands() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - sendCommand("get-command-of-task all"); - - /*for(TMLTask task: tmap.getTMLModeling().getTasks()) { - sendCommand("get-command-of-task " + task.getID()); - }*/ - } - - private void updateExecutedCommands() { - if (tmap == null) { - return; - } - - if (mode != STARTED_AND_CONNECTED) { - return; - } - - sendCommand("get-executed-operators"); - } - - - - private void updateRunningCommand(String id, String command, String progression, String startTime, String finishTime, String nextCommand, String transStartTime, String transFinishTime, String _state) { - Integer i = getInteger(id); - Integer c = getInteger(command); - Integer nc = getInteger(nextCommand); - - if (_state == null) { - _state = tasktm.getState(valueTable.get(new Integer(id))); - } - - TraceManager.addDev("state:" + _state); - - if ((i != null) && (c != null)) { - try { - //System.out.println("Searching for old value"); - Integer old = runningTable.get(i); - if(old != null) { - mgui.removeRunningId(old); - runningTable.remove(old); - } - - runningTable.put(i, c); - //System.out.println("Adding running command: " +c); - mgui.addRunningID(c, nc, progression, startTime, finishTime, transStartTime, transFinishTime, _state); - } catch (Exception e) { - TraceManager.addDev("Exception updateRunningCommand: " + e.getMessage()); - } - } - - } - - private void updateOpenDiagram(String name, String _command, String _progression, String _startTime, String _finishTime, String _transStartTime, String _transFinishTime) { - //System.out.println("UpdateOpenDiagram name=" + name + " for command:" + command); - if (tmap == null) { - return; - } - - String command = _command; - if (_progression != null) { - command += _progression; - } - if (_startTime != null) { - command += _startTime; - } - if (_finishTime != null) { - command += _finishTime; - } - if (_transStartTime != null) { - command += _transStartTime; - } - if (_transFinishTime != null) { - command += _transFinishTime; - } - - String cmd = diagramTable.get(name); - if (cmd == null) { - diagramTable.put(name, command); - //return; - } - - if ((cmd == null) || (!(cmd.equals(command)))) { - diagramTable.remove(name); - diagramTable.put(name, command); - - String diag = ""; - String tab = name; - int index = tab.indexOf("__"); - if (index != -1) { - diag = tab.substring(0, index); - tab = tab.substring(index+2, tab.length()); - } - //System.out.println("Opening diagram " + tab + " for command:" + command); - - mgui.openTMLTaskActivityDiagram(diag, tab); - } - } - - - - private void printCPUs() { - if (latex.isSelected()) { - String name; - String tmp, tmp1; - int index, index1; - jta.append("\\begin{tabular}{|l|c|c|}\n"); - jta.append("\\hline\n"); - jta.append("\\texbf{CPU} & \\textbf{Load} & \\textbf{Contention delay}\n"); - jta.append("\\hline\n"); - for(int i=0; i<cputm.getRowCount(); i++) { - name = (String)(cputm.getValueAt(i, 0)); - tmp = (String)(cputm.getValueAt(i, 2)); - jta.append(Conversion.toLatex(name) + " &"); - index = tmp.indexOf(';'); - if (index == -1) { - jta.append(" - & - \\\\\n"); - } else { - - - tmp1 = tmp.substring(0, index); - index1 = tmp1.indexOf(':'); - if (index1 != -1) { - tmp1 = tmp1.substring(index1 + 2, tmp1.length()); - } - jta.append("" + tmp1 + " &"); - tmp1 = tmp.substring(index+1, tmp.length()); - index1 = tmp1.indexOf(':'); - if (index1 != -1) { - tmp1 = tmp1.substring(index1 + 2, tmp1.length()); - } - jta.append("" + tmp1 + "\\\\\n"); - } - } - jta.append("\\hline\n"); - } else { - String name; - String tmp, tmp1; - int index, index1; - jta.append("\nCPUs:\n"); - for(int i=0; i<cputm.getRowCount(); i++) { - name = (String)(cputm.getValueAt(i, 0)); - tmp = (String)(cputm.getValueAt(i, 2)); - jta.append("* " + name + "\n"); - index = tmp.indexOf(';'); - if (index == -1) { - jta.append("\t - \n"); - } else { - jta.append("\t" + tmp.substring(0, index) + "\n"); - jta.append("\t" + tmp.substring(index+1, tmp.length()) + "\n"); - } - } - } - } - - private void printBuses() { - if (latex.isSelected()) { - String name; - String tmp, tmp1; - int index, index1; - jta.append("\\begin{tabular}{|l|c|c|}\n"); - jta.append("\\hline\n"); - jta.append("\\texbf{CPU} & \\textbf{Load} & \\textbf{Contention delay}\n"); - jta.append("\\hline\n"); - for(int i=0; i<bustm.getRowCount(); i++) { - name = (String)(bustm.getValueAt(i, 0)); - tmp = (String)(bustm.getValueAt(i, 2)); - jta.append(Conversion.toLatex(name) + " &"); - index = tmp.indexOf(':'); - if (index == -1) { - jta.append(" - \\\\\n"); - } else { - tmp1 = tmp.substring(index+2, tmp.length()); - jta.append("" + tmp1 + "\\\\\n"); - } - } - jta.append("\\hline\n"); - } else { - String name; - String tmp; - jta.append("\nBuses:\n"); - for(int i=0; i<bustm.getRowCount(); i++) { - name = (String)(bustm.getValueAt(i, 0)); - tmp = (String)(bustm.getValueAt(i, 2)); - jta.append("* " + name + "\n"); - jta.append("\t" + tmp + "\n"); - } - } - } - - private void updateVariableState(String _idvar, String _value) { - Integer i = getInteger(_idvar); - int row; - - if (i != null) { - try { - valueTable.remove(i); - valueTable.put(i, _value); - //System.out.println("Searching for old row"); - row = (Integer)(rowTable.get(i)).intValue(); - tvtm.fireTableCellUpdated(row, 4); - } catch (Exception e) { - TraceManager.addDev("Exception updateVariableState: " + e.getMessage() + " idvar=" + _idvar + " val=" + _value); - } - } - - } - - private void updateTaskCyclesAndState(String _id, String _extime, String _state) { - Integer i = getInteger(_id); - Integer ex = getInteger(_extime); - int row; - - String s = ""; - if (_state != null) { - s += _state; - } - s += ";"; - if (_extime != null) { - s+= _extime; - } - - - - if ((i != null) && (ex != null)) { - try { - valueTable.remove(i); - valueTable.put(i, s); - //System.out.println("Searching for old row"); - row = rowTable.get(i).intValue(); - if (_state != null) { - tasktm.fireTableCellUpdated(row, 2); - } - if (_extime != null) { - tasktm.fireTableCellUpdated(row, 3); - } - - Integer c = runningTable.get(i); - if (c != null) { - mgui.addRunningIDTaskState(c, _state); - } - } catch (Exception e) { - TraceManager.addDev("Exception updateTaskCyclesAndStates: " + e.getMessage()); - } - } - - } - - private void updateCPUState(String _id, String _utilization, String _usedEnergy, String contdel, String busName, String busID) { - Integer i = getInteger(_id); - int row; - String info; - - if (i != null) { - try { - valueTable.remove(i); - info = "Utilization: " + _utilization; - if (_usedEnergy != null) { - info += "; used energy: " + _usedEnergy; - } - if ((contdel != null) && (busName != null) && (busID != null)) { - info += "; Cont. delay on " + busName + " (" + busID + "): " + contdel; - } - valueTable.put(i, info); - //System.out.println("Searching for old row"); - row = (Integer)(rowTable.get(i)).intValue(); - cputm.fireTableCellUpdated(row, 2); - if (_usedEnergy == null) { - mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), -1); - } else { - mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), getLong(_usedEnergy).longValue()); - } - } catch (Exception e) { - TraceManager.addDev("Exception updateCPUState: " + e.getMessage() + " id=" + _id + " util=" + _utilization); - } - } - } - - private void updateBusState(String _id, String _utilization) { - Integer i = getInteger(_id); - int row; - - if (i != null) { - try { - valueTable.remove(i); - valueTable.put(i, "Utilization: " + _utilization); - //TraceManager.addDev("Searching for old row"); - row = rowTable.get(i).intValue(); - bustm.fireTableCellUpdated(row, 2); - mgui.addLoadInfo(i, getDouble(_utilization).doubleValue(), -1); - } catch (Exception e) { - System.err.println("Exception updateBusState: " + e.getMessage()); - } - } - } - - private void updateCommandExecutionState(String _id, String _nbOfExec) { - Integer id = getInteger(_id); - Integer nbOfExec = getInteger(_nbOfExec); - - //TraceManager.addDev("Updating execution of command " + _id + " to " + _nbOfExec); - - if (tmap != null) { - TMLElement tmle = tmap.getTMLModeling().getCorrespondance(id); - if (tmle != null) { - Object o = tmle.getReferenceObject(); - if ((o != null) && (o instanceof TGComponent)) { - //TraceManager.addDev("Setting met DIPLO = " + o); - ((TGComponent)o).setDIPLOMet(nbOfExec); - } - } - } - - //tmap.getElementByID(); - } - - public void askForUpdate() { - sendCommand("time"); - if (hashOK) { - if (animate.isSelected()) { - updateTaskCommands(); - updateExecutedCommands(); - } - if (update.isSelected()) { - updateTasks(); - updateVariables(); - updateCPUs(); - updateBus(); - } - } - } - - private void analyzeRG() { - mgui.statAUTDiplodocus(); - } - - private void viewRG() { - mgui.showRGDiplodocus(); - } - - public void itemStateChanged(ItemEvent e) { - if (e.getSource() == animate) { - mgui.setDiploAnimate(animate.isSelected()); - diploids.setEnabled(animate.isSelected()); - animateWithInfo.setEnabled(animate.isSelected()); - openDiagram.setEnabled(animate.isSelected()); - } else if (e.getSource() == diploids) { - mgui.setDiploIDs(diploids.isSelected()); - }else if (e.getSource() == animateWithInfo) { - mgui.setTransationProgression(animateWithInfo.isSelected()); - } - } - - public void stateChanged(ChangeEvent e) { - JSlider source = (JSlider)e.getSource(); - //if (!source.getValueIsAdjusting()) { - int val = (int)source.getValue(); - if (source == minimalCommandCoverage) { - labelMinimalCommandCoverage.setText("" + val+ "%"); - } else { - labelMinimalBranchCoverage.setText("" + val+ "%"); - } - //} -} - - public void actionPerformed(ActionEvent evt) { - String command = evt.getActionCommand(); - //TraceManager.addDev("Command:" + command); - - if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_ALL].getActionCommand())) { + } + + private void analyzeRG() { + mgui.statAUTDiplodocus(); + } + + private void viewRG() { + mgui.showRGDiplodocus(); + } + + public void itemStateChanged(ItemEvent e) { + if (e.getSource() == animate) { + mgui.setDiploAnimate(animate.isSelected()); + diploids.setEnabled(animate.isSelected()); + animateWithInfo.setEnabled(animate.isSelected()); + openDiagram.setEnabled(animate.isSelected()); + } else if (e.getSource() == diploids) { + mgui.setDiploIDs(diploids.isSelected()); + }else if (e.getSource() == animateWithInfo) { + mgui.setTransationProgression(animateWithInfo.isSelected()); + } + } + + public void stateChanged(ChangeEvent e) { + JSlider source = (JSlider)e.getSource(); + //if (!source.getValueIsAdjusting()) { + int val = (int)source.getValue(); + if (source == minimalCommandCoverage) { + labelMinimalCommandCoverage.setText("" + val+ "%"); + } else { + labelMinimalBranchCoverage.setText("" + val+ "%"); + } + //} + } + + public void actionPerformed(ActionEvent evt) { + String command = evt.getActionCommand(); + //TraceManager.addDev("Command:" + command); + + if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_ALL].getActionCommand())) { close(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_START_ALL].getActionCommand())) { - setComponents(); - startSimulation(); - //TraceManager.addDev("Start simulation!"); - } else if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_AND_CLOSE_ALL].getActionCommand())) { - killSimulator(); - close(); - return; - //TraceManager.addDev("Start simulation!"); - } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_SIMU].getActionCommand())) { + setComponents(); + startSimulation(); + //TraceManager.addDev("Start simulation!"); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_AND_CLOSE_ALL].getActionCommand())) { + killSimulator(); + close(); + return; + //TraceManager.addDev("Start simulation!"); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_SIMU].getActionCommand())) { sendCommand("run-to-next-breakpoint"); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_X_TIME_UNITS].getActionCommand())) { sendCommandWithPositiveInt("run-x-time-units"); @@ -2387,7 +2480,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene sendCommandWithPositiveInt("run-x-commands"); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_EXPLORATION].getActionCommand())) { runExploration(); - //sendCommand("run-exploration"); + //sendCommand("run-exploration"); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_TO_NEXT_BUS_TRANSFER].getActionCommand())) { toNextBusTransfer(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RUN_UNTIL_CPU_EXECUTES].getActionCommand())) { @@ -2413,10 +2506,10 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_BENCHMARK].getActionCommand())) { sendSaveBenchmarkCommand(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_RESET_SIMU].getActionCommand())) { - mgui.resetRunningID(); - mgui.resetLoadID(); + mgui.resetRunningID(); + mgui.resetLoadID(); sendCommand("reset"); - askForUpdate(); + askForUpdate(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_STOP_SIMU].getActionCommand())) { sendCommand("stop"); } else if (command.equals(actions[InteractiveSimulationActions.ACT_UPDATE_VARIABLES].getActionCommand())) { @@ -2429,6 +2522,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene updateBus(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_UPDATE_TASKS].getActionCommand())) { updateTasks(); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_UPDATE_TRANSACTIONS].getActionCommand())) { + updateTransactions(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_PRINT_CPUS].getActionCommand())) { printCPUs(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_PRINT_BUS].getActionCommand())) { @@ -2437,239 +2532,243 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene analyzeRG(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_VIEW_RG].getActionCommand())) { viewRG(); - } - } - - public void error(String error) { - jta.append("error: " + error + "\n"); - } - - public boolean isAPositiveInt(String s) { - int val; - try { - val = Integer.decode(s).intValue(); - } catch (Exception e) { - return false; - } - if (val > -1) { - return true; - } - return false; - } - - public Integer getInteger(String s) { - try { - return Integer.decode(s); - } catch (Exception e) { - return null; - } - } - - public Long getLong(String s) { - try { - return Long.decode(s); - } catch (Exception e) { - return null; - } - } - - public Double getDouble(String s) { - try { - return new Double(s); - } catch (Exception e) { - return null; - } - } - - public void toNextBusTransfer() { - int id = getIDFromString(busIDs[busses.getSelectedIndex()]); - if (id != -1) { - sendCommand("run-to-next-transfer-on-bus " + id); - } - } - - public void runUntilCPUExecutes() { - int id = getIDFromString(cpuIDs[cpus.getSelectedIndex()]); - if (id != -1) { - sendCommand("run-until-cpu-executes " + id); - } - } - - public void toNextMemoryTransfer() { - int id = getIDFromString(memIDs[mems.getSelectedIndex()]); - if (id != -1) { - sendCommand("run-until-memory-access " + id); - } - } - - public void runUntilTaskExecutes() { - int id = getIDFromString(taskIDs[tasks.getSelectedIndex()]); - if (id != -1) { - sendCommand("run-until-task-executes " + id); - } - } - - public void runUntilChannelAccess() { - int id = getIDFromString(chanIDs[chans.getSelectedIndex()]); - if (id != -1) { - sendCommand("run-until-channel-access " + id); - } - } - - - - public int getIDFromString(String s) { - int index0 = s.indexOf("("); - int index1 = s.indexOf(")"); - if ((index0 < 0) || (index1 <0) || (index1 < index0)) { - return -1; - } - - String in = s.substring(index0+1, index1); - - try { - return Integer.decode(in).intValue(); - } catch (Exception e) { - System.err.println("Wrong string: "+ in); - } - - return -1; - } - - - - public void addBreakPoint(int _commandID) { - //TraceManager.addDev("Add breakpoint: " + _commandID); - // Check whether that breakpoint is already listed or not - for(Point p: points) { - if (p.y == _commandID) { - return; - } - } - - if (tmap != null) { - TMLTask task = tmap.getTMLTaskByCommandID(_commandID); - //TraceManager.addDev("Got task: " + task); - if (task != null) { - //TraceManager.addDev("Adding bkp"); - sendCommand("add-breakpoint " + task.getID() + " " + _commandID + "\n"); - jpbp.addExternalBreakpoint(task.getID(), _commandID); - } - } - } - - public void removeBreakPoint(int _commandID) { - TraceManager.addDev("remove breakpoint"); - int cpt = 0; - for(Point p: points) { - if (p.y == _commandID) { - sendCommand("rm-breakpoint " + p.x + " " + p.y + "\n"); - jpbp.removeExternalBreakpoint(cpt); - return; - } - cpt ++; - } - } - - public void sendBreakPointList() { - for(Point p: points) { - sendCommand("add-breakpoint " + p.x + " " + p.y + "\n"); - } - sendCommand("active-breakpoints 1"); - } - - public void removeBreakpoint(Point p) { - if (mode == STARTED_AND_CONNECTED) { - sendCommand("rm-breakpoint " + p.x + " " + p.y + "\n"); - } - if (animate.isSelected()) { - mgui.removeBreakpoint(p); - } - } - - public void addBreakpoint(Point p) { - if (mode == STARTED_AND_CONNECTED) { - sendCommand("add-breakpoint " + p.x + " " + p.y + "\n"); - } - if (animate.isSelected()) { - mgui.addBreakpoint(p); - } - } - - public void printMessage(String msg) { - jta.append("*** " + msg + " ***\n"); - } - - public String[] makeCPUIDs() { - if (tmap == null) { - return null; - } - - return tmap.getCPUandHwAIDs(); - } - - public String[] makeBusIDs() { - if (tmap == null) { - return null; - } - - return tmap.getBusIDs(); - } - - public String[] makeMemIDs() { - if (tmap == null) { - return null; - } - - return tmap.getMemIDs(); - } - - public String[] makeTasksIDs() { - if (tmap == null) { - return null; - } - - return tmap.getTasksIDs(); - } - - public String[] makeChanIDs() { - if (tmap == null) { - return null; - } - - return tmap.getChanIDs(); - } - - public String[] makeCommandIDs(int index) { - if (tmap == null) { - return null; - } - - return tmap.makeCommandIDs(index); - } - - public String[] makeVariableIDs(int index) { - if (tmap == null) { - return null; - } - - return tmap.makeVariableIDs(index); - } - - public void activeBreakPoint(boolean active) { - if (mode == STARTED_AND_CONNECTED) { - if (active) { - sendCommand("active-breakpoints 1"); - } else { - sendCommand("active-breakpoints 0"); - } - } - } - - public void setVariables(int _idTask, int _idVariable, String _value) { - sendCommand("set-variable " + _idTask + " " + _idVariable + " " + _value); - sendCommand("get-variable-of-task " + _idTask + " " + _idVariable); - } - - + } + } + + public void error(String error) { + jta.append("error: " + error + "\n"); + } + + public boolean isAPositiveInt(String s) { + int val; + try { + val = Integer.decode(s).intValue(); + } catch (Exception e) { + return false; + } + if (val > -1) { + return true; + } + return false; + } + + public Integer getInteger(String s) { + try { + return Integer.decode(s); + } catch (Exception e) { + return null; + } + } + + public Long getLong(String s) { + try { + return Long.decode(s); + } catch (Exception e) { + return null; + } + } + + public Double getDouble(String s) { + try { + return new Double(s); + } catch (Exception e) { + return null; + } + } + + public void toNextBusTransfer() { + int id = getIDFromString(busIDs[busses.getSelectedIndex()]); + if (id != -1) { + sendCommand("run-to-next-transfer-on-bus " + id); + } + } + + public void runUntilCPUExecutes() { + int id = getIDFromString(cpuIDs[cpus.getSelectedIndex()]); + if (id != -1) { + sendCommand("run-until-cpu-executes " + id); + } + } + + public void toNextMemoryTransfer() { + int id = getIDFromString(memIDs[mems.getSelectedIndex()]); + if (id != -1) { + sendCommand("run-until-memory-access " + id); + } + } + + public void runUntilTaskExecutes() { + int id = getIDFromString(taskIDs[tasks.getSelectedIndex()]); + if (id != -1) { + sendCommand("run-until-task-executes " + id); + } + } + + public void runUntilChannelAccess() { + int id = getIDFromString(chanIDs[chans.getSelectedIndex()]); + if (id != -1) { + sendCommand("run-until-channel-access " + id); + } + } + + + + public int getIDFromString(String s) { + int index0 = s.indexOf("("); + int index1 = s.indexOf(")"); + if ((index0 < 0) || (index1 <0) || (index1 < index0)) { + return -1; + } + + String in = s.substring(index0+1, index1); + + try { + return Integer.decode(in).intValue(); + } catch (Exception e) { + System.err.println("Wrong string: "+ in); + } + + return -1; + } + + + + public void addBreakPoint(int _commandID) { + //TraceManager.addDev("Add breakpoint: " + _commandID); + // Check whether that breakpoint is already listed or not + for(Point p: points) { + if (p.y == _commandID) { + return; + } + } + + if (tmap != null) { + TMLTask task = tmap.getTMLTaskByCommandID(_commandID); + //TraceManager.addDev("Got task: " + task); + if (task != null) { + //TraceManager.addDev("Adding bkp"); + sendCommand("add-breakpoint " + task.getID() + " " + _commandID + "\n"); + jpbp.addExternalBreakpoint(task.getID(), _commandID); + } + } + } + + public void removeBreakPoint(int _commandID) { + TraceManager.addDev("remove breakpoint"); + int cpt = 0; + for(Point p: points) { + if (p.y == _commandID) { + sendCommand("rm-breakpoint " + p.x + " " + p.y + "\n"); + jpbp.removeExternalBreakpoint(cpt); + return; + } + cpt ++; + } + } + + public void sendBreakPointList() { + for(Point p: points) { + sendCommand("add-breakpoint " + p.x + " " + p.y + "\n"); + } + sendCommand("active-breakpoints 1"); + } + + public void removeBreakpoint(Point p) { + if (mode == STARTED_AND_CONNECTED) { + sendCommand("rm-breakpoint " + p.x + " " + p.y + "\n"); + } + if (animate.isSelected()) { + mgui.removeBreakpoint(p); + } + } + + public void addBreakpoint(Point p) { + if (mode == STARTED_AND_CONNECTED) { + sendCommand("add-breakpoint " + p.x + " " + p.y + "\n"); + } + if (animate.isSelected()) { + mgui.addBreakpoint(p); + } + } + + public void printMessage(String msg) { + jta.append("*** " + msg + " ***\n"); + } + + public String[] makeCPUIDs() { + if (tmap == null) { + return null; + } + + return tmap.getCPUandHwAIDs(); + } + + public String[] makeBusIDs() { + if (tmap == null) { + return null; + } + + return tmap.getBusIDs(); + } + + public String[] makeMemIDs() { + if (tmap == null) { + return null; + } + + return tmap.getMemIDs(); + } + + public String[] makeTasksIDs() { + if (tmap == null) { + return null; + } + + return tmap.getTasksIDs(); + } + + public String[] makeChanIDs() { + if (tmap == null) { + return null; + } + + return tmap.getChanIDs(); + } + + public String[] makeCommandIDs(int index) { + if (tmap == null) { + return null; + } + + return tmap.makeCommandIDs(index); + } + + public String[] makeVariableIDs(int index) { + if (tmap == null) { + return null; + } + + return tmap.makeVariableIDs(index); + } + + public void activeBreakPoint(boolean active) { + if (mode == STARTED_AND_CONNECTED) { + if (active) { + sendCommand("active-breakpoints 1"); + } else { + sendCommand("active-breakpoints 0"); + } + } + } + + public void setVariables(int _idTask, int _idVariable, String _value) { + sendCommand("set-variable " + _idTask + " " + _idVariable + " " + _value); + sendCommand("get-variable-of-task " + _idTask + " " + _idVariable); + } + + public Vector<SimulationTransaction> getListOfRecentTransactions() { + return trans; + } + + } // Class diff --git a/src/ui/interactivesimulation/SimulationTransaction.java b/src/ui/interactivesimulation/SimulationTransaction.java new file mode 100755 index 0000000000..73198f7e2f --- /dev/null +++ b/src/ui/interactivesimulation/SimulationTransaction.java @@ -0,0 +1,72 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class SimulationTransaction + * Transaction as defined by the simulation engine + * Creation: 20/05/2016 + * @version 1.0 20/05/2016 + * @author Ludovic APVRILLE + * @see + */ + +package ui.interactivesimulation; + +import java.util.*; +import javax.swing.table.*; + +import myutil.*; +import tmltranslator.*; + +public class SimulationTransaction { + + public final static int NODE_TYPE_CPU = 0; + public final static int NOTE_TYPE_BUS = 1; + + public String nodeType; + public String deviceName; + public String taskName; + public String command; + public String startTime; + public String length; /* Used for identifiying asynchronous messages */ + public String virtualLength; + public String channelName; + + public SimulationTransaction() { + } + +} -- GitLab