diff --git a/simulators/c++2/src_simulator/arch/CPU.cpp b/simulators/c++2/src_simulator/arch/CPU.cpp index 6dbb361881a64be14e5498e49038e09c73f498df..bd0ef56fef34f64a71ea388ca9563e72729a3e9d 100644 --- a/simulators/c++2/src_simulator/arch/CPU.cpp +++ b/simulators/c++2/src_simulator/arch/CPU.cpp @@ -87,49 +87,46 @@ void CPU::drawPieChart(std::ofstream& myfile) const { } } std::map <TMLTask*, double>::iterator iter = transPercentage.begin(); - myfile << SCHED_HTML_JS_WINDOW << std::endl; myfile << " var ctx" << _ID << "_" << j << "= $(\"#pie-chartcanvas-" << _ID << "_" << j << "\");\n"; - myfile << " var data" << _ID << "_" << j << " = { \n"; - myfile << " labels : ["; + double idle=1; + myfile << " var data" << _ID << "_" << j << " = new Array ("; while( iter != transPercentage.end()){ - myfile << " \"" << iter->first->toString() << "\","; + myfile << "\"" << iter->second << "\","; idle-=iter->second; ++iter; } - myfile << "\"idle time\"],\n"; - myfile << " datasets : [ \n" << " {\n"; + myfile << "\"" << idle << "\");\n"; + + myfile << " var efficiency" << _ID << "_" << j << " = [];" << std::endl; + myfile << " var coloR" << _ID << "_" << j << " = [];" << std::endl; + myfile << " var dynamicColors" << _ID << "_" << j << SCHED_HTML_JS_FUNCTION; + + myfile << " for (var i in data" << _ID << "_" << j << "){\n"; + myfile << " efficiency" << _ID << "_" << j << ".push(data" << _ID << "_" << j << "[i]);\n"; + myfile << " coloR" << _ID << "_" << j << ".push(dynamicColors" << _ID << "_" << j << "());\n"; + myfile << "}" << std::endl; + + myfile << " var data" << _ID << "_" << j << " = { \n"; + myfile << " labels : ["; iter = transPercentage.begin(); - myfile << " data : ["; while( iter != transPercentage.end()){ - myfile << iter->second << ","; + myfile << " \"" << iter->first->toString() << "\","; + idle-=iter->second; ++iter; - } - myfile << idle << "],\n"; - - myfile << SCHED_HTML_PIE_END << std::endl; + } + myfile << "\"idle time\"],\n"; + myfile << " datasets : [\n \ + {\n \ + data : efficiency" << _ID << "_" << j << ",\n"; + myfile << " backgroundColor : coloR" << _ID << "_" << j << std::endl; myfile << SCHED_HTML_JS_CONTENT1 << "Average load is " << averageLoad(j) << SCHED_HTML_JS_CONTENT2 << std::endl; - myfile << " var chart" << _ID << "_" << this->_cycleTime << " = new Chart( "<< + myfile << " var chart" << _ID << "_" << j << " = new Chart( "<< "ctx" << _ID << "_" << j << ", {\n \ type : \"pie\",\n"; myfile << " data : data" << _ID << "_" << j <<",\n"; myfile << " " << SCHED_HTML_JS_CONTENT3 << std::endl; } - - - //myfile << " var chart" << _ID << "_" << j << "= new CanvasJS.Chart(\"chartContainer" << _ID << "_" << j <<"\"," << std::endl; - //myfile << SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad(j) << SCHED_HTML_JS_CONTENT3 << std::endl; - /*double idle=1; - while( iter != transPercentage.end()){ - myfile << " { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl; - idle-=iter->second; - ++iter; - } - myfile << " { y:" << idle*100 << ", indexLabel: \"idle time\"" << " }" << std::endl; - myfile << std::endl; - myfile << SCHED_HTML_PIE_END; - myfile << "chart" << _ID << "_" << j << ".render();" << std::endl; - }*/ } diff --git a/simulators/c++2/src_simulator/arch/FPGA.cpp b/simulators/c++2/src_simulator/arch/FPGA.cpp index b46d25e16c3965f870185f2bf84e5286105da3df..16d080fedc9787e82cc06a28834670f5b45fd649 100644 --- a/simulators/c++2/src_simulator/arch/FPGA.cpp +++ b/simulators/c++2/src_simulator/arch/FPGA.cpp @@ -453,50 +453,76 @@ double FPGA::averageLoad (TMLTask* currTask) const{ } -void FPGA::drawPieChart(std::ofstream& myfile) const { - std::cout<<"fpga draw pie chart"<<std::endl; - TMLTime _maxEndTime=0; - - for( TransactionList::const_iterator i = _transactList.begin(); i != _transactList.end(); ++i ) { - if( (*i)-> getCommand()->getTask() == _htmlCurrTask ){ - TMLTime _endTime= (*i)->getEndTime(); - _maxEndTime=max(_maxEndTime,_endTime); - } - } -#ifdef DEBUG_FPGA - std::cout<<"max end time is "<<_maxEndTime<<std::endl; -#endif - std::map <TMLTask*, double > transPercentage; - - for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){ - if( (*i)-> getCommand()->getTask() == _htmlCurrTask ){ - transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime; - } - } - - std::map <TMLTask*, double>::iterator iter = transPercentage.begin(); - myfile << " var chart" << _ID << "_" << _htmlCurrTask->toShortString() << "= new CanvasJS.Chart(\"chartContainer" << _ID << "_" << _htmlCurrTask->toShortString() <<"\"," << std::endl; - myfile << SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad( _htmlCurrTask) << SCHED_HTML_JS_CONTENT2 << std::endl; - double idle=1; - while( iter != transPercentage.end()){ - myfile << " { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl; - idle-=iter->second; - ++iter; - } - myfile << " { y:" << idle*100 << ", indexLabel: \"idle time\"" << " }" << std::endl; - myfile << std::endl; - myfile << SCHED_HTML_PIE_END; - myfile << "chart" << _ID << "_" << _htmlCurrTask->toShortString() << ".render();" << std::endl; - - +void FPGA::drawPieChart(std::ofstream& myfile) const { + TMLTime _maxEndTime=0; + + for( TransactionList::const_iterator i = _transactList.begin(); i != _transactList.end(); ++i ) { + if( (*i)-> getCommand()->getTask() == _htmlCurrTask ){ + TMLTime _endTime= (*i)->getEndTime(); + _maxEndTime=max(_maxEndTime,_endTime); + } + } + std::map <TMLTask*, double > transPercentage; + for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){ + if( (*i)-> getCommand()->getTask() == _htmlCurrTask ){ + transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime; + } + } + std::map <TMLTask*, double>::iterator iter = transPercentage.begin(); + myfile << " var ctx" << _ID << "_" << _htmlCurrTask->toShortString() << "= $(\"#pie-chartcanvas-" << _ID << "_" << _htmlCurrTask->toShortString() << "\");\n"; + + double idle=1; + myfile << " var data" << _ID << "_" << _htmlCurrTask->toShortString() << " = new Array ("; + while( iter != transPercentage.end()){ + myfile << "\"" << iter->second << "\","; + idle-=iter->second; + ++iter; + } + myfile << "\"" << idle << "\");\n"; + + myfile << " var efficiency" << _ID << "_" << _htmlCurrTask->toShortString() << " = [];" << std::endl; + myfile << " var coloR" << _ID << "_" << _htmlCurrTask->toShortString() << " = [];" << std::endl; + myfile << " var dynamicColors" << _ID << "_" << _htmlCurrTask->toShortString() << SCHED_HTML_JS_FUNCTION; + + myfile << " for (var i in data" << _ID << "_" << _htmlCurrTask->toShortString() << "){\n"; + myfile << " efficiency" << _ID << "_" << _htmlCurrTask->toShortString() << ".push(data" << _ID << "_" << _htmlCurrTask->toShortString() << "[i]);\n"; + myfile << " coloR" << _ID << "_" << _htmlCurrTask->toShortString() << ".push(dynamicColors" << _ID << "_" << _htmlCurrTask->toShortString() << "());\n"; + myfile << "}" << std::endl; + + myfile << " var data" << _ID << "_" << _htmlCurrTask->toShortString() << " = { \n"; + myfile << " labels : ["; + iter = transPercentage.begin(); + while( iter != transPercentage.end()){ + myfile << " \"" << iter->first->toString() << "\","; + idle-=iter->second; + ++iter; + } + myfile << "\"idle time\"],\n"; + myfile << " datasets : [\n \ + {\n \ + data : efficiency" << _ID << "_" << _htmlCurrTask->toShortString() << ",\n"; + myfile << " backgroundColor : coloR" << _ID << "_" << _htmlCurrTask->toShortString() << std::endl; + myfile << SCHED_HTML_JS_CONTENT1 << "Average load is " << averageLoad(_htmlCurrTask) << SCHED_HTML_JS_CONTENT2 << std::endl; + myfile << " var chart" << _ID << "_" << _htmlCurrTask->toShortString() << " = new Chart( "<< + "ctx" << _ID << "_" << _htmlCurrTask->toShortString() << ", {\n \ + type : \"pie\",\n"; + myfile << " data : data" << _ID << "_" << _htmlCurrTask->toShortString() <<",\n"; + myfile << " " << SCHED_HTML_JS_CONTENT3 << std::endl; + } void FPGA::showPieChart(std::ofstream& myfile) const{ - if(_taskNumber==1) + /* if(_taskNumber==1) myfile << SCHED_HTML_JS_DIV_ID << _ID << "_" << _htmlCurrTask->toShortString() << SCHED_HTML_JS_DIV_ID_END <<std::endl; else - myfile << SCHED_HTML_JS_DIV_ID << _ID << "_" << _htmlCurrTask->toShortString() << SCHED_HTML_JS_DIV_ID_END_FPGA <<std::endl; + myfile << SCHED_HTML_JS_DIV_ID << _ID << "_" << _htmlCurrTask->toShortString() << SCHED_HTML_JS_DIV_ID_END_FPGA <<std::endl;*/ + if( _taskNumber == 1) + myfile << SCHED_HTML_JS_DIV_BEGIN << std::endl; + else + myfile << SCHED_HTML_JS_DIV_BEGIN2 << std::endl; + myfile << SCHED_HTML_JS_BEGIN_CANVAS << _ID << "_" << _htmlCurrTask->toShortString() << SCHED_HTML_JS_END_CANVAS <<std::endl; + myfile << SCHED_HTML_JS_DIV_END << std::endl; } std::string FPGA::determineHTMLCellClass(unsigned int &nextColor ) { diff --git a/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp b/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp index 5792537c98ec4e206055e4a2ea9fcd1a362bbf03..aed5e10b504a3cd216283ed8ecc92c564f92cd7c 100644 --- a/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp +++ b/simulators/c++2/src_simulator/arch/SchedulableDevice.cpp @@ -211,42 +211,67 @@ double SchedulableDevice::averageLoad() const{ } -void SchedulableDevice::drawPieChart(std::ofstream& myfile) const { - +void SchedulableDevice::drawPieChart(std::ofstream& myfile) const { TMLTime _maxEndTime=0; for( TransactionList::const_iterator i = _transactList.begin(); i != _transactList.end(); ++i ) { TMLTime _endTime= (*i)->getEndTime(); _maxEndTime=max(_maxEndTime,_endTime); } + std::map <TMLTask*, double > transPercentage; - - - for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){ - - transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime; - + for( TransactionList::const_iterator i = _transactList.begin(); i!= _transactList.end(); ++i){ + transPercentage[(*i)-> getCommand()->getTask()]+=(double)((*i)->getEndTime()-(*i)->getStartTime())/_maxEndTime; } - + std::map <TMLTask*, double>::iterator iter = transPercentage.begin(); - myfile << " var chart" << _ID << "= new CanvasJS.Chart(\"chartContainer" << _ID <<"\"," << std::endl; - myfile << SCHED_HTML_JS_CONTENT2 << "Average load is " << averageLoad() << SCHED_HTML_JS_CONTENT2 << std::endl; + myfile << " var ctx" << _ID << "= $(\"#pie-chartcanvas-" << _ID << "\");\n"; + double idle=1; + myfile << " var data" << _ID << " = new Array ("; while( iter != transPercentage.end()){ - myfile << " { y:" << (iter->second)*100 << ", indexLabel: \"" << iter->first->toString() << "\" }," << std::endl; + myfile << "\"" << iter->second << "\","; idle-=iter->second; - ++iter; + ++iter; } - myfile << " { y:" << idle*100 << ", indexLabel: \"idle time\"" << " }" << std::endl; - myfile << std::endl; - myfile << SCHED_HTML_PIE_END; - myfile << "chart" << _ID << ".render();" << std::endl; + myfile << "\"" << idle << "\");\n"; + + myfile << " var efficiency" << _ID << " = [];" << std::endl; + myfile << " var coloR" << _ID << " = [];" << std::endl; + myfile << " var dynamicColors" << _ID << SCHED_HTML_JS_FUNCTION; + + myfile << " for (var i in data" << _ID << "){\n"; + myfile << " efficiency" << _ID << ".push(data" << _ID << "[i]);\n"; + myfile << " coloR" << _ID << ".push(dynamicColors" << _ID << "());\n"; + myfile << "}" << std::endl; + + myfile << " var data" << _ID << " = { \n"; + myfile << " labels : ["; + iter = transPercentage.begin(); + while( iter != transPercentage.end()){ + myfile << " \"" << iter->first->toString() << "\","; + idle-=iter->second; + ++iter; + } + myfile << "\"idle time\"],\n"; + myfile << " datasets : [\n \ + {\n \ + data : efficiency" << _ID << ",\n"; + myfile << " backgroundColor : coloR" << _ID << std::endl; + myfile << SCHED_HTML_JS_CONTENT1 << "Average load is " << averageLoad() << SCHED_HTML_JS_CONTENT2 << std::endl; + myfile << " var chart" << _ID << " = new Chart( "<< + "ctx" << _ID << ", {\n \ + type : \"pie\",\n"; + myfile << " data : data" << _ID << ",\n"; + myfile << " " << SCHED_HTML_JS_CONTENT3 << std::endl; } void SchedulableDevice::showPieChart(std::ofstream& myfile) const{ - myfile << SCHED_HTML_JS_DIV_ID << _ID << SCHED_HTML_JS_DIV_ID_END << "<br>"; + myfile << SCHED_HTML_JS_DIV_BEGIN << std::endl; + myfile << SCHED_HTML_JS_BEGIN_CANVAS << _ID << SCHED_HTML_JS_END_CANVAS <<std::endl; + myfile << SCHED_HTML_JS_DIV_END << std::endl; } diff --git a/simulators/c++2/src_simulator/definitions.h b/simulators/c++2/src_simulator/definitions.h index 1ab96e76acd7f560eb6a7525d15f32534904daf8..af775c8c9b7c6c11a58d96ea4fb5138404f9348b 100644 --- a/simulators/c++2/src_simulator/definitions.h +++ b/simulators/c++2/src_simulator/definitions.h @@ -269,16 +269,25 @@ using std::max; #define SCHED_HTML_END_JS "</script>\n" #define SCHED_HTML_JS_BEGIN_CANVAS " <canvas id=\"pie-chartcanvas-" #define SCHED_HTML_JS_END_CANVAS "\"></canvas>" -#define SCHED_HTML_JS_WINDOW "window.onload = function () {" +#define SCHED_HTML_JS_WINDOW "window.onload = function () {\n" #define SCHED_HTML_JS_DIV_BEGIN "<div class=\"wrapper\">" +#define SCHED_HTML_JS_DIV_BEGIN2 "<div class=\"pie-chart-container\">" #define SCHED_HTML_JS_DIV_END "</div>" -#define SCHED_HTML_JS_DIV_ID "<div id=\"chartContainer" -#define SCHED_HTML_JS_DIV_ID_END "\" style=\"height: 300px; width: 300px;\"></div>\n" -#define SCHED_HTML_JS_DIV_ID_END_FPGA "\" style=\"height: 300px; width: 300px;float:left;margin-right:40px;\"></div>\n" #define SCHED_HTML_JS_CLEAR "<div class = \"clear\"></div>" #define NB_HTML_COLORS 15 -#define SCHED_HTML_JS_CONTENT1 "var options = {\n \ +#define SCHED_HTML_JS_FUNCTION "= function() {\n \ + var r = Math.floor(Math.random() * 255);\n \ + var g = Math.floor(Math.random() * 255);\n \ + var b = Math.floor(Math.random() * 255);\n \ + return \"rgb(\" + r + \",\" + g + \",\" + b + \")\";\n \ + };\n" + + +#define SCHED_HTML_JS_CONTENT1 " }\n \ + ]\n \ +};\n \ + var options = {\n \ title : {\n \ display : true,\n \ position : \"top\",\n \ @@ -550,6 +559,11 @@ h2 span {\n \ width: 256px;\n \ height: 256px;\n \ }\n \ +.pie-chart-container {\n \ + width : 256px;\n \ + height : 256px;\n \ + float : left;\n \ +}\n \ .clear {\n \ clear:both\n \ }" diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index 9375232cd34ffbb1958162dc7bd0a0dbccb4fdff..4e51e22ea468f4a42c56a804653c758942a89db0 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -425,6 +425,8 @@ std::cout<<"schedule2HTML--------------------------------------***************** myfile << SCHED_HTML_JS_LINK1 << SCHED_HTML_END_JS << std::endl; myfile << SCHED_HTML_JS_LINK2 << SCHED_HTML_END_JS << std::endl; myfile << SCHED_HTML_BEGIN_JS << std::endl; + + myfile << SCHED_HTML_JS_WINDOW; for(CPUList::const_iterator i=_simComp->getCPUList().begin(); i != _simComp->getCPUList().end(); ++i){ (*i)->drawPieChart(myfile); } @@ -435,7 +437,7 @@ std::cout<<"schedule2HTML--------------------------------------***************** } } for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ - // (*j)->drawPieChart(myfile); + (*j)->drawPieChart(myfile); } myfile << "}" <<std::endl; @@ -471,18 +473,16 @@ std::cout<<"schedule2HTML--------------------------------------***************** (*j)->schedule2HTML(myfile); (*j)->setStartFlagHTML(false); } - myfile << SCHED_HTML_JS_DIV_BEGIN << std::endl; for(TaskList::const_iterator i = (*j)->getTaskList().begin(); i != (*j)->getTaskList().end(); ++i){ (*j)->setHtmlCurrTask(*i); (*j)->showPieChart(myfile); } - myfile << SCHED_HTML_JS_DIV_END <<std::endl; myfile << SCHED_HTML_JS_CLEAR <<std::endl; } for(BusList::const_iterator j=_simComp->getBusList().begin(); j != _simComp->getBusList().end(); ++j){ (*j)->schedule2HTML(myfile); - // (*j)->showPieChart(myfile); + (*j)->showPieChart(myfile); } //for_each(iCPUlist.begin(), iCPUlist.end(),std::bind2nd(std::mem_fun(&CPU::schedule2HTML),myfile));