@@ -65,6 +65,7 @@ void print_usage(const string & progname)
6565 cout << " -e cha/config=0,name=UNC_CHA_CLOCKTICKS/ -e imc/fixed,name=DRAM_CLOCKS/\n " ;
6666#ifdef PCM_SIMDJSON_AVAILABLE
6767 cout << " -e NAME where the NAME is an event from https://github.com/intel/perfmon event lists\n " ;
68+ cout << " -? | /? => print all events that can be monitored on the host platform along with a description\n " ;
6869 cout << " -ep path | /ep path => path to event list directory (default is the current directory)\n " ;
6970#endif
7071 cout << " -yc | --yescores | /yc => enable specific cores to output\n " ;
@@ -217,16 +218,24 @@ bool initPMUEventMap()
217218 inited = true ;
218219 const auto mapfile = " mapfile.csv" ;
219220 const auto mapfilePath = eventFileLocationPrefix + " /" + mapfile;
221+ const auto mapfilePathAlt = getInstallPathPrefix () + " perfmon/" + mapfile;
220222 std::ifstream in (mapfilePath);
221223 std::string line, item;
222224
223225 if (!in.is_open ())
224226 {
225- cerr << " ERROR: File " << mapfilePath << " can't be open. \n " ;
226- cerr << " Use -ep <pcm_source_directory>/perfmon option if you cloned PCM source repository recursively with submodules,\n " ;
227- cerr << " or run 'git clone https://github.com/intel/perfmon' to download the perfmon event repository and use -ep <perfmon_directory> option\n " ;
228- cerr << " or download the file from https://raw.githubusercontent.com/intel/perfmon/main/" << mapfile << " \n " ;
229- return false ;
227+ in.open (mapfilePathAlt);
228+ if (!in.is_open ())
229+ {
230+ cerr << " ERROR: File " << mapfilePath << " or " << mapfilePathAlt << " can't be open. \n " ;
231+ #ifndef _MSC_VER
232+ cerr << " run 'make install' in the pcm build directory if you cloned PCM source repository recursively with submodules, or\n " ;
233+ #endif
234+ cerr << " use -ep <pcm_source_directory>/perfmon option if you cloned PCM source repository recursively with submodules,\n " ;
235+ cerr << " or run 'git clone https://github.com/intel/perfmon' to download the perfmon event repository and use -ep <perfmon_directory> option\n " ;
236+ cerr << " or download the file from https://raw.githubusercontent.com/intel/perfmon/main/" << mapfile << " \n " ;
237+ return false ;
238+ }
230239 }
231240 int32 FMSPos = -1 ;
232241 int32 FilenamePos = -1 ;
@@ -255,12 +264,12 @@ bool initPMUEventMap()
255264 cerr << " Can't read first line from " << mapfile << " \n " ;
256265 return false ;
257266 }
258- // cout << FMSPos << " " << FilenamePos << " " << EventTypetPos << "\n" ;
267+ DBG ( 1 , FMSPos , " " , FilenamePos , " " , EventTypetPos) ;
259268 assert (FMSPos >= 0 );
260269 assert (FilenamePos >= 0 );
261270 assert (EventTypetPos >= 0 );
262271 const std::string ourFMS = PCM::getInstance ()->getCPUFamilyModelString ();
263- // cout << "Our FMS: " << ourFMS << "\n" ;
272+ DBG ( 1 , " Our FMS: " , ourFMS) ;
264273 std::multimap<std::string, std::string> eventFiles;
265274 cerr << " Matched event files:\n " ;
266275 while (std::getline (in, line))
@@ -300,6 +309,7 @@ bool initPMUEventMap()
300309 {
301310 const std::string path1 = eventFileLocationPrefix + evfile.second ;
302311 const std::string path2 = eventFileLocationPrefix + evfile.second .substr (evfile.second .rfind (' /' ));
312+ const std::string path3 = getInstallPathPrefix () + " perfmon" + evfile.second ;
303313
304314 if (std::ifstream (path1).good ())
305315 {
@@ -309,9 +319,13 @@ bool initPMUEventMap()
309319 {
310320 path = path2;
311321 }
322+ else if (std::ifstream (path3).good ())
323+ {
324+ path = path3;
325+ }
312326 else
313327 {
314- std::cerr << " ERROR: Can't open event file at location " << path1 << " or " << path2 << " \n " ;
328+ std::cerr << " ERROR: Can't open event file at location " << path1 << " or " << path2 << " or " << path3 << " \n " ;
315329 printError ();
316330 return false ;
317331 }
@@ -351,7 +365,7 @@ bool initPMUEventMap()
351365 catch (std::exception& e)
352366 {
353367 cerr << " Error while opening and/or parsing " << path << " : " << e.what () << " \n " ;
354- printError ();
368+ printError ();
355369 return false ;
356370 }
357371 }
@@ -418,6 +432,15 @@ class EventMap {
418432 return res;
419433 }
420434
435+ static void print_event_description (const std::string &eventStr) {
436+ if (PMUEventMapJSON.find (eventStr) != PMUEventMapJSON.end ()) {
437+ const auto eventObj = PMUEventMapJSON[eventStr];
438+ for (const auto & key : {" BriefDescription" , " PublicDescription" })
439+ std::cout << key << " : " << eventObj[key] << " \n " ;
440+ return ;
441+ }
442+ }
443+
421444 static void print_event (const std::string &eventStr) {
422445 if (PMUEventMapJSON.find (eventStr) != PMUEventMapJSON.end ()) {
423446 const auto eventObj = PMUEventMapJSON[eventStr];
@@ -437,19 +460,52 @@ class EventMap {
437460 }
438461 }
439462 }
463+ }
440464
465+ static void print_event_debug (const std::string &eventStr, const int debugLevel = 1 ) {
466+ if (PMUEventMapJSON.find (eventStr) != PMUEventMapJSON.end ()) {
467+ const auto eventObj = PMUEventMapJSON[eventStr];
468+ for (const auto & keyValue : eventObj)
469+ DBG (debugLevel, " JSON " , keyValue.key , " : " , keyValue.value );
470+ }
471+
472+ for (auto &EventMapTSV : PMUEventMapsTSV) {
473+ if (EventMapTSV.find (eventStr) != EventMapTSV.end ()) {
474+ const auto &col_names = EventMapTSV[" COL_NAMES" ];
475+ const auto event = EventMapTSV[eventStr];
476+ if (EventMapTSV.find (eventStr) != EventMapTSV.end ()) {
477+ for (size_t i = 0 ; i < col_names.size () ; i++)
478+ DBG (debugLevel, " TSV " , col_names[i] , " : " , event[i]);
479+ }
480+ }
481+ }
441482 }
442483};
443484
485+ void printAllEventDescriptions ()
486+ {
487+ if (initPMUEventMap () == false )
488+ {
489+ cerr << " ERROR: PMU Event map can not be initialized\n " ;
490+ return ;
491+ }
492+ for (const auto & event : PMUEventMapJSON)
493+ {
494+ std::cout << event.first << " \n " ;
495+ EventMap::print_event_description (event.first );
496+ std::cout << " \n " ;
497+ }
498+ }
499+
444500AddEventStatus addEventFromDB (PCM::RawPMUConfigs& curPMUConfigs, string fullEventStr)
445501{
446502 if (initPMUEventMap () == false )
447503 {
448504 cerr << " ERROR: PMU Event map can not be initialized\n " ;
449505 return AddEventStatus::Failed;
450506 }
451- // cerr << "Parsing event " << fullEventStr << "\n" ;
452- // cerr << "size: " << fullEventStr.size() << "\n" ;
507+ DBG ( 2 , " Parsing event " , fullEventStr) ;
508+ DBG ( 2 , " size: " , fullEventStr.size ()) ;
453509 while (fullEventStr.empty () == false && fullEventStr.back () == ' ' )
454510 {
455511 fullEventStr.resize (fullEventStr.size () - 1 ); // remove trailing spaces
@@ -469,7 +525,9 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
469525
470526 const auto eventStr = EventTokens[0 ];
471527
472- // cerr << "size: " << eventStr.size() << "\n";
528+ EventMap::print_event_debug (eventStr);
529+
530+ DBG (2 , " size: " , eventStr.size ());
473531 PCM::RawEventConfig config = { {0 ,0 ,0 ,0 ,0 }, " " };
474532 std::string pmuName;
475533
@@ -623,17 +681,17 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
623681 {
624682 std::string unit = EventMap::getField (eventStr, " Unit" );
625683 lowerCase (unit);
626- // std::cout << eventStr << " is uncore event for unit " << unit << "\n" ;
684+ DBG ( 2 , eventStr , " is uncore event for unit " , unit) ;
627685 pmuName = (pmuNameMap.find (unit) == pmuNameMap.end ()) ? unit : pmuNameMap[unit];
628686 }
629687
630688 config.second = fullEventStr;
631689
632690 if (1 )
633691 {
634- // cerr << "pmuName: " << pmuName << " full event "<< fullEventStr << " \n" ;
692+ DBG ( 2 , " pmuName: " , pmuName , " full event " , fullEventStr) ;
635693 std::string CounterStr = EventMap::getField (eventStr, " Counter" );
636- // cout << "Counter: " << CounterStr << "\n" ;
694+ DBG ( 2 , " Counter: " , CounterStr) ;
637695 int fixedCounter = -1 ;
638696 fixed = (pcm_sscanf (CounterStr) >> s_expect (" Fixed counter " ) >> fixedCounter) ? true : false ;
639697 if (!fixed){
@@ -707,15 +765,15 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
707765 };
708766 for (const auto & registerKeyValue : PMUDeclObj)
709767 {
710- // cout << "Setting " << registerKeyValue.key << " : " << registerKeyValue.value << "\n" ;
768+ DBG ( 2 , " Setting " , registerKeyValue.key , " : " , registerKeyValue.value ) ;
711769 simdjson::dom::object fieldDescriptionObj = registerKeyValue.value ;
712- // cout << " config: " << uint64_t(fieldDescriptionObj["Config"]) << "\n" ;
713- // cout << " Position: " << uint64_t(fieldDescriptionObj["Position"]) << "\n" ;
770+ DBG ( 2 , " config: " , uint64_t (fieldDescriptionObj[" Config" ])) ;
771+ DBG ( 2 , " Position: " , uint64_t (fieldDescriptionObj[" Position" ])) ;
714772 const std::string fieldNameStr{ registerKeyValue.key .begin (), registerKeyValue.key .end () };
715773 if (fieldNameStr == " MSRIndex" )
716774 {
717775 string fieldValueStr = EventMap::getField (eventStr, fieldNameStr);
718- // cout << "MSR field " << fieldNameStr << " value is " << fieldValueStr << " (" << read_number(fieldValueStr.c_str()) << ") offcore=" << offcore << "\n" ;
776+ DBG ( 2 , " MSR field " , fieldNameStr , " value is " , fieldValueStr , " (" , read_number (fieldValueStr.c_str ()) , " ) offcore=" , offcore); ;
719777 lowerCase (fieldValueStr);
720778 if (fieldValueStr == " 0" || fieldValueStr == " 0x00" )
721779 {
@@ -732,7 +790,7 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
732790 }
733791 MSRIndexStr = MSRIndexes[offcoreEventIndex];
734792 }
735- // cout << " MSR field " << fieldNameStr << " value is " << MSRIndexStr << " (" << read_number(MSRIndexStr.c_str()) << ") offcore=" << offcore << "\n" ;
793+ DBG ( 2 , " MSR field " , fieldNameStr , " value is " , MSRIndexStr , " (" , read_number (MSRIndexStr.c_str ()) , " ) offcore=" , offcore) ;
736794 MSRObject = registerKeyValue.value [MSRIndexStr];
737795 const string msrValueStr = EventMap::getField (eventStr, " MSRValue" );
738796 setMSRValue (msrValueStr);
@@ -745,7 +803,7 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
745803 }
746804 if (!EventMap::isField (eventStr, fieldNameStr))
747805 {
748- // cerr << fieldNameStr << " not found\n" ;
806+ DBG ( 2 , fieldNameStr , " not found" ) ;
749807 if (fieldDescriptionObj[" DefaultValue" ].error () == NO_SUCH_FIELD)
750808 {
751809 cerr << " ERROR: DefaultValue not provided for field \" " << fieldNameStr << " \" in " << path << " \n " ;
@@ -773,7 +831,7 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
773831 }
774832 fieldValueStr = offcoreCodes[offcoreEventIndex];
775833 }
776- // cout << " field " << fieldNameStr << " value is " << fieldValueStr << " (" << read_number(fieldValueStr.c_str()) << ") offcore=" << offcore << "\n" ;
834+ DBG ( 2 , " field " , fieldNameStr , " value is " , fieldValueStr , " (" , read_number (fieldValueStr.c_str ()) , " ) offcore=" , offcore) ;
777835 setConfig (config, fieldDescriptionObj, read_number (fieldValueStr.c_str ()), position);
778836 }
779837 }
@@ -921,13 +979,6 @@ AddEventStatus addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEven
921979 }
922980 }
923981
924- /*
925- for (const auto& keyValue : eventObj)
926- {
927- cout << keyValue.key << " : " << keyValue.value << "\n";
928- }
929- */
930-
931982 printEvent (pmuName, fixed, config);
932983
933984 return AddEventStatus::OK;
@@ -2475,6 +2526,13 @@ int mainThrows(int argc, char * argv[])
24752526 extendPrintout = true ;
24762527 continue ;
24772528 }
2529+ #if PCM_SIMDJSON_AVAILABLE
2530+ else if (check_argument_equals (*argv, {" -?" , " /?" }))
2531+ {
2532+ printAllEventDescriptions ();
2533+ return 0 ;
2534+ }
2535+ #endif
24782536 else if (check_argument_equals (*argv, {" -single-header" , " /single-header" }))
24792537 {
24802538 singleHeader = true ;
@@ -2736,9 +2794,6 @@ int mainThrows(int argc, char * argv[])
27362794 }
27372795 m->globalUnfreezeUncoreCounters ();
27382796
2739- // cout << "Time elapsed: " << dec << fixed << AfterTime - BeforeTime << " ms\n";
2740- // cout << "Called sleep function for " << dec << fixed << delay_ms << " ms\n";
2741-
27422797 printAll (group, m, SysBeforeState, SysAfterState, BeforeState, AfterState, BeforeUncoreState, AfterUncoreState, BeforeSocketState, AfterSocketState, PMUConfigs, groupNr == nGroups);
27432798 if (nGroups == 1 )
27442799 {
0 commit comments