[llvm] [BOLT] Heatmap fix on large binaries and printing mappings (PR #92815)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 12:46:28 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Paschalis Mpeis (paschalis-mpeis)

<details>
<summary>Changes</summary>

### DRAFT PR: This is WIP.

Needs:
- Add context describing the issue
- Add testing

## In short, it improves heatmaps by:
1) Fixing a bug where the computation of a text section's size was wrong. As a result, running the heatmap tool on some bigger bolted binaries, the tool ignored most of the hits in hot/cold text segments.

2) Adding to the legend the mapping between the bucket letters to the actual text sections.

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


2 Files Affected:

- (modified) bolt/lib/Profile/DataAggregator.cpp (+14-3) 
- (modified) bolt/lib/Profile/Heatmap.cpp (+11) 


``````````diff
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index e06debcee741e..8d5b5531654cb 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -2009,8 +2009,9 @@ std::error_code DataAggregator::parseMMapEvents() {
       return MI.second.PID == FileMMapInfo.second.PID;
     });
 
-    if (PIDExists)
-      continue;
+    // let duplicates to the multimap.
+    // if (PIDExists)
+    //   continue;
 
     GlobalMMapInfo.insert(FileMMapInfo);
   }
@@ -2067,7 +2068,17 @@ std::error_code DataAggregator::parseMMapEvents() {
       }
     }
 
-    BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo));
+    // The mapping was already in place, but there are cases where the size
+    // is wrong. Fix it if needed.
+    if(!BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)).second) {
+      auto EndAddress = MMapInfo.MMapAddress + MMapInfo.Size;
+      auto FixedSize = EndAddress - BinaryMMapInfo[MMapInfo.PID].BaseAddress;
+
+      if (FixedSize != BinaryMMapInfo[MMapInfo.PID].Size) {
+          outs() << "MMap size fixed: " << Twine::utohexstr(FixedSize) << " \n";
+         BinaryMMapInfo[MMapInfo.PID].Size = FixedSize;
+      }
+    }
   }
 
   if (BinaryMMapInfo.empty()) {
diff --git a/bolt/lib/Profile/Heatmap.cpp b/bolt/lib/Profile/Heatmap.cpp
index 210a5cc98c104..233b070bde2da 100644
--- a/bolt/lib/Profile/Heatmap.cpp
+++ b/bolt/lib/Profile/Heatmap.cpp
@@ -164,6 +164,7 @@ void Heatmap::print(raw_ostream &OS) const {
 
   // Print map legend
   OS << "Legend:\n";
+  OS << "\nRegions:\n";
   uint64_t PrevValue = 0;
   for (unsigned I = 0; I < sizeof(Range) / sizeof(Range[0]); ++I) {
     const uint64_t Value = Range[I];
@@ -173,6 +174,16 @@ void Heatmap::print(raw_ostream &OS) const {
     PrevValue = Value;
   }
 
+  {
+    OS << "\nSections:\n";
+    int Idx = 0;
+    for (auto TxtSeg : TextSections) {
+      OS << static_cast<char>('A' + ((Idx++) % 26)) << ": " << TxtSeg.Name
+         << ": 0x" <<  Twine::utohexstr(TxtSeg.BeginAddress) << "-0x"
+         << Twine::utohexstr(TxtSeg.EndAddress) << "\n";
+    }
+  }
+
   // Pos - character position from right in hex form.
   auto printHeader = [&](unsigned Pos) {
     OS << "            ";

``````````

</details>


https://github.com/llvm/llvm-project/pull/92815


More information about the llvm-commits mailing list