llvm.org GIT mirror llvm / fbfbf06
[PGO] Refactor profile dumping function for ease of adding other profile kind Refactor the dumping function so that we can add other value profile kind easily. Differential Revision: https://reviews.llvm.org/D30752 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297399 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 2 years ago
2 changed file(s) with 64 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
4545 foo2:20000
4646
4747 #ICTXT: Indirect Call Site Count: 3
48 #ICTXT-NEXT: Indirect Target Results:
48 #ICTXT-NEXT: Indirect Target Results:
4949 #ICTXT-NEXT: [ 1, foo, 100 ]
5050 #ICTXT-NEXT: [ 1, foo2, 1000 ]
5151 #ICTXT-NEXT: [ 2, foo2, 20000 ]
5252
5353 #IC: Indirect Call Site Count: 3
54 #IC-NEXT: Indirect Target Results:
54 #IC-NEXT: Indirect Target Results:
5555 #IC-NEXT: [ 1, foo2, 1000 ]
5656 #IC-NEXT: [ 1, foo, 100 ]
5757 #IC-NEXT: [ 2, foo2, 20000 ]
7171 999000
7272 359800
7373
74 #ICSUM: Total Number of Indirect Call Sites : 3
75 #ICSUM: Total Number of Sites With Values : 2
76 #ICSUM: Total Number of Profiled Values : 3
74 #ICSUM: Statistics for indirect call sites profile:
75 #ICSUM: Total number of sites: 3
76 #ICSUM: Total number of sites with values: 2
77 #ICSUM: Total number of profiled values: 3
7778 #ICSUM: NumTargets, SiteCount
78 #ICSUM 1, 1
79 #ICSUM 2, 1
80
79 #ICSUM 1, 1
80 #ICSUM 2, 1
445445 return 0;
446446 }
447447
448 typedef struct ValueSitesStats {
449 ValueSitesStats()
450 : TotalNumValueSites(0), TotalNumValueSitesWithValueProfile(0),
451 TotalNumValues(0) {}
452 uint64_t TotalNumValueSites;
453 uint64_t TotalNumValueSitesWithValueProfile;
454 uint64_t TotalNumValues;
455 std::vector ValueSitesHistogram;
456 } ValueSitesStats;
457
458 static void traverseAllValueSites(const InstrProfRecord &Func, uint32_t VK,
459 ValueSitesStats &Stats, raw_fd_ostream &OS,
460 InstrProfSymtab &Symtab) {
461 uint32_t NS = Func.getNumValueSites(VK);
462 Stats.TotalNumValueSites += NS;
463 for (size_t I = 0; I < NS; ++I) {
464 uint32_t NV = Func.getNumValueDataForSite(VK, I);
465 std::unique_ptr VD = Func.getValueForSite(VK, I);
466 Stats.TotalNumValues += NV;
467 if (NV) {
468 Stats.TotalNumValueSitesWithValueProfile++;
469 if (NV > Stats.ValueSitesHistogram.size())
470 Stats.ValueSitesHistogram.resize(NV, 0);
471 Stats.ValueSitesHistogram[NV - 1]++;
472 }
473 for (uint32_t V = 0; V < NV; V++) {
474 OS << "\t[ " << I << ", ";
475 OS << Symtab.getFuncName(VD[V].Value) << ", " << VD[V].Count;
476 OS << " ]\n";
477 }
478 }
479 }
480
481 static void showValueSitesStats(raw_fd_ostream &OS, uint32_t VK,
482 ValueSitesStats &Stats) {
483 OS << " Total number of sites: " << Stats.TotalNumValueSites << "\n";
484 OS << " Total number of sites with values: "
485 << Stats.TotalNumValueSitesWithValueProfile << "\n";
486 OS << " Total number of profiled values: " << Stats.TotalNumValues << "\n";
487
488 OS << " Value sites histogram:\n\tNumTargets, SiteCount\n";
489 for (unsigned I = 0; I < Stats.ValueSitesHistogram.size(); I++) {
490 if (Stats.ValueSitesHistogram[I] > 0)
491 OS << "\t" << I + 1 << ", " << Stats.ValueSitesHistogram[I] << "\n";
492 }
493 }
494
448495 static int showInstrProfile(const std::string &Filename, bool ShowCounts,
449496 bool ShowIndirectCallTargets,
450497 bool ShowDetailedSummary,
464511 auto Reader = std::move(ReaderOrErr.get());
465512 bool IsIRInstr = Reader->isIRLevelProfile();
466513 size_t ShownFunctions = 0;
467 uint64_t TotalNumValueSites = 0;
468 uint64_t TotalNumValueSitesWithValueProfile = 0;
469 uint64_t TotalNumValues = 0;
470 std::vector ICHistogram;
514 int NumVPKind = IPVK_Last - IPVK_First + 1;
515 std::vector VPStats(NumVPKind);
471516 for (const auto &Func : *Reader) {
472517 bool Show =
473518 ShowAllFunctions || (!ShowFunction.empty() &&
511556 }
512557
513558 if (ShowIndirectCallTargets) {
514 InstrProfSymtab &Symtab = Reader->getSymtab();
515 uint32_t NS = Func.getNumValueSites(IPVK_IndirectCallTarget);
516 OS << " Indirect Target Results: \n";
517 TotalNumValueSites += NS;
518 for (size_t I = 0; I < NS; ++I) {
519 uint32_t NV = Func.getNumValueDataForSite(IPVK_IndirectCallTarget, I);
520 std::unique_ptr VD =
521 Func.getValueForSite(IPVK_IndirectCallTarget, I);
522 TotalNumValues += NV;
523 if (NV) {
524 TotalNumValueSitesWithValueProfile++;
525 if (NV > ICHistogram.size())
526 ICHistogram.resize(NV, 0);
527 ICHistogram[NV - 1]++;
528 }
529 for (uint32_t V = 0; V < NV; V++) {
530 OS << "\t[ " << I << ", ";
531 OS << Symtab.getFuncName(VD[V].Value) << ", " << VD[V].Count
532 << " ]\n";
533 }
534 }
559 OS << " Indirect Target Results:\n";
560 traverseAllValueSites(Func, IPVK_IndirectCallTarget,
561 VPStats[IPVK_IndirectCallTarget], OS,
562 Reader->getSymtab());
535563 }
536564 }
537565 }
547575 OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
548576 OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
549577 if (ShownFunctions && ShowIndirectCallTargets) {
550 OS << "Total Number of Indirect Call Sites : " << TotalNumValueSites
551 << "\n";
552 OS << "Total Number of Sites With Values : "
553 << TotalNumValueSitesWithValueProfile << "\n";
554 OS << "Total Number of Profiled Values : " << TotalNumValues << "\n";
555
556 OS << "IC Value histogram : \n\tNumTargets, SiteCount\n";
557 for (unsigned I = 0; I < ICHistogram.size(); I++) {
558 OS << "\t" << I + 1 << ", " << ICHistogram[I] << "\n";
559 }
578 OS << "Statistics for indirect call sites profile:\n";
579 showValueSitesStats(OS, IPVK_IndirectCallTarget,
580 VPStats[IPVK_IndirectCallTarget]);
560581 }
561582
562583 if (ShowDetailedSummary) {