Skip to content

Commit d375415

Browse files
committed
refactor PID option parsing
Change-Id: I7d8caaa3080e722d132213ef44d9aa4243e401d7
1 parent 5b8bb48 commit d375415

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/pcm-raw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ int main(int argc, char* argv[])
18101810
bool reset_pmu = false;
18111811
PCM* m = PCM::getInstance();
18121812

1813-
parseParam(argc, argv, "pid", [&pid](const char* p) { if (p) pid = atoi(p); });
1813+
parsePID(argc, argv, pid);
18141814

18151815
#ifdef PCM_SIMDJSON_AVAILABLE
18161816
parseParam(argc, argv, "ep", [](const char* p) { eventFileLocationPrefix = p;});
@@ -1844,7 +1844,7 @@ int main(int argc, char* argv[])
18441844
{
18451845
continue;
18461846
}
1847-
else if (strncmp(*argv, "-pid", 4) == 0 || strncmp(*argv, "/pid", 4) == 0)
1847+
else if (isPIDOption(argv))
18481848
{
18491849
argv++;
18501850
argc--;

src/pcm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ int main(int argc, char * argv[])
11671167
bool reset_pmu = false;
11681168
bool disable_JKT_workaround = false; // as per http://software.intel.com/en-us/articles/performance-impact-when-sampling-certain-llc-events-on-snb-ep-with-vtune
11691169

1170-
parseParam(argc, argv, "pid", [&pid](const char* p) { if (p) pid = atoi(p); });
1170+
parsePID(argc, argv, pid);
11711171

11721172
MainLoop mainLoop;
11731173
std::bitset<MAX_CORES> ycores;
@@ -1267,7 +1267,7 @@ int main(int argc, char * argv[])
12671267
}
12681268
continue;
12691269
}
1270-
else if (strncmp(*argv, "-pid", 4) == 0 || strncmp(*argv, "/pid", 4) == 0)
1270+
else if (isPIDOption(argv))
12711271
{
12721272
argv++;
12731273
argc--;

src/utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,15 @@ void check_and_set_silent(int argc, char * argv[], null_stream &nullStream2);
498498

499499
void print_pid_collection_message(int pid);
500500

501+
inline bool isPIDOption(char * argv [])
502+
{
503+
return strncmp(*argv, "-pid", 4) == 0 || strncmp(*argv, "/pid", 4) == 0;
504+
}
505+
506+
inline void parsePID(int argc, char* argv[], int& pid)
507+
{
508+
parseParam(argc, argv, "pid", [&pid](const char* p) { if (p) pid = atoi(p); });
509+
}
510+
511+
501512
} // namespace pcm

0 commit comments

Comments
 (0)