[llvm] [llvm-profgen][SPGO] Support profiles with multiple concurrent processes (PR #169353)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 18:23:39 PST 2025
================
@@ -541,22 +555,41 @@ void PerfScriptReader::updateBinaryAddress(const MMapEvent &Event) {
return;
// Drop the event if process does not match pid filter
- if (PIDFilter && Event.PID != *PIDFilter)
+ if (!PIDFilter.empty() && !PIDFilter.contains(Event.PID))
return;
+ // If no PID is in the profile's samples, we treat everything as the default
+ // PID value
+ int32_t LookupPID = MultiProcessProfile ? Event.PID : DefaultPID;
+
// Drop the event if its image is loaded at the same address
- if (Event.Address == Binary->getBaseAddress()) {
+ if (Event.Address == Binary->getBaseAddress(LookupPID)) {
Binary->setIsLoadedByMMap(true);
return;
}
+ std::optional<int32_t> LastSeenPID = Binary->getLastSeenPID();
+ if (!MultiProcessProfile && LastSeenPID.has_value() &&
+ LastSeenPID.value() != Event.PID) {
+ WithColor::warning() << "Binary previously loaded in process ID "
+ << LastSeenPID.value() << " at "
+ << format("0x%" PRIx64,
+ Binary->getBaseAddress(LookupPID))
+ << " was reloaded in process ID " << Event.PID
+ << " at " << format("0x%" PRIx64, Event.Address)
+ << ". If profiling multiple processes running "
+ << "concurrently, use --multi-process-profile to "
+ << "prevent loss of samples.\n";
+ }
+ Binary->setLastSeenPID(Event.PID);
+
if (IsKernel || Event.Offset == Binary->getTextSegmentOffset()) {
// A binary image could be unloaded and then reloaded at different
// place, so update binary load address.
// Only update for the first executable segment and assume all other
// segments are loaded at consecutive memory addresses, which is the case on
// X64.
- Binary->setBaseAddress(Event.Address);
+ Binary->setBaseAddress(LookupPID, Event.Address);
----------------
HighW4y2H3ll wrote:
This doesn’t seem to apply to kernel?
https://github.com/llvm/llvm-project/pull/169353
More information about the llvm-commits
mailing list