@@ -72,7 +72,8 @@ class PseudoProbeRewriter final : public MetadataRewriter {
72
72
73
73
// / Parse .pseudo_probe_desc section and .pseudo_probe section
74
74
// / Setup Pseudo probe decoder
75
- void parsePseudoProbe ();
75
+ // / If \p ProfiledOnly is set, only parse records for functions with profile.
76
+ void parsePseudoProbe (bool ProfiledOnly = false );
76
77
77
78
// / PseudoProbe decoder
78
79
std::shared_ptr<MCPseudoProbeDecoder> ProbeDecoderPtr;
@@ -92,7 +93,7 @@ class PseudoProbeRewriter final : public MetadataRewriter {
92
93
93
94
Error PseudoProbeRewriter::preCFGInitializer () {
94
95
if (opts::ProfileWritePseudoProbes)
95
- parsePseudoProbe ();
96
+ parsePseudoProbe (true );
96
97
97
98
return Error::success ();
98
99
}
@@ -105,7 +106,7 @@ Error PseudoProbeRewriter::postEmitFinalizer() {
105
106
return Error::success ();
106
107
}
107
108
108
- void PseudoProbeRewriter::parsePseudoProbe () {
109
+ void PseudoProbeRewriter::parsePseudoProbe (bool ProfiledOnly ) {
109
110
MCPseudoProbeDecoder &ProbeDecoder (*ProbeDecoderPtr);
110
111
PseudoProbeDescSection = BC.getUniqueSectionByName (" .pseudo_probe_desc" );
111
112
PseudoProbeSection = BC.getUniqueSectionByName (" .pseudo_probe" );
@@ -136,6 +137,7 @@ void PseudoProbeRewriter::parsePseudoProbe() {
136
137
MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
137
138
SmallVector<StringRef, 3 > Suffixes ({" .destroy" , " .resume" , " .llvm." });
138
139
for (const BinaryFunction *F : BC.getAllBinaryFunctions ()) {
140
+ bool HasProfile = F->hasProfileAvailable ();
139
141
for (const MCSymbol *Sym : F->getSymbols ()) {
140
142
StringRef SymName = NameResolver::restore (Sym->getName ());
141
143
if (std::optional<StringRef> CommonName =
@@ -144,6 +146,23 @@ void PseudoProbeRewriter::parsePseudoProbe() {
144
146
}
145
147
uint64_t GUID = Function::getGUID (SymName);
146
148
FuncStartAddrs[GUID] = F->getAddress ();
149
+ if (ProfiledOnly && HasProfile)
150
+ GuidFilter.insert (GUID);
151
+ std::optional<StringRef> CommonName =
152
+ getCommonName (SymName, false , Suffixes);
153
+ if (!CommonName)
154
+ continue ;
155
+ GUID = Function::getGUID (*CommonName);
156
+ FuncStartAddrs.try_emplace (GUID, F->getAddress ());
157
+ if (ProfiledOnly && HasProfile)
158
+ GuidFilter.insert (GUID);
159
+ }
160
+ }
161
+ if (ProfiledOnly) {
162
+ for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap ()) {
163
+ uint64_t GUID = FuncDesc.FuncGUID ;
164
+ if (!FuncStartAddrs.contains (GUID))
165
+ GuidFilter.insert (GUID);
147
166
}
148
167
}
149
168
Contents = PseudoProbeSection->getContents ();
0 commit comments