@@ -455,9 +455,9 @@ class SampleProfileMatcher {
455
455
Unknown = 32 ,
456
456
};
457
457
458
- // For each function, store every callsite state into a map, of which each
459
- // entry is a pair of callsite location and MatchState. This is used for
460
- // profile stalness computation and report.
458
+ // For each function, store every callsite a matching state into this map, of
459
+ // which each entry is a pair of callsite location and MatchState. This is
460
+ // used for profile stalness computation and report.
461
461
StringMap<std::unordered_map<LineLocation, MatchState, LineLocationHash>>
462
462
FuncCallsiteMatchStates;
463
463
@@ -501,7 +501,7 @@ class SampleProfileMatcher {
501
501
const FunctionSamples &FS,
502
502
std::map<LineLocation, std::unordered_set<FunctionId>> &ProfileAnchors);
503
503
// Compute the callsite match states for profile staleness report, the result
504
- // is save in FuncCallsiteMatchStates.
504
+ // is saved in FuncCallsiteMatchStates.
505
505
void computeCallsiteMatchStates (
506
506
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
507
507
const std::map<LineLocation, std::unordered_set<FunctionId>>
@@ -2403,8 +2403,8 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
2403
2403
auto &CallsiteMatchStates =
2404
2404
FuncCallsiteMatchStates[FunctionSamples::getCanonicalFnName (F.getName ())];
2405
2405
2406
- // IRToProfileLocationMap is null before the matching.
2407
2406
auto MapIRLocToProfileLoc = [&](const LineLocation &IRLoc) {
2407
+ // IRToProfileLocationMap is null in pre-match phrase.
2408
2408
if (!IRToProfileLocationMap)
2409
2409
return IRLoc;
2410
2410
const auto &ProfileLoc = IRToProfileLocationMap->find (IRLoc);
@@ -2435,8 +2435,8 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
2435
2435
2436
2436
if (IsCallsiteMatched) {
2437
2437
auto R = CallsiteMatchStates.emplace (Loc, MatchState::Matched);
2438
- // Update the post-match state when there is a existing state indicateing
2439
- // it's in post-match phrase .
2438
+ // When there is an existing state, we know it's in post-match phrase.
2439
+ // Update the matching state accordingly .
2440
2440
if (!R.second ) {
2441
2441
if (R.first ->second == MatchState::Mismatched)
2442
2442
R.first ->second = MatchState::Recovered;
@@ -2447,15 +2447,15 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
2447
2447
}
2448
2448
2449
2449
// Check if there are any callsites in the profile that does not match to any
2450
- // IR callsites, those callsite samples will be discarded .
2450
+ // IR callsites.
2451
2451
for (const auto &I : ProfileAnchors) {
2452
2452
const auto &Loc = I.first ;
2453
2453
[[maybe_unused]] const auto &Callees = I.second ;
2454
2454
assert (!Callees.empty () && " Callees should not be empty" );
2455
2455
auto It = CallsiteMatchStates.find (Loc);
2456
2456
if (It == CallsiteMatchStates.end ())
2457
2457
CallsiteMatchStates.emplace (Loc, MatchState::Mismatched);
2458
- // If in post-match, the state is not updated to Recovered or StayMatched,
2458
+ // In post-match, if the state is not updated to Recovered or StayMatched,
2459
2459
// update it to Mismatched.
2460
2460
else if (IsPostMatch && It->second == MatchState::Matched)
2461
2461
CallsiteMatchStates.emplace (Loc, MatchState::Mismatched);
@@ -2472,17 +2472,19 @@ void SampleProfileMatcher::countMismatchedFuncSamples(const FunctionSamples &FS,
2472
2472
if (ProbeManager->profileIsHashMismatched (*FuncDesc, FS)) {
2473
2473
if (IsTopLevel)
2474
2474
NumStaleProfileFunc++;
2475
- // Once the checksum is mismatched, it's likely all the callites are
2476
- // mismatched and dropped, we conservatively count all the samples as
2477
- // mismatched samples and stop counting the inlinee profile.
2475
+ // Given currently all probe ids are after block probe ids, once the
2476
+ // checksum is mismatched, it's likely all the callites are mismatched and
2477
+ // dropped. We conservatively count all the samples as mismatched and stop
2478
+ // counting the inlinees' profiles.
2478
2479
MismatchedFunctionSamples += FS.getTotalSamples ();
2479
2480
return ;
2480
2481
}
2481
2482
2482
- // Even the current function checksum is matched, it's possible that the
2483
- // inlinees' checksums are mismatched, we need to go deeper to check the
2484
- // inlinee's function samples. Similarly, if the inlinee's checksum is
2485
- // mismatched, we stop and count all the samples as mismatched samples.
2483
+ // Even the current-level function checksum is matched, it's possible that the
2484
+ // nested inlinees' checksums are mismatched that affect the inlinee's sample
2485
+ // loading, we need to go deeper to check the inlinees' function samples.
2486
+ // Similarly, count all the samples as mismatched if the inlinee's checksum is
2487
+ // mismatched using this recursive function.
2486
2488
for (const auto &I : FS.getCallsiteSamples ())
2487
2489
for (const auto &CS : I.second )
2488
2490
countMismatchedFuncSamples (CS.second , false );
@@ -2512,10 +2514,11 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
2512
2514
};
2513
2515
2514
2516
// The non-inlined callsites are saved in the body samples of function
2515
- // profile.
2517
+ // profile, go through it to count the non-inlined callsite samples .
2516
2518
for (const auto &I : FS.getBodySamples ())
2517
2519
AttributeMismatchedSamples (findMatchState (I.first ), I.second .getSamples ());
2518
2520
2521
+ // Count the inlined callsite samples.
2519
2522
for (const auto &I : FS.getCallsiteSamples ()) {
2520
2523
auto State = findMatchState (I.first );
2521
2524
uint64_t CallsiteSamples = 0 ;
0 commit comments