[PATCH] D87740: fix llvm-profdata overlap crash

Lei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 21:14:39 PDT 2020


wlei created this revision.
Herald added subscribers: llvm-commits, wenlei.
Herald added a project: LLVM.
wlei requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87740

Files:
  llvm/test/tools/llvm-profdata/compact-sample.proftext
  llvm/tools/llvm-profdata/llvm-profdata.cpp


Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -1540,14 +1540,14 @@
   StringMap<const FunctionSamples *> BaseFuncProf;
   const auto &BaseProfiles = BaseReader->getProfiles();
   for (const auto &BaseFunc : BaseProfiles) {
-    BaseFuncProf.try_emplace(BaseFunc.second.getFuncName(), &(BaseFunc.second));
+    BaseFuncProf.try_emplace(BaseFunc.second.getName(), &(BaseFunc.second));
   }
   ProfOverlap.UnionCount = BaseFuncProf.size();
 
   const auto &TestProfiles = TestReader->getProfiles();
   for (const auto &TestFunc : TestProfiles) {
     SampleOverlapStats FuncOverlap;
-    FuncOverlap.TestName = TestFunc.second.getFuncName();
+    FuncOverlap.TestName = TestFunc.second.getName();
     assert(TestStats.count(FuncOverlap.TestName) &&
            "TestStats should have records for all functions in test profile "
            "except inlinees");
@@ -1574,7 +1574,7 @@
 
       // Two functions match with each other. Compute function-level overlap and
       // aggregate them into profile-level overlap.
-      FuncOverlap.BaseName = Match->second->getFuncName();
+      FuncOverlap.BaseName = Match->second->getName();
       assert(BaseStats.count(FuncOverlap.BaseName) &&
              "BaseStats should have records for all functions in base profile "
              "except inlinees");
@@ -1623,10 +1623,10 @@
 
   // Traverse through functions in base profile but not in test profile.
   for (const auto &F : BaseFuncProf) {
-    assert(BaseStats.count(F.second->getFuncName()) &&
+    assert(BaseStats.count(F.second->getName()) &&
            "BaseStats should have records for all functions in base profile "
            "except inlinees");
-    const FuncSampleStats &FuncStats = BaseStats[F.second->getFuncName()];
+    const FuncSampleStats &FuncStats = BaseStats[F.second->getName()];
     ++ProfOverlap.BaseUniqueCount;
     ProfOverlap.BaseUniqueSample += FuncStats.SampleSum;
 
@@ -1657,7 +1657,7 @@
     FuncSampleStats FuncStats;
     getFuncSampleStats(I.second, FuncStats, BaseHotThreshold);
     ProfOverlap.BaseSample += FuncStats.SampleSum;
-    BaseStats.try_emplace(I.second.getFuncName(), FuncStats);
+    BaseStats.try_emplace(I.second.getName(), FuncStats);
   }
 
   const auto &TestProf = TestReader->getProfiles();
@@ -1666,7 +1666,7 @@
     FuncSampleStats FuncStats;
     getFuncSampleStats(I.second, FuncStats, TestHotThreshold);
     ProfOverlap.TestSample += FuncStats.SampleSum;
-    TestStats.try_emplace(I.second.getFuncName(), FuncStats);
+    TestStats.try_emplace(I.second.getName(), FuncStats);
   }
 
   ProfOverlap.BaseName = StringRef(BaseFilename);
@@ -2297,9 +2297,8 @@
         (ProfileTotalSample > 0)
             ? (Func.getTotalSamples() * 100.0) / ProfileTotalSample
             : 0;
-    PrintValues.emplace_back(HotFuncInfo(
-        Func.getFuncName(), Func.getTotalSamples(), TotalSamplePercent,
-        FuncPair.second.second, Func.getEntrySamples()));
+    PrintValues.emplace_back(HotFuncInfo(Func.getName(), Func.getTotalSamples(), TotalSamplePercent,
+                    FuncPair.second.second, Func.getEntrySamples()));
   }
   dumpHotFunctionList(ColumnTitle, ColumnOffset, PrintValues, HotFuncCount,
                       Profiles.size(), HotFuncSample, ProfileTotalSample,
Index: llvm/test/tools/llvm-profdata/compact-sample.proftext
===================================================================
--- llvm/test/tools/llvm-profdata/compact-sample.proftext
+++ llvm/test/tools/llvm-profdata/compact-sample.proftext
@@ -1,8 +1,20 @@
 # Make sure "llvm-profdata show" works for sample profile in binary compact format
 
-# RUN: llvm-profdata show -sample %S/Inputs/compat-sample.profdata  | FileCheck %s 
+# RUN: llvm-profdata show -sample %S/Inputs/compat-sample.profdata  | FileCheck %s
 
-# CHECK: Function: 15822663052811949562: 17, 0, 6 sampled lines 
+# CHECK: Function: 15822663052811949562: 17, 0, 6 sampled lines
 # CHECK-NEXT: Samples collected in the function's body {
 # CHECK: Samples collected in inlined callsites {
 # CHECK-NEXT: 1: inlined callee: 6309742469962978389: 17, 0, 1
+
+# RUN: llvm-profdata show -hot-func-list -sample %S/Inputs/compat-sample.profdata  | FileCheck %s -check-prefix=HOTFUNC
+# HOTFUNC: 24753993 out of 24754010 profile counts (100.00%) are from hot functions.
+# HOTFUNC:  Total sample (%)       Max sample        Entry sample    Function name
+# HOTFUNC-NEXT:  24753993 (100.00%)     1284671           1284671         16429767378996342100
+
+# Make sure "llvm-profdata overlap" works for sample profile in binary compact format
+# RUN: llvm-profdata overlap -sample %S/Inputs/compat-sample.profdata %S/Inputs/compat-sample.profdata   | FileCheck %s -check-prefix=OVERLAP
+
+# OVERLAP: Program level:
+# OVERLAP-NEXT:   Whole program profile similarity: 100.000%
+# OVERLAP-NEXT:   Whole program sample overlap: 100.000%


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87740.292087.patch
Type: text/x-patch
Size: 5018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200916/469b6b3a/attachment.bin>


More information about the llvm-commits mailing list