[compiler-rt] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 4 14:13:37 PDT 2024


================
@@ -216,6 +226,32 @@ u64 GetShadowCount(uptr p, u32 size) {
   return count;
 }
 
+// Accumulates the access count from the shadow for the given pointer and size.
+u64 GetShadowCountHistogram(uptr p, u32 size) {
+  u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p);
+  u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size);
+  u64 count = 0;
+  for (; shadow <= shadow_end; shadow++)
+    count += *shadow;
+  return count;
+}
+
+// If we use the normal approach in clearCountersWithoutHistogram, the histogram
+// will clear to much data and may overwrite shadow counters that are in use.
----------------
teresajohnson wrote:

(In general it would be good to have a clear comment somewhere that can be referenced from various places that describes the difference between the way the shadow memory is laid out and handled for the 2 cases)

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


More information about the llvm-commits mailing list