Skip to content

Commit ad4d98f

Browse files
shawbyoungaaupov
authored andcommitted
Debug logging
Created using spr 1.3.4
1 parent 1c8b150 commit ad4d98f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "llvm/Support/CommandLine.h"
2121
#include <algorithm>
2222

23+
#undef DEBUG_TYPE
24+
#define DEBUG_TYPE "bolt-prof"
25+
2326
using namespace llvm;
2427

2528
namespace opts {
@@ -666,24 +669,35 @@ size_t YAMLProfileReader::matchWithPseudoProbes(BinaryContext &BC) {
666669

667670
// Get unused profile functions GUID.
668671
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
669-
if (YamlBF.Used || YamlBF.InlineTree.empty())
672+
if (YamlBF.Used)
673+
continue;
674+
LLVM_DEBUG(dbgs() << "Attempting to match " << YamlBF.Name
675+
<< " using pseudo probes: ");
676+
if (YamlBF.InlineTree.empty()) {
677+
LLVM_DEBUG(dbgs() << "no probe information\n");
670678
continue;
679+
}
671680
uint64_t GUIDIdx = YamlBF.InlineTree.front().GUIDIndex;
672681
assert(GUIDIdx - 1 < YamlPD.GUID.size());
673682
uint64_t YamlGUID = YamlPD.GUID[GUIDIdx - 1];
674683

675684
// Look up corresponding GUID in binary.
676685
auto It = GUID2FuncDescMap.find(YamlGUID);
677-
if (It == GUID2FuncDescMap.end())
686+
if (It == GUID2FuncDescMap.end()) {
687+
LLVM_DEBUG(dbgs() << "no function with GUID=" << YamlGUID
688+
<< " in the binary\n");
678689
continue;
690+
}
679691

680692
// Check if checksums match between profile and binary.
681693
assert(GUIDIdx - 1 < YamlPD.GUIDHash.size());
682694
uint64_t HashIdx = YamlPD.GUIDHash[GUIDIdx - 1];
683695
assert(HashIdx < YamlPD.Hash.size());
684696
uint64_t YamlHash = YamlPD.Hash[HashIdx];
685-
if (YamlHash != It->FuncHash)
697+
if (YamlHash != It->FuncHash) {
698+
LLVM_DEBUG(dbgs() << "hash mismatch\n");
686699
continue;
700+
}
687701

688702
// Look for binary inline trees with the best match to YAML inline tree.
689703
auto Range = llvm::make_range(std::equal_range(
@@ -707,17 +721,15 @@ size_t YAMLProfileReader::matchWithPseudoProbes(BinaryContext &BC) {
707721
BestNodes.push_back(Node);
708722
}
709723

724+
LLVM_DEBUG(dbgs() << BestNodes.size() << " candidates: ");
725+
710726
// Find binary functions containing best matching binary inline tree nodes.
711727
DenseMap<BinaryFunction *, uint32_t> BFProbeCountMap;
712728
for (const MCDecodedPseudoProbeInlineTree *Node : BestNodes) {
713729
// Find top-level function containing Node.
714730
const MCDecodedPseudoProbeInlineTree *Root = Node;
715731
while (!Root->Parent->isRoot())
716732
Root = (const MCDecodedPseudoProbeInlineTree *)Root->Parent;
717-
// Get containing non-profiled binary function.
718-
auto GUIDToBFIt = GUIDToBF.find(Root->Guid);
719-
if (GUIDToBFIt == GUIDToBF.end())
720-
continue;
721733
// Compute the number of probes belonging to functions.
722734
for (const MCDecodedPseudoProbe &Probe : Node->getProbes()) {
723735
uint64_t Address = Probe.getAddress();
@@ -732,10 +744,13 @@ size_t YAMLProfileReader::matchWithPseudoProbes(BinaryContext &BC) {
732744
llvm::sort(BFProbeCountVec);
733745
for (BinaryFunction *BF : llvm::make_second_range(BFProbeCountVec)) {
734746
// Check if BF already has profile attached, bail for now.
735-
if (ProfiledFunctions.count(BF))
747+
if (ProfiledFunctions.count(BF)) {
748+
LLVM_DEBUG(dbgs() << *BF << " is already profiled, ");
736749
continue;
750+
}
737751
matchProfileToFunction(YamlBF, *BF);
738752
++MatchedWithPseudoProbes;
753+
LLVM_DEBUG(dbgs() << "matched to " << *BF << '\n');
739754
break;
740755
}
741756
}

0 commit comments

Comments
 (0)