Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-hwoo committed Sep 21, 2023
1 parent f7678d2 commit 287b0c5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 49 deletions.
44 changes: 15 additions & 29 deletions src/c++/perf_analyzer/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -964,37 +964,23 @@ CLParser::ParseCommandLine(int argc, char** argv)
case 7: {
params_->using_concurrency_range = true;
std::string arg = optarg;
size_t pos = 0;
int index = 0;
while (pos != std::string::npos) {
size_t colon_pos = arg.find(":", pos);
if (index > 2) {
Usage(
"Failed to parse --concurrency-range. The value does not "
"match <start:end:step>.");
}
int64_t val;
if (colon_pos == std::string::npos) {
val = std::stoull(arg.substr(pos, colon_pos));
pos = colon_pos;
} else {
val = std::stoull(arg.substr(pos, colon_pos - pos));
pos = colon_pos + 1;
}
switch (index) {
case 0:
params_->concurrency_range.start = val;
break;
case 1:
params_->concurrency_range.end = val;
break;
case 2:
params_->concurrency_range.step = val;
break;
}
index++;
std::vector<std::string> values{SplitString(arg)};
if (values.size() > 3) {
Usage(
"Failed to parse --concurrency-range. The value does not match "
"<start:end:step>.");
}

for (size_t i = 0; i < values.size(); ++i) {
uint64_t val = std::stoull(values[i]);
if (i == 0) {
params_->concurrency_range.start = val;
} else if (i == 1) {
params_->concurrency_range.end = val;
} else if (i == 2) {
params_->concurrency_range.step = val;
}
}
break;
}
case 8:
Expand Down
40 changes: 20 additions & 20 deletions src/c++/perf_analyzer/test_command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,26 +493,6 @@ CheckInvalidRange(

check_params = false;
}

SUBCASE("wrong separator")
{
args.push_back(option_name);
args.push_back("100,400,10");

int argc = args.size();
char* argv[argc];
std::copy(args.begin(), args.end(), argv);

REQUIRE_NOTHROW(act = parser.Parse(argc, argv));
CHECK(parser.UsageCalled());

// BUG (TMA-1307): Should detect this and through an error. User will
// enter this and have no clue why the end and step sizes are not used
// correctly.
//

check_params = false;
}
}


Expand Down Expand Up @@ -1167,6 +1147,26 @@ TEST_CASE("Testing Command Line Parser")

CheckInvalidRange(args, option_name, parser, act, check_params);

SUBCASE("wrong separator")
{
args.push_back(option_name);
args.push_back("100,400,10");

int argc = args.size();
char* argv[argc];
std::copy(args.begin(), args.end(), argv);

REQUIRE_NOTHROW(act = parser.Parse(argc, argv));
CHECK(!parser.UsageCalled());

// BUG (TMA-1307): Should detect this and through an error. User will
// enter this and have no clue why the end and step sizes are not used
// correctly.
//

check_params = false;
}

SUBCASE("invalid condition - end and latency threshold are 0")
{
args.push_back(option_name);
Expand Down

0 comments on commit 287b0c5

Please sign in to comment.