Skip to content

Commit

Permalink
[BOLT][NFCI] Use StringRef.split in launchPerfProcess
Browse files Browse the repository at this point in the history
Use StringRef method instead of reimplementing the splitting.
Incidentally, it also fixes the duplicate printing of the command arguments:
```
PERF2BOLT: spawning perf job to read branch events
Launching perf: /usr/bin/perf script^@-F^@pid,ip,brstack -F^@pid,ip,brstack pid,ip,brstack -f -i
PERF2BOLT: spawning perf job to read mem events
Launching perf: /usr/bin/perf script^@-F^@pid,event,addr,ip -F^@pid,event,addr,ip pid,event,addr,ip -f -i
PERF2BOLT: spawning perf job to read process events
Launching perf: /usr/bin/perf script^@--show-mmap-events --show-mmap-events -f -i
PERF2BOLT: spawning perf job to read task events
Launching perf: /usr/bin/perf script^@--show-task-events --show-task-events -f -i
```

Fixes it to:
```
PERF2BOLT: spawning perf job to read branch events
Launching perf: /usr/bin/perf script -F pid,ip,brstack -f -i
PERF2BOLT: spawning perf job to read mem events
Launching perf: /usr/bin/perf script -F pid,event,addr,ip -f -i
PERF2BOLT: spawning perf job to read process events
Launching perf: /usr/bin/perf script --show-mmap-events -f -i
PERF2BOLT: spawning perf job to read task events
Launching perf: /usr/bin/perf script --show-task-events -f -i
```

Reviewed By: #bolt, rafauler

Differential Revision: https://reviews.llvm.org/D152483
  • Loading branch information
aaupov committed Jun 9, 2023
1 parent c45695e commit 5acac7d
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,7 @@ void DataAggregator::launchPerfProcess(StringRef Name, PerfProcessInfo &PPI,
outs() << "PERF2BOLT: spawning perf job to read " << Name << '\n';
Argv.push_back(PerfPath.data());

char *WritableArgsString = strdup(ArgsString);
char *Str = WritableArgsString;
do {
Argv.push_back(Str);
while (*Str && *Str != ' ')
++Str;
if (!*Str)
break;
*Str++ = 0;
} while (true);

StringRef(ArgsString).split(Argv, ' ');
Argv.push_back("-f");
Argv.push_back("-i");
Argv.push_back(Filename.c_str());
Expand Down Expand Up @@ -266,8 +256,6 @@ void DataAggregator::launchPerfProcess(StringRef Name, PerfProcessInfo &PPI,
else
PPI.PI = sys::ExecuteNoWait(PerfPath.data(), Argv, /*envp*/ std::nullopt,
Redirects);

free(WritableArgsString);
}

void DataAggregator::processFileBuildID(StringRef FileBuildID) {
Expand Down

0 comments on commit 5acac7d

Please sign in to comment.