@@ -446,12 +446,12 @@ class SampleProfileMatcher {
446
446
447
447
// Match state for an anchor/callsite.
448
448
enum class MatchState {
449
- Matched = 0 ,
450
- Mismatched = 1 ,
451
- // Stay Matched after profile matching .
452
- StayMatched = 2 ,
453
- // Recovered from Mismatched after profile matching .
454
- Recovered = 3 ,
449
+ InitialMatch = 0 ,
450
+ InitialMismatch = 1 ,
451
+ // From initial mismatch to final match .
452
+ RecoveredMismatch = 2 ,
453
+ // From initial match to final mismatch .
454
+ RemovedMatch = 3 ,
455
455
Unknown = 32 ,
456
456
};
457
457
@@ -500,9 +500,9 @@ class SampleProfileMatcher {
500
500
void findProfileAnchors (
501
501
const FunctionSamples &FS,
502
502
std::map<LineLocation, std::unordered_set<FunctionId>> &ProfileAnchors);
503
- // Compute the callsite match states for profile staleness report, the result
503
+ // Record the callsite match states for profile staleness report, the result
504
504
// is saved in FuncCallsiteMatchStates.
505
- void computeCallsiteMatchStates (
505
+ void recordCallsiteMatchStates (
506
506
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
507
507
const std::map<LineLocation, std::unordered_set<FunctionId>>
508
508
&ProfileAnchors,
@@ -2376,7 +2376,7 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
2376
2376
2377
2377
// Compute the callsite match states for profile staleness report.
2378
2378
if (ReportProfileStaleness || PersistProfileStaleness)
2379
- computeCallsiteMatchStates (F, IRAnchors, ProfileAnchors, nullptr );
2379
+ recordCallsiteMatchStates (F, IRAnchors, ProfileAnchors, nullptr );
2380
2380
2381
2381
// Run profile matching for checksum mismatched profile, currently only
2382
2382
// support for pseudo-probe.
@@ -2389,12 +2389,12 @@ void SampleProfileMatcher::runOnFunction(const Function &F) {
2389
2389
IRToProfileLocationMap);
2390
2390
// Find and update callsite match states after matching.
2391
2391
if (ReportProfileStaleness || PersistProfileStaleness)
2392
- computeCallsiteMatchStates (F, IRAnchors, ProfileAnchors,
2393
- &IRToProfileLocationMap);
2392
+ recordCallsiteMatchStates (F, IRAnchors, ProfileAnchors,
2393
+ &IRToProfileLocationMap);
2394
2394
}
2395
2395
}
2396
2396
2397
- void SampleProfileMatcher::computeCallsiteMatchStates (
2397
+ void SampleProfileMatcher::recordCallsiteMatchStates (
2398
2398
const Function &F, const std::map<LineLocation, StringRef> &IRAnchors,
2399
2399
const std::map<LineLocation, std::unordered_set<FunctionId>>
2400
2400
&ProfileAnchors,
@@ -2434,15 +2434,12 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
2434
2434
IsCallsiteMatched = true ;
2435
2435
2436
2436
if (IsCallsiteMatched) {
2437
- auto R = CallsiteMatchStates.emplace (ProfileLoc, MatchState::Matched);
2437
+ auto R =
2438
+ CallsiteMatchStates.emplace (ProfileLoc, MatchState::InitialMatch);
2438
2439
// When there is an existing state, we know it's in post-match phrase.
2439
2440
// Update the matching state accordingly.
2440
- if (!R.second ) {
2441
- if (R.first ->second == MatchState::Mismatched)
2442
- R.first ->second = MatchState::Recovered;
2443
- if (R.first ->second == MatchState::Matched)
2444
- R.first ->second = MatchState::StayMatched;
2445
- }
2441
+ if (!R.second && R.first ->second == MatchState::InitialMismatch)
2442
+ R.first ->second = MatchState::RecoveredMismatch;
2446
2443
}
2447
2444
}
2448
2445
@@ -2454,11 +2451,10 @@ void SampleProfileMatcher::computeCallsiteMatchStates(
2454
2451
assert (!Callees.empty () && " Callees should not be empty" );
2455
2452
auto It = CallsiteMatchStates.find (Loc);
2456
2453
if (It == CallsiteMatchStates.end ())
2457
- CallsiteMatchStates.emplace (Loc, MatchState::Mismatched);
2458
- // In post-match, if the state is not updated to Recovered or StayMatched,
2459
- // update it to Mismatched.
2460
- else if (IsPostMatch && It->second == MatchState::Matched)
2461
- CallsiteMatchStates.emplace (Loc, MatchState::Mismatched);
2454
+ CallsiteMatchStates.emplace (Loc, MatchState::InitialMismatch);
2455
+ // The inital match is removed in post-match.
2456
+ else if (IsPostMatch && It->second == MatchState::InitialMatch)
2457
+ CallsiteMatchStates.emplace (Loc, MatchState::RemovedMatch);
2462
2458
}
2463
2459
}
2464
2460
@@ -2505,11 +2501,16 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
2505
2501
return It->second ;
2506
2502
};
2507
2503
2504
+ auto IsMismatchState = [&](const enum MatchState &State) {
2505
+ return State == MatchState::InitialMismatch ||
2506
+ State == MatchState::RemovedMatch;
2507
+ };
2508
+
2508
2509
auto AttributeMismatchedSamples = [&](const enum MatchState &State,
2509
2510
uint64_t Samples) {
2510
- if (State == MatchState::Mismatched )
2511
+ if (IsMismatchState ( State) )
2511
2512
MismatchedCallsiteSamples += Samples;
2512
- else if (State == MatchState::Recovered )
2513
+ else if (State == MatchState::RecoveredMismatch )
2513
2514
RecoveredCallsiteSamples += Samples;
2514
2515
};
2515
2516
@@ -2526,7 +2527,7 @@ void SampleProfileMatcher::countMismatchedCallsiteSamples(
2526
2527
CallsiteSamples += CS.second .getTotalSamples ();
2527
2528
AttributeMismatchedSamples (State, CallsiteSamples);
2528
2529
2529
- if (State == MatchState::Mismatched )
2530
+ if (IsMismatchState ( State) )
2530
2531
continue ;
2531
2532
2532
2533
// When the current level of inlined call site matches the profiled call
@@ -2545,9 +2546,10 @@ void SampleProfileMatcher::countMismatchCallsites(const FunctionSamples &FS) {
2545
2546
const auto &MatchStates = It->second ;
2546
2547
for (const auto &I : MatchStates) {
2547
2548
TotalProfiledCallsites++;
2548
- if (I.second == MatchState::Mismatched)
2549
+ if (I.second == MatchState::InitialMismatch ||
2550
+ I.second == MatchState::RemovedMatch)
2549
2551
NumMismatchedCallsites++;
2550
- else if (I.second == MatchState::Recovered )
2552
+ else if (I.second == MatchState::RecoveredMismatch )
2551
2553
NumRecoveredCallsites++;
2552
2554
}
2553
2555
}
0 commit comments