当前位置: 首页>>代码示例>>C++>>正文


C++ Energy::getCounter方法代码示例

本文整理汇总了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();
	}
    }
}
开发者ID:DanieleDeSensi,项目名称:mammut,代码行数:57,代码来源:demo-energy-extended.cpp


注:本文中的Energy::getCounter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。