Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. bool Initialize() {
  2.     SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
  3.     TCHAR driverPath[1024];
  4.     GetCurrentDirectory(1024, driverPath);
  5.     wcscat(driverPath, L"\\msr.sys");
  6.                
  7.     if (!drv.start(driverPath))
  8.     {
  9.         std::cout << "Cannot access CPU counters" << std::endl;
  10.         std::cout << "You must have signed msr.sys driver in your current directory and have administrator rights to run this program" << std::endl;
  11.     }
  12.        
  13.     pcm = PCM::getInstance();
  14.     PCM::ErrorCode status = pcm->program();
  15.  
  16.     switch (status) {
  17.         case PCM::Success:
  18.             break;
  19.         case PCM::MSRAccessDenied:
  20.             std::cout << "Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access)." << std::endl;
  21.             goto err;
  22.         case PCM::PMUBusy:
  23.             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;
  24.             std::cout << "Alternatively you can try to reset PMU configuration at your own risk. Try to reset? (y/n)" << std::endl;
  25.             char yn;
  26.             std::cin >> yn;
  27.             if ('y' == yn)
  28.             {
  29.                 pcm->resetPMU();
  30.                 std::cout << "PMU configuration has been reset. Try to rerun the program again." << std::endl;
  31.             }
  32.             goto err;
  33.         default:
  34.             std::cout << "Access to Intel(r) Performance Counter Monitor has denied (Unknown error)." << std::endl;
  35.             goto err;
  36.     }
  37.  
  38.     cstates    = new CoreCounterState[pcm->getNumCores()];
  39.     sktstate1  = new SocketCounterState[pcm->getNumSockets()];
  40.     sktstate2  = new SocketCounterState[pcm->getNumSockets()];
  41.  
  42.     return true;
  43. err:
  44.     pcm->resetPMU();
  45.     return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement