1919#include " llvm/MC/MCSymbol.h"
2020#include " llvm/Support/Endian.h"
2121#include " llvm/Support/Error.h"
22+ #include " llvm/Support/FormatVariadic.h"
2223#include " llvm/Support/LEB128.h"
2324#include " llvm/Support/MD5.h"
25+ #include " llvm/Support/Timer.h"
2426#include " llvm/Support/raw_ostream.h"
2527#include < algorithm>
2628#include < cassert>
@@ -376,6 +378,8 @@ ErrorOr<StringRef> MCPseudoProbeDecoder::readString(uint32_t Size) {
376378
377379bool MCPseudoProbeDecoder::buildGUID2FuncDescMap (const uint8_t *Start,
378380 std::size_t Size) {
381+ Timer T (" buildGUID2FDMap" , " build GUID to FuncDesc map" );
382+ T.startTimer ();
379383 // The pseudo_probe_desc section has a format like:
380384 // .section .pseudo_probe_desc,"",@progbits
381385 // .quad -5182264717993193164 // GUID
@@ -430,6 +434,12 @@ bool MCPseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
430434 llvm::sort (GUID2FuncDescMap, [](const auto &LHS, const auto &RHS) {
431435 return LHS.FuncGUID < RHS.FuncGUID ;
432436 });
437+ T.stopTimer ();
438+ auto TT = T.getTotalTime ();
439+ T.clear ();
440+ dbgs () << " func desc " ;
441+ TT.print (TT, dbgs ());
442+ dbgs () << ' \n ' ;
433443 return true ;
434444}
435445
@@ -623,32 +633,53 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap(
623633 Data = Start;
624634 End = Data + Size;
625635 bool Discard = false ;
636+ Timer T (" countRecords" , " pre-parsing function records" );
637+ T.startTimer ();
626638 while (Data < End) {
627639 if (!countRecords<true >(Discard, ProbeCount, InlinedCount, GuidFilter))
628640 return false ;
629641 TopLevelFuncs += !Discard;
630642 }
643+ T.stopTimer ();
644+ auto TT = T.getTotalTime ();
645+ T.clear ();
646+ dbgs () << " pre-parsing " ;
647+ TT.print (TT, dbgs ());
631648 assert (Data == End && " Have unprocessed data in pseudo_probe section" );
649+ T.startTimer ();
632650 PseudoProbeVec.reserve (ProbeCount);
633651 InlineTreeVec.reserve (InlinedCount);
634652
635653 // Allocate top-level function records as children of DummyInlineRoot.
636654 InlineTreeVec.resize (TopLevelFuncs);
637655 DummyInlineRoot.getChildren () = MutableArrayRef (InlineTreeVec);
638656
657+ T.stopTimer ();
658+ TT = T.getTotalTime ();
659+ T.clear ();
660+ dbgs () << " \n alloc " ;
661+ TT.print (TT, dbgs ());
662+
663+ T.startTimer ();
639664 Data = Start;
640665 End = Data + Size;
641666 uint64_t LastAddr = 0 ;
642667 uint32_t CurChildIndex = 0 ;
643668 while (Data < End)
644669 CurChildIndex += buildAddress2ProbeMap<true >(
645670 &DummyInlineRoot, LastAddr, GuidFilter, FuncStartAddrs, CurChildIndex);
671+ T.stopTimer ();
672+ TT = T.getTotalTime ();
673+ T.clear ();
674+ dbgs () << " \n parsing " ;
675+ TT.print (TT, dbgs ());
646676 assert (Data == End && " Have unprocessed data in pseudo_probe section" );
647677 assert (PseudoProbeVec.size () == ProbeCount &&
648678 " Mismatching probe count pre- and post-parsing" );
649679 assert (InlineTreeVec.size () == InlinedCount &&
650680 " Mismatching function records count pre- and post-parsing" );
651681
682+ T.startTimer ();
652683 std::vector<std::pair<uint64_t , uint32_t >> SortedA2P (ProbeCount);
653684 for (const auto &[I, Probe] : llvm::enumerate (PseudoProbeVec))
654685 SortedA2P[I] = {Probe.getAddress (), I};
@@ -657,6 +688,25 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap(
657688 for (const uint32_t I : llvm::make_second_range (SortedA2P))
658689 Address2ProbesMap.emplace_back (PseudoProbeVec[I]);
659690 SortedA2P.clear ();
691+ T.stopTimer ();
692+ TT = T.getTotalTime ();
693+ T.clear ();
694+ dbgs () << " \n sorting " ;
695+ TT.print (TT, dbgs ());
696+ dbgs () << ' \n ' ;
697+ size_t PPVecSize = 32 * PseudoProbeVec.capacity ();
698+ size_t ITVecSize = 48 * InlineTreeVec.capacity ();
699+ size_t G2FDMapSize = 32 * GUID2FuncDescMap.capacity ();
700+ size_t StringSize = FuncNameAllocator.getBytesAllocated ();
701+ size_t A2PSize = 8 * Address2ProbesMap.capacity ();
702+ dbgs () << formatv (" PPVec size: {0} GiB\n " , 1 .f * PPVecSize / (1 << 30 ))
703+ << formatv (" ITVec size: {0} GiB\n " , 1 .f * ITVecSize / (1 << 30 ))
704+ << formatv (" G2FDMap size: {0} GiB\n " , 1 .f * G2FDMapSize / (1 << 30 ))
705+ << formatv (" (strings {0} GiB)\n " , 1 .f * StringSize / (1 << 30 ))
706+ << formatv (" A2P size: {0} GiB\n " , 1 .f * A2PSize / (1 << 30 ))
707+ << formatv (" Total size: {0} GiB\n " ,
708+ 1 .f * (PPVecSize + ITVecSize + G2FDMapSize + A2PSize) /
709+ (1 << 30 ));
660710 return true ;
661711}
662712
0 commit comments