Skip to content

Commit

Permalink
Merge pull request #814 from artiomn/master
Browse files Browse the repository at this point in the history
PCM::checkStatus() implemented
  • Loading branch information
rdementi authored Aug 14, 2024
2 parents db66fd7 + e3f3fb7 commit 66121f8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
67 changes: 46 additions & 21 deletions src/cpucounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <condition_variable>
#include <mutex>
#include <atomic>
#include <system_error>

#ifdef __APPLE__
#include <sys/types.h>
Expand Down Expand Up @@ -3834,30 +3835,54 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
return PCM::Success;
}

void PCM::checkStatus(const PCM::ErrorCode status)
{
switch (status)
{
case pcm::PCM::Success:
{
break;
}
case pcm::PCM::MSRAccessDenied:
throw std::system_error(pcm::PCM::MSRAccessDenied, std::generic_category(),
"Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access).");
case pcm::PCM::PMUBusy:
throw std::system_error(pcm::PCM::PMUBusy, std::generic_category(),
"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,"
" or reset PMU configuration from PCM application itself");
default:
throw std::system_error(pcm::PCM::UnknownError, std::generic_category(),
"Access to Intel(r) Performance Counter Monitor has denied (Unknown error).");
}
}

void PCM::checkError(const PCM::ErrorCode code)
{
switch (code)
try
{
case PCM::Success:
break;
case PCM::MSRAccessDenied:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access).\n";
exit(EXIT_FAILURE);
case PCM::PMUBusy:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application)\n";
std::cerr << "Try to stop the application that uses PMU, or reset PMU configuration from PCM application itself\n";
std::cerr << "You can try to reset PMU configuration now. Try to reset? (y/n)\n";
char yn;
std::cin >> yn;
if ('y' == yn)
{
resetPMU();
std::cerr << "PMU configuration has been reset. Try to rerun the program again.\n";
}
exit(EXIT_FAILURE);
default:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (Unknown error).\n";
exit(EXIT_FAILURE);
checkStatus(code);
}
catch (const std::system_error &e)
{
switch (e.code().value())
{
case PCM::PMUBusy:
std::cerr << e.what() << "\n"
<< "You can try to reset PMU configuration now. Try to reset? (y/n)" << std::endl;
char yn;
std::cin >> yn;
if ('y' == yn)
{
resetPMU();
std::cerr << "PMU configuration has been reset. Try to rerun the program again." << std::endl;
}
exit(EXIT_FAILURE);
case PCM::MSRAccessDenied:
default:
std::cerr << e.what() << std::endl;
exit(EXIT_FAILURE);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/cpucounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,12 @@ class PCM_API PCM
*/
ErrorCode program(const ProgramMode mode_ = DEFAULT_EVENTS, const void * parameter_ = NULL, const bool silent = false, const int pid = -1); // program counters and start counting

/*! \brief checks the error without side effects.
\throw std::system_error generic_category exception with PCM error code.
\param code error code from the 'program' call
*/
void checkStatus(const ErrorCode status);

/*! \brief checks the error and suggests solution and/or exits the process
\param code error code from the 'program' call
*/
Expand Down

0 comments on commit 66121f8

Please sign in to comment.