[PATCH] D152483: [BOLT][NFCI] Use StringRef.split in launchPerfProcess

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 16:09:04 PDT 2023

Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

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 ...

  rG LLVM Github Monorepo



Index: bolt/lib/Profile/DataAggregator.cpp
--- bolt/lib/Profile/DataAggregator.cpp
+++ bolt/lib/Profile/DataAggregator.cpp
@@ -216,17 +216,7 @@
   outs() << "PERF2BOLT: spawning perf job to read " << Name << '\n';
-  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, ' ');
@@ -266,8 +256,6 @@
     PPI.PI = sys::ExecuteNoWait(PerfPath.data(), Argv, /*envp*/ std::nullopt,
-  free(WritableArgsString);
 void DataAggregator::processFileBuildID(StringRef FileBuildID) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152483.529763.patch
Type: text/x-patch
Size: 938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230608/26f032a5/attachment.bin>

More information about the llvm-commits mailing list