Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Initialize() {
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
- TCHAR driverPath[1024];
- GetCurrentDirectory(1024, driverPath);
- wcscat(driverPath, L"\\msr.sys");
- if (!drv.start(driverPath))
- {
- std::cout << "Cannot access CPU counters" << std::endl;
- std::cout << "You must have signed msr.sys driver in your current directory and have administrator rights to run this program" << std::endl;
- }
- pcm = PCM::getInstance();
- PCM::ErrorCode status = pcm->program();
- switch (status) {
- case PCM::Success:
- break;
- case PCM::MSRAccessDenied:
- std::cout << "Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access)." << std::endl;
- goto err;
- case PCM::PMUBusy:
- std::cout << "Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application). Try to stop the application that uses PMU." << std::endl;
- std::cout << "Alternatively you can try to reset PMU configuration at your own risk. Try to reset? (y/n)" << std::endl;
- char yn;
- std::cin >> yn;
- if ('y' == yn)
- {
- pcm->resetPMU();
- std::cout << "PMU configuration has been reset. Try to rerun the program again." << std::endl;
- }
- goto err;
- default:
- std::cout << "Access to Intel(r) Performance Counter Monitor has denied (Unknown error)." << std::endl;
- goto err;
- }
- cstates = new CoreCounterState[pcm->getNumCores()];
- sktstate1 = new SocketCounterState[pcm->getNumSockets()];
- sktstate2 = new SocketCounterState[pcm->getNumSockets()];
- return true;
- err:
- pcm->resetPMU();
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement