00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <qvblockprogramming/qvcpustatcontroler.h>
00026
00027 #include <iostream>
00028
00029 void QVStatControler::step()
00030 {
00031 if (freq > 0)
00032 {
00033 for (int i = 0; i < cpustats.getFlagNames().size(); i++)
00034 accumulated[i] += cpustats.getLastStats()[i];
00035 rounds++;
00036 if ( (rounds % freq) == 0 ) printStats();
00037 }
00038
00039 lastFlagPos = -1;
00040 lastTime.start();
00041 }
00042
00043
00044 void QVStatControler::setFreq(int frequency)
00045 {
00046 if (frequency >= 0)
00047 {
00048 freq = frequency;
00049 for (int i = 0; i < cpustats.getFlagNames().size(); i++)
00050 accumulated[i] = 0;
00051 rounds = 0;
00052 }
00053 }
00054
00055 void QVStatControler::printStats()
00056 {
00057 for (int i = 0; i < cpustats.getFlagNames().size(); i++)
00058 totalAccumulated[i] += (accumulated[i] / rounds);
00059 totalRounds++;
00060
00061 std::cout << "Cpu stats of " << blockName.toStdString() << ": Iteration " << totalRounds << " (steps elapsed " << rounds << ")." << std::endl;
00062 std::cout << "Cpu stats:\t\tMean Total\tMean Actual\tFlag name" << std::endl;
00063 for (int i = 0; i< cpustats.getFlagNames().size(); i++)
00064 std::cout << "CpuStat: stats:\t\t" << totalAccumulated[i]/(double)totalRounds << "\t\t" << (accumulated[i] / rounds) << "\t\t"
00065 << cpustats.getFlagNames().at(i).toStdString() << std::endl;
00066 std::cout << "Cpu stats:" << std::endl;
00067
00068 for (int i = 0; i < cpustats.getFlagNames().size(); i++)
00069 accumulated[i] = 0;
00070 rounds = 0;
00071 }
00072
00073
00074 void QVStatControler::setFlag(QString flagName)
00075 {
00076 bool exist = (cpustats.getFlagNames()).contains(flagName);
00077 double elapsedTime = lastTime.restart();
00078
00079 lastFlagPos++;
00080 if (!exist)
00081 {
00082 cpustats.addFlag(lastFlagPos, flagName);
00083 accumulated.insert(lastFlagPos, 0);
00084 totalAccumulated.insert(lastFlagPos, 0);
00085 }
00086 cpustats.setValue(lastFlagPos, elapsedTime);
00087 }
00088
00089
00090
00091