本文整理汇总了C++中Energy::getCounter方法的典型用法代码示例。如果您正苦于以下问题:C++ Energy::getCounter方法的具体用法?C++ Energy::getCounter怎么用?C++ Energy::getCounter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Energy
的用法示例。
在下文中一共展示了Energy::getCounter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv){
Mammut m;
Energy* energy = m.getInstanceEnergy();
/** Gets the power plug counter. **/
CounterPlug* counterPlug = dynamic_cast<CounterPlug*>(energy->getCounter(COUNTER_PLUG));
if(!counterPlug){
cout << "Plug counter not present on this machine." << endl;
}
/** Gets the CPUs energy counters. **/
CounterCpus* counterCpus = dynamic_cast<CounterCpus*>(energy->getCounter(COUNTER_CPUS));
if(!counterCpus){
cout << "Cpu counters not present on this machine." << endl;
}
/** Prints information for each counter. **/
if(counterCpus){
cout << "Found Cpus counter ";
cout << "Has cores counter: " << counterCpus->hasJoulesCores() << " ";
cout << "Has graphic counter: " << counterCpus->hasJoulesGraphic() << " ";
cout << "Has Dram counter: " << counterCpus->hasJoulesDram() << " ";
cout << endl;
}
/** Gets the value of the counter every sleepingSecs seconds. **/
unsigned int sleepingSecs = 10;
unsigned int iterations = 4;
for(unsigned int i = 0; i < iterations; i++){
cout << "Sleeping " << sleepingSecs << " seconds." << endl;
sleep(sleepingSecs);
if(counterPlug){
cout << "Joules consumed at power plug: " << counterPlug->getJoules() << endl;
counterPlug->reset();
}
if(counterCpus){
vector<Cpu*> cpus = m.getInstanceTopology()->getCpus();
for(size_t j = 0; j < cpus.size(); j++){
CpuId id = cpus.at(j)->getCpuId();
cout << "Joules consumed for CPU " << id << ": ";
cout << "Cpu: " << counterCpus->getJoulesCpu(id) << " ";
if(counterCpus->hasJoulesCores()){
cout << "Cores: " << counterCpus->getJoulesCores(id) << " ";
}
if(counterCpus->hasJoulesGraphic()){
cout << "Graphic: " << counterCpus->getJoulesGraphic(id) << " ";
}
if(counterCpus->hasJoulesDram()){
cout << "Dram: " << counterCpus->getJoulesDram(id) << " ";
}
cout << endl;
}
counterCpus->reset();
}
}
}