@@ -40,13 +40,6 @@ struct PerfSpeEventsTestHelper : public testing::Test {
4040protected:
4141 using Trace = DataAggregator::Trace;
4242 using TakenBranchInfo = DataAggregator::TakenBranchInfo;
43- using TraceHash = DataAggregator::TraceHash;
44- struct MockBranchInfo {
45- uint64_t From;
46- uint64_t To;
47- uint64_t TakenCount;
48- uint64_t MispredCount;
49- };
5043
5144 void initalizeLLVM () {
5245 llvm::InitializeAllTargetInfos ();
@@ -82,23 +75,25 @@ struct PerfSpeEventsTestHelper : public testing::Test {
8275
8376 // / Helper function to export lists to show the mismatch.
8477 void reportBrStackEventMismatch (
85- const std::unordered_map< Trace, TakenBranchInfo, TraceHash> &BranchLBRs ,
86- const std::vector<MockBranchInfo > &ExpectedSamples) {
87- llvm::errs () << " BranchLBRs items: \n " ;
88- for (const auto &AggrLBR : BranchLBRs )
89- llvm::errs () << " {" << AggrLBR. first . From << " , " << AggrLBR. first . To
90- << " , " << AggrLBR. second .TakenCount << " , "
91- << AggrLBR. second .MispredCount << " }" << " \n " ;
78+ const std::vector<std::pair< Trace, TakenBranchInfo>> &Traces ,
79+ const std::vector<std::pair<Trace, TakenBranchInfo> > &ExpectedSamples) {
80+ llvm::errs () << " Traces items: \n " ;
81+ for (const auto &[Trace, BI] : Traces )
82+ llvm::errs () << " {" << Trace. Branch << " , " << Trace. From << " , "
83+ << Trace. To << " , " << BI .TakenCount << " , "
84+ << BI .MispredCount << " }" << " \n " ;
9285
9386 llvm::errs () << " Expected items: \n " ;
94- for (const MockBranchInfo &BI : ExpectedSamples)
95- llvm::errs () << " {" << BI.From << " , " << BI.To << " , " << BI.TakenCount
96- << " , " << BI.MispredCount << " }" << " \n " ;
87+ for (const auto &[Trace, BI] : ExpectedSamples)
88+ llvm::errs () << " {" << Trace.Branch << " , " << Trace.From << " , "
89+ << Trace.To << " , " << BI.TakenCount << " , "
90+ << BI.MispredCount << " }" << " \n " ;
9791 }
9892
9993 // / Parse and check SPE brstack as LBR.
10094 void parseAndCheckBrstackEvents (
101- uint64_t PID, const std::vector<MockBranchInfo> &ExpectedSamples) {
95+ uint64_t PID,
96+ const std::vector<std::pair<Trace, TakenBranchInfo>> &ExpectedSamples) {
10297 DataAggregator DA (" <pseudo input>" );
10398 DA.ParsingBuf = opts::ReadPerfEvents;
10499 DA.BC = BC.get ();
@@ -107,18 +102,19 @@ struct PerfSpeEventsTestHelper : public testing::Test {
107102
108103 DA.parseBranchEvents ();
109104
110- EXPECT_EQ (DA.BranchLBRs .size (), ExpectedSamples.size ());
111- if (DA.BranchLBRs .size () != ExpectedSamples.size ())
112- reportBrStackEventMismatch (DA.BranchLBRs , ExpectedSamples);
105+ EXPECT_EQ (DA.Traces .size (), ExpectedSamples.size ());
106+ if (DA.Traces .size () != ExpectedSamples.size ())
107+ reportBrStackEventMismatch (DA.Traces , ExpectedSamples);
113108
114- for (const MockBranchInfo &BI : ExpectedSamples) {
115- // Check that each key exists and that it matches.
116- EXPECT_NO_THROW (DA.BranchLBRs .at (Trace (BI.From , BI.To )));
109+ const auto TracesBegin = DA.Traces .begin ();
110+ const auto TracesEnd = DA.Traces .end ();
111+ for (const auto &BI : ExpectedSamples) {
112+ auto it = find_if (TracesBegin, TracesEnd,
113+ [&BI](const auto &Tr) { return Tr.first == BI.first ; });
117114
118- EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).MispredCount ,
119- BI.MispredCount );
120- EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).TakenCount ,
121- BI.TakenCount );
115+ EXPECT_NE (it, TracesEnd);
116+ EXPECT_EQ (it->second .MispredCount , BI.second .MispredCount );
117+ EXPECT_EQ (it->second .TakenCount , BI.second .TakenCount );
122118 }
123119 }
124120};
@@ -147,16 +143,20 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
147143 " 1234 0xf001/0xf002/MN/-/-/8/COND/-\n "
148144 " 1234 0xc456/0xc789/M/-/-/13/-/-\n " ;
149145
150- // MockBranchInfo contains the aggregated information about
151- // a Branch {From, To, TakenCount, MispredCount}.
152- // Let's check the following example: {0xd123, 0xd456, 2, 2}.
153- // This entry has a TakenCount = 2,
154- // as we have two samples for (0xd123, 0xd456) in our input.
155- // It also has MispredsCount = 2, as 'M' misprediction flag
156- // appears in both cases.
157- std::vector<MockBranchInfo> ExpectedSamples = {
158- {0xa001 , 0xa002 , 1 , 0 }, {0xb001 , 0xb002 , 1 , 0 }, {0xc456 , 0xc789 , 2 , 1 },
159- {0xd123 , 0xd456 , 2 , 2 }, {0xe001 , 0xe002 , 1 , 0 }, {0xf001 , 0xf002 , 1 , 1 }};
146+ // ExpectedSamples contains the aggregated information about
147+ // a branch {{Branch From, To}, {TakenCount, MispredCount}}.
148+ // Consider this example trace: {{0xd123, 0xd456, Trace::BR_ONLY},
149+ // {2,2}}. This entry has a TakenCount = 2, as we have two samples for
150+ // (0xd123, 0xd456) in our input. It also has MispredsCount = 2,
151+ // as 'M' misprediction flag appears in both cases. BR_ONLY means
152+ // the trace only contains branch data.
153+ std::vector<std::pair<Trace, TakenBranchInfo>> ExpectedSamples = {
154+ {{0xa001 , 0xa002 , Trace::BR_ONLY}, {1 , 0 }},
155+ {{0xb001 , 0xb002 , Trace::BR_ONLY}, {1 , 0 }},
156+ {{0xc456 , 0xc789 , Trace::BR_ONLY}, {2 , 1 }},
157+ {{0xd123 , 0xd456 , Trace::BR_ONLY}, {2 , 2 }},
158+ {{0xe001 , 0xe002 , Trace::BR_ONLY}, {1 , 0 }},
159+ {{0xf001 , 0xf002 , Trace::BR_ONLY}, {1 , 1 }}};
160160
161161 parseAndCheckBrstackEvents (1234 , ExpectedSamples);
162162}
0 commit comments