@@ -70,7 +70,7 @@ bool anyPmem(const ServerUncoreMemoryMetrics & metrics)
70
70
71
71
bool skipInactiveChannels = true ;
72
72
73
- void print_help (const string prog_name)
73
+ void print_help (const string & prog_name)
74
74
{
75
75
cout << " \n Usage: \n " << prog_name
76
76
<< " --help | [delay] [options] [-- external_program [external_program_options]]\n " ;
@@ -1002,6 +1002,8 @@ int main(int argc, char * argv[])
1002
1002
{
1003
1003
argv++;
1004
1004
argc--;
1005
+ string arg_value;
1006
+
1005
1007
if (check_argument_equals (*argv, {" --help" , " -h" , " /h" }))
1006
1008
{
1007
1009
print_help (program);
@@ -1012,117 +1014,101 @@ int main(int argc, char * argv[])
1012
1014
// handled in check_and_set_silent
1013
1015
continue ;
1014
1016
}
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))
1017
1022
{
1018
1023
csv = true ;
1019
1024
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);
1027
1027
}
1028
1028
continue ;
1029
1029
}
1030
1030
else if (mainLoop.parseArg (*argv))
1031
1031
{
1032
1032
continue ;
1033
1033
}
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))
1036
1035
{
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 ;
1045
1038
}
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 ();
1046
1044
continue ;
1047
1045
}
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))
1050
1047
{
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 " ;
1058
1059
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;
1067
1060
}
1061
+ if (rankA < 0 ) rankA = rank;
1062
+ else if (rankB < 0 ) rankB = rank;
1063
+ metrics = PartialWrites;
1068
1064
}
1069
1065
continue ;
1070
1066
}
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" }))
1074
1068
{
1075
1069
show_channel_output = false ;
1076
1070
continue ;
1077
1071
}
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" }))
1082
1073
{
1083
1074
metrics = Pmem;
1084
1075
continue ;
1085
1076
}
1086
- else if (strncmp (*argv, " -all" , 4 ) == 0 ||
1087
- strncmp (*argv, " /all" , 4 ) == 0 )
1077
+ else if (check_argument_equals (*argv, {" -all" , " /all" }))
1088
1078
{
1089
1079
skipInactiveChannels = false ;
1090
1080
continue ;
1091
1081
}
1092
- else if (strncmp (*argv, " -mixed" , 6 ) == 0 ||
1093
- strncmp (*argv, " /mixed" , 6 ) == 0 )
1082
+ else if (check_argument_equals (*argv, {" -mixed" , " /mixed" }))
1094
1083
{
1095
1084
metrics = PmemMixedMode;
1096
1085
continue ;
1097
1086
}
1098
- else if (strncmp (*argv, " -mm" , 3 ) == 0 ||
1099
- strncmp (*argv, " /mm" , 3 ) == 0 )
1087
+ else if (check_argument_equals (*argv, {" -mm" , " /mm" }))
1100
1088
{
1101
1089
metrics = PmemMemoryMode;
1102
1090
show_channel_output = false ;
1103
1091
continue ;
1104
1092
}
1105
- else if (strncmp (*argv, " -partial" , 8 ) == 0 ||
1106
- strncmp (*argv, " /partial" , 8 ) == 0 )
1093
+ else if (check_argument_equals (*argv, {" -partial" , " /partial" }))
1107
1094
{
1108
1095
metrics = PartialWrites;
1109
1096
continue ;
1110
1097
}
1111
- else if (strncmp (*argv, " -u" , 2 ) == 0 ||
1112
- strncmp (*argv, " /u" , 2 ) == 0 )
1098
+ else if (check_argument_equals (*argv, {" -u" , " /u" }))
1113
1099
{
1114
1100
print_update = true ;
1115
1101
continue ;
1116
1102
}
1117
1103
#ifdef _MSC_VER
1118
- else if (strncmp (*argv, " --uninstallDriver" , 17 ) == 0 )
1104
+ else if (check_argument_equals (*argv, { " --uninstallDriver" }) )
1119
1105
{
1120
1106
Driver tmpDrvObject;
1121
1107
tmpDrvObject.uninstall ();
1122
1108
cerr << " msr.sys driver has been uninstalled. You might need to reboot the system to make this effective.\n " ;
1123
1109
exit (EXIT_SUCCESS);
1124
1110
}
1125
- else if (strncmp (*argv, " --installDriver" , 15 ) == 0 )
1111
+ else if (check_argument_equals (*argv, { " --installDriver" }) )
1126
1112
{
1127
1113
Driver tmpDrvObject = Driver (Driver::msrLocalPath ());
1128
1114
if (!tmpDrvObject.start ())
@@ -1134,7 +1120,7 @@ int main(int argc, char * argv[])
1134
1120
exit (EXIT_SUCCESS);
1135
1121
}
1136
1122
#endif
1137
- else if (strncmp (*argv, " --" , 2 ) == 0 )
1123
+ else if (check_argument_equals (*argv, { " --" }) )
1138
1124
{
1139
1125
argv++;
1140
1126
sysCmd = *argv;
@@ -1143,18 +1129,7 @@ int main(int argc, char * argv[])
1143
1129
}
1144
1130
else
1145
1131
{
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);
1158
1133
continue ;
1159
1134
}
1160
1135
} while (argc > 1 ); // end of command line parsing loop
0 commit comments