diff options
author | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2023-04-12 10:21:38 -0700 |
---|---|---|
committer | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2023-04-13 10:37:05 -0700 |
commit | 4bddef4117403a305727d145a9abf6bda700f8ff (patch) | |
tree | fecf699626134bbc6558209bb1a4b1b0134349d4 /llvm/unittests/ProfileData/InstrProfTest.cpp | |
parent | aca110f9dd17f2ec6492e56472a49bd409c185ae (diff) | |
download | llvm-4bddef4117403a305727d145a9abf6bda700f8ff.zip llvm-4bddef4117403a305727d145a9abf6bda700f8ff.tar.gz llvm-4bddef4117403a305727d145a9abf6bda700f8ff.tar.bz2 |
[InstrProf][Temporal] Add weight field to traces
As discussed in [0], add a `weight` field to temporal profiling traces found in profiles. This allows users to use the `--weighted-input=` flag in the `llvm-profdata merge` command to weight traces from different scenarios differently.
Note that this is a breaking change, but since [1] landed very recently and there is no way to "use" this trace data, there should be no users of this feature. We believe it is acceptable to land this change without bumping the profile format version.
[0] https://reviews.llvm.org/D147812#4259507
[1] https://reviews.llvm.org/D147287
Reviewed By: snehasish
Differential Revision: https://reviews.llvm.org/D148150
Diffstat (limited to 'llvm/unittests/ProfileData/InstrProfTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/InstrProfTest.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index dc58347..26211bd 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -39,6 +39,14 @@ ErrorEquals(instrprof_error Expected, Error E) { return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n"; } +namespace llvm { +bool operator==(const TemporalProfTraceTy &lhs, + const TemporalProfTraceTy &rhs) { + return lhs.Weight == rhs.Weight && + lhs.FunctionNameRefs == rhs.FunctionNameRefs; +} +} // end namespace llvm + namespace { struct InstrProfTest : ::testing::Test { @@ -234,13 +242,15 @@ TEST_F(InstrProfTest, test_merge_temporal_prof_traces_truncated) { ASSERT_THAT_ERROR(Writer.mergeProfileKind(InstrProfKind::TemporalProfile), Succeeded()); - auto LargeTrace = {IndexedInstrProf::ComputeHash("foo"), - IndexedInstrProf::ComputeHash("bar"), - IndexedInstrProf::ComputeHash("goo")}; - auto SmallTrace = {IndexedInstrProf::ComputeHash("foo"), - IndexedInstrProf::ComputeHash("bar")}; + TemporalProfTraceTy LargeTrace, SmallTrace; + LargeTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("foo"), + IndexedInstrProf::ComputeHash("bar"), + IndexedInstrProf::ComputeHash("goo")}; + SmallTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("foo"), + IndexedInstrProf::ComputeHash("bar")}; - Writer.addTemporalProfileTraces({LargeTrace, SmallTrace}, 2); + SmallVector Traces = {LargeTrace, SmallTrace}; + Writer.addTemporalProfileTraces(Traces, 2); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); @@ -261,11 +271,13 @@ TEST_F(InstrProfTest, test_merge_traces_from_writer) { ASSERT_THAT_ERROR(Writer2.mergeProfileKind(InstrProfKind::TemporalProfile), Succeeded()); - auto FooTrace = {IndexedInstrProf::ComputeHash("foo")}; - auto BarTrace = {IndexedInstrProf::ComputeHash("bar")}; + TemporalProfTraceTy FooTrace, BarTrace; + FooTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("foo")}; + BarTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("bar")}; - Writer.addTemporalProfileTraces({FooTrace}, 1); - Writer2.addTemporalProfileTraces({BarTrace}, 1); + SmallVector Traces1({FooTrace}), Traces2({BarTrace}); + Writer.addTemporalProfileTraces(Traces1, 1); + Writer2.addTemporalProfileTraces(Traces2, 1); Writer.mergeRecordsFromWriter(std::move(Writer2), Err); auto Profile = Writer.writeBuffer(); @@ -284,15 +296,19 @@ TEST_F(InstrProfTest, test_merge_traces_sampled) { ASSERT_THAT_ERROR(Writer.mergeProfileKind(InstrProfKind::TemporalProfile), Succeeded()); - auto FooTrace = {IndexedInstrProf::ComputeHash("foo")}; - auto BarTrace = {IndexedInstrProf::ComputeHash("bar")}; - auto GooTrace = {IndexedInstrProf::ComputeHash("Goo")}; + TemporalProfTraceTy FooTrace, BarTrace, GooTrace; + FooTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("foo")}; + BarTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("bar")}; + GooTrace.FunctionNameRefs = {IndexedInstrProf::ComputeHash("Goo")}; // Add some sampled traces - Writer.addTemporalProfileTraces({FooTrace, BarTrace, GooTrace}, 5); + SmallVector SampledTraces = {FooTrace, BarTrace, GooTrace}; + Writer.addTemporalProfileTraces(SampledTraces, 5); // Add some unsampled traces - Writer.addTemporalProfileTraces({BarTrace, GooTrace}, 2); - Writer.addTemporalProfileTraces({FooTrace}, 1); + SmallVector UnsampledTraces = {BarTrace, GooTrace}; + Writer.addTemporalProfileTraces(UnsampledTraces, 2); + UnsampledTraces = {FooTrace}; + Writer.addTemporalProfileTraces(UnsampledTraces, 1); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); |