30#define DEBUG_TYPE "mcpseudoprobe"
33using namespace support;
53 assert((LastProbe || IsSentinel) &&
54 "Last probe should not be null for non-sentinel probes");
63 assert(
Type <= 0xF &&
"Probe type too big to encode, exceeding 15");
67 assert(NewAttributes <= 0x7 &&
68 "Probe attributes too big to encode, exceeding 7");
69 uint8_t PackedType =
Type | (NewAttributes << 4);
116 if (InlineStack.
empty()) {
126 if (!InlineStack.
empty()) {
127 auto Iter = InlineStack.
begin();
128 auto Index = std::get<1>(*Iter);
130 for (; Iter != InlineStack.
end(); Iter++) {
133 Index = std::get<1>(*Iter);
138 Cur->Probes.push_back(Probe);
145 dbgs() <<
"Group [\n";
148 assert(!
isRoot() &&
"Root should be handled seperately");
159 bool NeedSentinel =
false;
162 "Starting probe of a top-level function should be a sentinel probe");
173 LastProbe->
emit(MCOS,
nullptr);
176 for (
const auto &Probe :
Probes) {
177 Probe.emit(MCOS, LastProbe);
183 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
184 auto Comparer = [](
const InlineeType &
A,
const InlineeType &
B) {
185 return A.first <
B.first;
187 std::vector<InlineeType> Inlinees;
189 Inlinees.emplace_back(Child.first, Child.second.get());
190 std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
192 for (
const auto &Inlinee : Inlinees) {
197 dbgs() <<
"InlineSite: " << std::get<1>(Inlinee.first) <<
"\n";
200 Inlinee.second->emit(MCOS, LastProbe);
212 for (
auto &ProbeSec : MCProbeDivisions) {
213 const auto *FuncSym = ProbeSec.first;
214 const auto &Root = ProbeSec.second;
216 FuncSym->getSection())) {
222 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
223 auto Comparer = [](
const InlineeType &
A,
const InlineeType &
B) {
224 return A.first <
B.first;
226 std::vector<InlineeType> Inlinees;
227 for (
const auto &Child : Root.getChildren())
228 Inlinees.emplace_back(Child.first, Child.second.get());
229 std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
231 for (
const auto &Inlinee : Inlinees) {
239 Inlinee.second->emit(MCOS, Probe);
255 if (ProbeSections.empty())
261 ProbeSections.emit(MCOS);
266 auto It = GUID2FuncMAP.
find(GUID);
267 assert(It != GUID2FuncMAP.end() &&
268 "Probe function must exist for a valid GUID");
269 return It->second.FuncName;
291 std::reverse(ContextStack.
begin() + Begin, ContextStack.
end());
296 std::ostringstream OContextStr;
299 for (
auto &Cxt : ContextStack) {
300 if (OContextStr.str().size())
301 OContextStr <<
" @ ";
302 OContextStr << Cxt.first.str() <<
":" << Cxt.second;
304 return OContextStr.str();
312 bool ShowName)
const {
316 OS << FuncName.
str() <<
" ";
320 OS <<
"Index: " <<
Index <<
" ";
325 if (InlineContextStr.size()) {
327 OS << InlineContextStr;
332template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnencodedNumber() {
333 if (Data +
sizeof(
T) > End) {
334 return std::error_code();
336 T Val = endian::readNext<T, little, unaligned>(Data);
340template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnsignedNumber() {
341 unsigned NumBytesRead = 0;
343 if (Val > std::numeric_limits<T>::max() || (Data + NumBytesRead > End)) {
344 return std::error_code();
346 Data += NumBytesRead;
350template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readSignedNumber() {
351 unsigned NumBytesRead = 0;
353 if (Val > std::numeric_limits<T>::max() || (Data + NumBytesRead > End)) {
354 return std::error_code();
356 Data += NumBytesRead;
362 if (Data +
Size > End) {
363 return std::error_code();
386 auto ErrorOrGUID = readUnencodedNumber<uint64_t>();
390 auto ErrorOrHash = readUnencodedNumber<uint64_t>();
394 auto ErrorOrNameSize = readUnsignedNumber<uint32_t>();
395 if (!ErrorOrNameSize)
399 auto ErrorOrName = readString(
NameSize);
403 uint64_t GUID = std::move(*ErrorOrGUID);
404 uint64_t Hash = std::move(*ErrorOrHash);
410 assert(Data == End &&
"Have unprocessed data in pseudo_probe_desc section");
421 bool IsTopLevelFunc = Cur == &DummyInlineRoot;
422 if (IsTopLevelFunc) {
427 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
430 Index = std::move(*ErrorOrIndex);
434 auto ErrorOrCurGuid = readUnencodedNumber<uint64_t>();
437 uint64_t Guid = std::move(*ErrorOrCurGuid);
440 if (IsTopLevelFunc && !GuidFilter.
empty() && !GuidFilter.
count(Guid))
448 if (IsTopLevelFunc && !EncodingIsAddrBased) {
449 if (
auto V = FuncStartAddrs.
lookup(Guid))
455 auto ErrorOrNodeCount = readUnsignedNumber<uint32_t>();
456 if (!ErrorOrNodeCount)
458 uint32_t NodeCount = std::move(*ErrorOrNodeCount);
460 auto ErrorOrCurChildrenToProcess = readUnsignedNumber<uint32_t>();
461 if (!ErrorOrCurChildrenToProcess)
464 for (std::size_t
I = 0;
I < NodeCount;
I++) {
466 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
471 auto ErrorOrValue = readUnencodedNumber<uint8_t>();
474 uint8_t
Value = std::move(*ErrorOrValue);
475 uint8_t Kind =
Value & 0xf;
476 uint8_t Attr = (
Value & 0x70) >> 4;
480 auto ErrorOrOffset = readSignedNumber<int64_t>();
483 int64_t
Offset = std::move(*ErrorOrOffset);
486 auto ErrorOrAddr = readUnencodedNumber<int64_t>();
489 Addr = std::move(*ErrorOrAddr);
500 EncodingIsAddrBased =
true;
506 auto ErrorOrDiscriminator = readUnsignedNumber<uint32_t>();
507 if (!ErrorOrDiscriminator)
509 Discriminator = std::move(*ErrorOrDiscriminator);
514 auto &Probes = Address2ProbesMap[
Addr];
522 uint32_t ChildrenToProcess = std::move(*ErrorOrCurChildrenToProcess);
531 const uint8_t *Start, std::size_t
Size,
const Uint64Set &GuidFilter,
539 assert(Data == End &&
"Have unprocessed data in pseudo_probe section");
544 OS <<
"Pseudo Probe Desc:\n";
546 std::map<uint64_t, MCPseudoProbeFuncDesc> OrderedMap(GUID2FuncDescMap.begin(),
547 GUID2FuncDescMap.end());
548 for (
auto &
I : OrderedMap) {
555 auto It = Address2ProbesMap.find(
Address);
556 if (It != Address2ProbesMap.end()) {
557 for (
auto &Probe : It->second) {
559 Probe.print(
OS, GUID2FuncDescMap,
true);
565 std::vector<uint64_t> Addresses;
566 for (
auto Entry : Address2ProbesMap)
567 Addresses.push_back(Entry.first);
569 for (
auto K : Addresses) {
579 auto It = Address2ProbesMap.find(
Address);
580 if (It == Address2ProbesMap.end())
582 const auto &Probes = It->second;
585 for (
const auto &Probe : Probes) {
586 if (Probe.isCall()) {
588 "There should be only one call probe corresponding to address "
589 "which is a callsite.");
598 auto It = GUID2FuncDescMap.find(GUID);
599 assert(It != GUID2FuncDescMap.end() &&
"Function descriptor doesn't exist");
606 bool IncludeLeaf)
const {
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
static const char * PseudoProbeTypeStr[3]
static StringRef getProbeFNameForGUID(const GUIDProbeFunctionMap &GUID2FuncMAP, uint64_t GUID)
static const MCExpr * buildSymbolDiff(MCObjectStreamer *MCOS, const MCSymbol *A, const MCSymbol *B)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Represents either an error or a value T.
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Context object for machine code objects.
MCPseudoProbeTable & getMCPseudoProbeTable()
const MCObjectFileInfo * getObjectFileInfo() const
bool hasInlineSite() const
void print(raw_ostream &OS, const GUIDProbeFunctionMap &GUID2FuncMAP, bool ShowName) const
std::string getInlineContextStr(const GUIDProbeFunctionMap &GUID2FuncMAP) const
void getInlineContext(SmallVectorImpl< MCPseduoProbeFrameLocation > &ContextStack, const GUIDProbeFunctionMap &GUID2FuncMAP) const
MCDecodedPseudoProbeInlineTree * getInlineTreeNode() const
Base class for the full range of assembler expressions which are needed for parsing.
MCSection * getPseudoProbeSection(const MCSection &TextSec) const
Streaming object file generation interface.
MCAssembler * getAssemblerPtr() override
void insert(MCFragment *F)
uint8_t getAttributes() const
uint64_t getIndex() const
bool buildAddress2ProbeMap(const uint8_t *Start, std::size_t Size, const Uint64Set &GuildFilter, const Uint64Map &FuncStartAddrs)
void getInlineContextForProbe(const MCDecodedPseudoProbe *Probe, SmallVectorImpl< MCPseduoProbeFrameLocation > &InlineContextStack, bool IncludeLeaf) const
void printProbesForAllAddresses(raw_ostream &OS)
bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size)
void printGUID2FuncDescMap(raw_ostream &OS)
void printProbeForAddress(raw_ostream &OS, uint64_t Address)
const MCPseudoProbeFuncDesc * getInlinerDescForProbe(const MCDecodedPseudoProbe *Probe) const
const MCDecodedPseudoProbe * getCallProbeForAddr(uint64_t Address) const
const MCPseudoProbeFuncDesc * getFuncDescForGUID(uint64_t GUID) const
InlinedProbeTreeMap & getChildren()
MCPseudoProbeInlineTreeBase< MCPseudoProbe, MCPseudoProbeInlineTree > * Parent
void addProbes(ProbeType Probe)
MCPseudoProbeInlineTree * getOrAddNode(const InlineSite &Site)
std::vector< MCPseudoProbe > Probes
InlinedProbeTreeMap Children
void emit(MCObjectStreamer *MCOS, const MCPseudoProbe *&LastProbe)
void addPseudoProbe(const MCPseudoProbe &Probe, const MCPseudoProbeInlineStack &InlineStack)
void emit(MCObjectStreamer *MCOS)
MCPseudoProbeSections & getProbeSections()
static int DdgPrintIndent
static void emit(MCObjectStreamer *MCOS)
Instances of this class represent a pseudo probe instance for a pseudo probe table entry,...
MCSymbol * getLabel() const
void emit(MCObjectStreamer *MCOS, const MCPseudoProbe *LastProbe) const
MCContext & getContext() const
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void emitInt64(uint64_t Value)
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void emitInt8(uint64_t Value)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
constexpr size_t NameSize
This is an optimization pass for GlobalISel generic memory operations.
static bool isSentinelProbe(uint32_t Flags)
std::tuple< uint64_t, uint32_t > InlineSite
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
std::pair< StringRef, uint32_t > MCPseduoProbeFrameLocation
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool hasDiscriminator(uint32_t Flags)
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
std::unordered_map< uint64_t, MCPseudoProbeFuncDesc > GUIDProbeFunctionMap
void print(raw_ostream &OS)