@@ -70,7 +70,7 @@ bool anyPmem(const ServerUncoreMemoryMetrics & metrics)
7070
7171bool skipInactiveChannels = true ;
7272
73- void print_help (const string prog_name)
73+ void print_help (const string & prog_name)
7474{
7575 cout << " \n Usage: \n " << prog_name
7676 << " --help | [delay] [options] [-- external_program [external_program_options]]\n " ;
@@ -1002,6 +1002,8 @@ int main(int argc, char * argv[])
10021002 {
10031003 argv++;
10041004 argc--;
1005+ string arg_value;
1006+
10051007 if (check_argument_equals (*argv, {" --help" , " -h" , " /h" }))
10061008 {
10071009 print_help (program);
@@ -1012,117 +1014,101 @@ int main(int argc, char * argv[])
10121014 // handled in check_and_set_silent
10131015 continue ;
10141016 }
1015- else if (strncmp (*argv, " -csv" ,4 ) == 0 ||
1016- strncmp (*argv, " /csv" ,4 ) == 0 )
1017+ else if (check_argument_equals (*argv, {" -csv" , " /csv" }))
1018+ {
1019+ csv = csvheader = true ;
1020+ }
1021+ else if (extract_argument_value (*argv, {" -csv" , " /csv" }, arg_value))
10171022 {
10181023 csv = true ;
10191024 csvheader = true ;
1020- string cmd = string (*argv);
1021- size_t found = cmd.find (' =' ,4 );
1022- if (found != string::npos) {
1023- string filename = cmd.substr (found+1 );
1024- if (!filename.empty ()) {
1025- m->setOutput (filename);
1026- }
1025+ if (!arg_value.empty ()) {
1026+ m->setOutput (arg_value);
10271027 }
10281028 continue ;
10291029 }
10301030 else if (mainLoop.parseArg (*argv))
10311031 {
10321032 continue ;
10331033 }
1034- else if (strncmp (*argv, " -columns" , 8 ) == 0 ||
1035- strncmp (*argv, " /columns" , 8 ) == 0 )
1034+ else if (extract_argument_value (*argv, {" -columns" , " /columns" }, arg_value))
10361035 {
1037- string cmd = string (*argv);
1038- size_t found = cmd.find (' =' ,2 );
1039- if (found != string::npos) {
1040- no_columns = atoi (cmd.substr (found+1 ).c_str ());
1041- if (no_columns == 0 )
1042- no_columns = DEFAULT_DISPLAY_COLUMNS;
1043- if (no_columns > m->getNumSockets ())
1044- no_columns = m->getNumSockets ();
1036+ if (arg_value.empty ()) {
1037+ continue ;
10451038 }
1039+ no_columns = stoi (arg_value);
1040+ if (no_columns == 0 )
1041+ no_columns = DEFAULT_DISPLAY_COLUMNS;
1042+ if (no_columns > m->getNumSockets ())
1043+ no_columns = m->getNumSockets ();
10461044 continue ;
10471045 }
1048- else if (strncmp (*argv, " -rank" , 5 ) == 0 ||
1049- strncmp (*argv, " /rank" , 5 ) == 0 )
1046+ else if (extract_argument_value (*argv, {" -rank" , " /rank" }, arg_value))
10501047 {
1051- string cmd = string (*argv);
1052- size_t found = cmd.find (' =' ,2 );
1053- if (found != string::npos) {
1054- int rank = atoi (cmd.substr (found+1 ).c_str ());
1055- if (rankA >= 0 && rankB >= 0 )
1056- {
1057- cerr << " At most two DIMM ranks can be monitored \n " ;
1048+ if (arg_value.empty ()) {
1049+ continue ;
1050+ }
1051+ int rank = stoi (arg_value);
1052+ if (rankA >= 0 && rankB >= 0 )
1053+ {
1054+ cerr << " At most two DIMM ranks can be monitored \n " ;
1055+ exit (EXIT_FAILURE);
1056+ } else {
1057+ if (rank > 7 ) {
1058+ cerr << " Invalid rank number " << rank << " \n " ;
10581059 exit (EXIT_FAILURE);
1059- } else {
1060- if (rank > 7 ) {
1061- cerr << " Invalid rank number " << rank << " \n " ;
1062- exit (EXIT_FAILURE);
1063- }
1064- if (rankA < 0 ) rankA = rank;
1065- else if (rankB < 0 ) rankB = rank;
1066- metrics = PartialWrites;
10671060 }
1061+ if (rankA < 0 ) rankA = rank;
1062+ else if (rankB < 0 ) rankB = rank;
1063+ metrics = PartialWrites;
10681064 }
10691065 continue ;
10701066 }
1071- else if (strncmp (*argv, " --nochannel" , 11 ) == 0 ||
1072- strncmp (*argv, " -nc" , 3 ) == 0 ||
1073- strncmp (*argv, " /nc" , 3 ) == 0 )
1067+ else if (check_argument_equals (*argv, {" --nochannel" , " /nc" , " -nc" }))
10741068 {
10751069 show_channel_output = false ;
10761070 continue ;
10771071 }
1078- else if (strncmp (*argv, " -pmm" , 4 ) == 0 ||
1079- strncmp (*argv, " /pmm" , 4 ) == 0 ||
1080- strncmp (*argv, " -pmem" , 5 ) == 0 ||
1081- strncmp (*argv, " /pmem" , 5 ) == 0 )
1072+ else if (check_argument_equals (*argv, {" -pmm" , " /pmm" , " -pmem" , " /pmem" }))
10821073 {
10831074 metrics = Pmem;
10841075 continue ;
10851076 }
1086- else if (strncmp (*argv, " -all" , 4 ) == 0 ||
1087- strncmp (*argv, " /all" , 4 ) == 0 )
1077+ else if (check_argument_equals (*argv, {" -all" , " /all" }))
10881078 {
10891079 skipInactiveChannels = false ;
10901080 continue ;
10911081 }
1092- else if (strncmp (*argv, " -mixed" , 6 ) == 0 ||
1093- strncmp (*argv, " /mixed" , 6 ) == 0 )
1082+ else if (check_argument_equals (*argv, {" -mixed" , " /mixed" }))
10941083 {
10951084 metrics = PmemMixedMode;
10961085 continue ;
10971086 }
1098- else if (strncmp (*argv, " -mm" , 3 ) == 0 ||
1099- strncmp (*argv, " /mm" , 3 ) == 0 )
1087+ else if (check_argument_equals (*argv, {" -mm" , " /mm" }))
11001088 {
11011089 metrics = PmemMemoryMode;
11021090 show_channel_output = false ;
11031091 continue ;
11041092 }
1105- else if (strncmp (*argv, " -partial" , 8 ) == 0 ||
1106- strncmp (*argv, " /partial" , 8 ) == 0 )
1093+ else if (check_argument_equals (*argv, {" -partial" , " /partial" }))
11071094 {
11081095 metrics = PartialWrites;
11091096 continue ;
11101097 }
1111- else if (strncmp (*argv, " -u" , 2 ) == 0 ||
1112- strncmp (*argv, " /u" , 2 ) == 0 )
1098+ else if (check_argument_equals (*argv, {" -u" , " /u" }))
11131099 {
11141100 print_update = true ;
11151101 continue ;
11161102 }
11171103#ifdef _MSC_VER
1118- else if (strncmp (*argv, " --uninstallDriver" , 17 ) == 0 )
1104+ else if (check_argument_equals (*argv, { " --uninstallDriver" }) )
11191105 {
11201106 Driver tmpDrvObject;
11211107 tmpDrvObject.uninstall ();
11221108 cerr << " msr.sys driver has been uninstalled. You might need to reboot the system to make this effective.\n " ;
11231109 exit (EXIT_SUCCESS);
11241110 }
1125- else if (strncmp (*argv, " --installDriver" , 15 ) == 0 )
1111+ else if (check_argument_equals (*argv, { " --installDriver" }) )
11261112 {
11271113 Driver tmpDrvObject = Driver (Driver::msrLocalPath ());
11281114 if (!tmpDrvObject.start ())
@@ -1134,7 +1120,7 @@ int main(int argc, char * argv[])
11341120 exit (EXIT_SUCCESS);
11351121 }
11361122#endif
1137- else if (strncmp (*argv, " --" , 2 ) == 0 )
1123+ else if (check_argument_equals (*argv, { " --" }) )
11381124 {
11391125 argv++;
11401126 sysCmd = *argv;
@@ -1143,18 +1129,7 @@ int main(int argc, char * argv[])
11431129 }
11441130 else
11451131 {
1146- // any other options positional that is a floating point number is treated as <delay>,
1147- // while the other options are ignored with a warning issues to stderr
1148- double delay_input = 0.0 ;
1149- istringstream is_str_stream (*argv);
1150- is_str_stream >> noskipws >> delay_input;
1151- if (is_str_stream.eof () && !is_str_stream.fail ()) {
1152- delay = delay_input;
1153- } else {
1154- cerr << " WARNING: unknown command-line option: \" " << *argv << " \" . Ignoring it.\n " ;
1155- print_help (program);
1156- exit (EXIT_FAILURE);
1157- }
1132+ delay = parse_delay (*argv, program, (print_usage_func)print_help);
11581133 continue ;
11591134 }
11601135 } while (argc > 1 ); // end of command line parsing loop
0 commit comments