-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[llvm-profgen][SPGO] Support profiles with multiple concurrent processes #169353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-pgo Author: circuit10 (Heath123) ChangesFixes #164581. This PR adds support for interpreting perf profiles containing multiple processes running concurrently. Previously, profiling multiple processes worked only if a single instance was running at any given time, since the base address of the binary would be overwritten; see the linked issue for more detail. This is addressed by using a map which stores the base address for each binary's PID. Since including the PID of the relevant process in perf samples changes the output format, the feature has been gated behind a flag, to prevent breaking existing perf script files. To compliment the support for multiple processes, the PID filter may now also take multiple processes. Patch is 47.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/169353.diff 13 Files Affected:
diff --git a/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfbin b/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfbin
new file mode 100755
index 0000000000000..6e98e86d236a4
Binary files /dev/null and b/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfbin differ
diff --git a/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfscript b/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfscript
new file mode 100644
index 0000000000000..1e23ed3f81fde
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/Inputs/multi-process-cs-probe.perfscript
@@ -0,0 +1,30 @@
+; Load first process
+ 262511 PERF_RECORD_MMAP2 262511/262511: [0x61f3acfa8000(0x1000) @ 0x1000 103:02 13931513 3957944494]: r-xp /home/multi-process-cs-probe.perfbin
+
+; Samples from first process
+ 262511
+ 61f3acfa8155
+ 61f3acfa81e9
+ 78d7ee62a1ca
+ 78d7ee62a28b
+ 61f3acfa8065
+ 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/-
+
+; Load second process
+ 262512 PERF_RECORD_MMAP2 262512/262512: [0x5b3c4c631000(0x1000) @ 0x1000 103:02 13931513 3957944494]: r-xp /home/multi-process-cs-probe.perfbin
+
+; Samples from both processes
+ 262512
+ 5b3c4c631195
+ 5b3c4c63120c
+ 73bf70e2a1ca
+ 73bf70e2a28b
+ 5b3c4c631065
+ 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/5/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/4/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/5/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/5/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/5/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/5/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/5/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/- 0x5b3c4c631190/0x5b3c4c631195/P/-/-/1/UNCOND/- 0x5b3c4c6311a1/0x5b3c4c63117c/P/-/-/1/UNCOND/-
+ 262511
+ 61f3acfa813c
+ 61f3acfa81e9
+ 78d7ee62a1ca
+ 78d7ee62a28b
+ 61f3acfa8065
+ 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/4/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/- 0x61f3acfa8161/0x61f3acfa813c/P/-/-/1/UNCOND/- 0x61f3acfa8150/0x61f3acfa8155/P/-/-/1/UNCOND/-
diff --git a/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfbin b/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfbin
new file mode 100755
index 0000000000000..b7859ec8d6794
Binary files /dev/null and b/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfbin differ
diff --git a/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfscript b/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfscript
new file mode 100644
index 0000000000000..2ec2975cf07af
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/Inputs/multi-process-nocs-noprobe.perfscript
@@ -0,0 +1,12 @@
+; Load first process
+ 149754 PERF_RECORD_MMAP2 149754/149754: [0x5ffeb3637000(0x1000) @ 0x1000 103:02 16291238 2733047042]: r-xp /home/multi-process-nocs-noprobe.perfbin
+
+; Samples from first process
+ 149754 5ffeb3637150 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/-
+
+; Load second process
+ 149755 PERF_RECORD_MMAP2 149755/149755: [0x5caa46c41000(0x1000) @ 0x1000 103:02 16291238 2733047042]: r-xp /home/multi-process-nocs-noprobe.perfbin
+
+; Samples from both processes
+ 149755 5caa46c41190 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/-
+ 149754 5ffeb3637161 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/-
diff --git a/llvm/test/tools/llvm-profgen/Inputs/multi-process-warning.perfscript b/llvm/test/tools/llvm-profgen/Inputs/multi-process-warning.perfscript
new file mode 100644
index 0000000000000..bfca95dd26307
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/Inputs/multi-process-warning.perfscript
@@ -0,0 +1,12 @@
+; Load first process
+PERF_RECORD_MMAP2 149754/149754: [0x5ffeb3637000(0x1000) @ 0x1000 103:02 16291238 2733047042]: r-xp /home/multi-process-nocs-noprobe.perfbin
+
+; Samples from first process
+ 5ffeb3637150 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/-
+
+; Load second process
+PERF_RECORD_MMAP2 149755/149755: [0x5caa46c41000(0x1000) @ 0x1000 103:02 16291238 2733047042]: r-xp /home/multi-process-nocs-noprobe.perfbin
+
+; Samples from both processes
+ 5caa46c41190 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/- 0x5caa46c41190/0x5caa46c41195/P/-/-/1/UNCOND/- 0x5caa46c411a1/0x5caa46c4117c/P/-/-/1/UNCOND/-
+ 5ffeb3637161 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/- 0x5ffeb3637161/0x5ffeb363713c/P/-/-/1/UNCOND/- 0x5ffeb3637150/0x5ffeb3637155/P/-/-/1/UNCOND/-
diff --git a/llvm/test/tools/llvm-profgen/multi-pid-filter.test b/llvm/test/tools/llvm-profgen/multi-pid-filter.test
new file mode 100644
index 0000000000000..0802a6b545555
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/multi-pid-filter.test
@@ -0,0 +1,39 @@
+; Test that the --pid argument works, including when passing multiple PIDs
+
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/multi-process-nocs-noprobe.perfscript --binary=%S/Inputs/multi-process-nocs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --multi-process-profile --pid=149754
+; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-FIRST-ONLY
+
+CHECK-FIRST-ONLY-NOT: loop2
+
+CHECK-FIRST-ONLY: loop1:1302:0
+CHECK-FIRST-ONLY-NEXT: 0: 0
+CHECK-FIRST-ONLY-NEXT: 1: 31
+CHECK-FIRST-ONLY-NEXT: 2: 0
+
+CHECK-FIRST-ONLY-NOT: loop2
+
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/multi-process-nocs-noprobe.perfscript --binary=%S/Inputs/multi-process-nocs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --multi-process-profile --pid=149755
+; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-SECOND-ONLY
+
+CHECK-SECOND-ONLY-NOT: loop1
+
+CHECK-SECOND-ONLY:loop2:655:0
+CHECK-SECOND-ONLY-NEXT: 0: 0
+CHECK-SECOND-ONLY-NEXT: 1: 16
+CHECK-SECOND-ONLY-NEXT: 2: 0
+
+CHECK-SECOND-ONLY-NOT: loop1
+
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/multi-process-nocs-noprobe.perfscript --binary=%S/Inputs/multi-process-nocs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --multi-process-profile --pid=149754,149755
+; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-BOTH
+
+CHECK-BOTH: loop1:1302:0
+CHECK-BOTH-NEXT: 0: 0
+CHECK-BOTH-NEXT: 1: 31
+CHECK-BOTH-NEXT: 2: 0
+CHECK-BOTH-NEXT:loop2:655:0
+CHECK-BOTH-NEXT: 0: 0
+CHECK-BOTH-NEXT: 1: 16
+CHECK-BOTH-NEXT: 2: 0
+
+; original code can be found in multi-process-nocs-noprobe.test
diff --git a/llvm/test/tools/llvm-profgen/multi-process-cs-probe.test b/llvm/test/tools/llvm-profgen/multi-process-cs-probe.test
new file mode 100644
index 0000000000000..adc28040349ff
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/multi-process-cs-probe.test
@@ -0,0 +1,46 @@
+; Check that we can handle profiles with multiple processes, using pseudo probes
+; and a context-senstive profile
+
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/multi-process-cs-probe.perfscript --binary=%S/Inputs/multi-process-cs-probe.perfbin --output=%t --profile-summary-cold-count=0 --multi-process-profile
+; RUN: FileCheck %s --input-file %t
+
+CHECK: loop1:93:0
+CHECK-NEXT: 1: 0
+CHECK-NEXT: 2: 31
+CHECK-NEXT: 3: 31
+CHECK-NEXT: 4: 31
+CHECK-NEXT: 5: 0
+CHECK-NEXT: !CFGChecksum: 88680961901
+CHECK-NEXT:loop2:47:0
+CHECK-NEXT: 1: 0
+CHECK-NEXT: 2: 16
+CHECK-NEXT: 3: 16
+CHECK-NEXT: 4: 15
+CHECK-NEXT: 5: 0
+CHECK-NEXT: !CFGChecksum: 88680961901
+
+; original code:
+; clang -g -fpseudo-probe-for-profiling -fno-omit-frame-pointer test.c -o multi-process-cs-probe.perfbin
+#include <stdint.h>
+
+// Loop for a while so we see samples in the function (compiled at -O0)
+void loop1() {
+ for (uint64_t i = 0; i < 10000000000; i++) {}
+}
+
+// Slightly modified to make sure there isn't any kind of linker merging
+void loop2() {
+ for (uint64_t i = 1; i < 10000000001; i++) {}
+}
+
+int main(int argc, char *argv[]) {
+ // Use CLI argument to choose which loop to run, so we can distinguish which
+ // process...
[truncated]
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
Thanks, fixing this will be a nice improvement. It is a bit onerous for the user to have to enumerate all the relevant pids to be processed. I wonder if instead we can read the build id from the binary specified in the command line ( |
Thanks for the comments. Passing the PIDs of the relevant processes isn't actually required; if the PID filter is empty, profgen will accept all PIDs, and use the name of the binary for this: llvm-project/llvm/tools/llvm-profgen/PerfReader.cpp Lines 1198 to 1202 in 9e5043a
The PID filter is for if the user needs to ignore certain processes in the output which would otherwise pass this check. |
Fixes #164581.
This PR adds support for interpreting perf profiles containing multiple processes running concurrently. Previously, profiling multiple processes worked only if a single instance was running at any given time, since the base address of the binary would be overwritten; see the linked issue for more detail. This is addressed by using a map which stores the base address for each binary's PID.
Since including the PID of the relevant process in perf samples changes the output format, the feature has been gated behind a flag, to prevent breaking existing perf script files.
To compliment the support for multiple processes, the PID filter may now also take multiple processes.