Skip to content

[BOLT] Only parse probes for profiled functions in profile-write-pseudo-probes mode #106365

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

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented Aug 28, 2024

Implement selective probe parsing for profiled functions only when
emitting probe information to YAML profile as suggested in
#102904 (review)

For a large binary, this reduces probe parsing

  • processing time from 10.5925s to 5.6295s,
  • peak RSS from 10.54 to 7.98 GiB.

aaupov added 2 commits August 28, 2024 03:57
Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2024

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/106365.diff

1 Files Affected:

  • (modified) bolt/lib/Rewrite/PseudoProbeRewriter.cpp (+7-3)
diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
index 228913e6ea1f39..89a7fddbb5d2af 100644
--- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
+++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
@@ -72,7 +72,8 @@ class PseudoProbeRewriter final : public MetadataRewriter {
 
   /// Parse .pseudo_probe_desc section and .pseudo_probe section
   /// Setup Pseudo probe decoder
-  void parsePseudoProbe();
+  /// If \p ProfiledOnly is set, only parse records for functions with profile.
+  void parsePseudoProbe(bool ProfiledOnly = false);
 
   /// PseudoProbe decoder
   std::shared_ptr<MCPseudoProbeDecoder> ProbeDecoderPtr;
@@ -92,7 +93,7 @@ class PseudoProbeRewriter final : public MetadataRewriter {
 
 Error PseudoProbeRewriter::preCFGInitializer() {
   if (opts::ProfileWritePseudoProbes)
-    parsePseudoProbe();
+    parsePseudoProbe(true);
 
   return Error::success();
 }
@@ -105,7 +106,7 @@ Error PseudoProbeRewriter::postEmitFinalizer() {
   return Error::success();
 }
 
-void PseudoProbeRewriter::parsePseudoProbe() {
+void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
   MCPseudoProbeDecoder &ProbeDecoder(*ProbeDecoderPtr);
   PseudoProbeDescSection = BC.getUniqueSectionByName(".pseudo_probe_desc");
   PseudoProbeSection = BC.getUniqueSectionByName(".pseudo_probe");
@@ -136,6 +137,7 @@ void PseudoProbeRewriter::parsePseudoProbe() {
   MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
   SmallVector<StringRef, 3> Suffixes({".llvm.", ".destroy", ".resume"});
   for (const BinaryFunction *F : BC.getAllBinaryFunctions()) {
+    bool HasProfile = F->hasProfileAvailable();
     for (const MCSymbol *Sym : F->getSymbols()) {
       StringRef SymName = NameResolver::restore(Sym->getName());
       if (std::optional<StringRef> CommonName =
@@ -144,6 +146,8 @@ void PseudoProbeRewriter::parsePseudoProbe() {
       }
       uint64_t GUID = Function::getGUID(SymName);
       FuncStartAddrs[GUID] = F->getAddress();
+      if (ProfiledOnly && HasProfile)
+        GuidFilter.insert(GUID);
     }
   }
   Contents = PseudoProbeSection->getContents();

@aaupov aaupov requested review from wlei-llvm and WenleiHe August 28, 2024 11:03
Copy link
Contributor

@wlei-llvm wlei-llvm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@aaupov aaupov changed the base branch from users/aaupov/spr/main.bolt-only-parse-probes-for-profiled-functions-in-profile-write-pseudo-probes-mode to main September 11, 2024 23:33
@aaupov aaupov merged commit 86ec59e into main Sep 11, 2024
7 of 9 checks passed
@aaupov aaupov deleted the users/aaupov/spr/bolt-only-parse-probes-for-profiled-functions-in-profile-write-pseudo-probes-mode branch September 11, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants