@@ -40,13 +40,6 @@ struct PerfSpeEventsTestHelper : public testing::Test {
40
40
protected:
41
41
using Trace = DataAggregator::Trace;
42
42
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
- };
50
43
51
44
void initalizeLLVM () {
52
45
llvm::InitializeAllTargetInfos ();
@@ -82,23 +75,25 @@ struct PerfSpeEventsTestHelper : public testing::Test {
82
75
83
76
// / Helper function to export lists to show the mismatch.
84
77
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 " ;
92
85
93
86
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 " ;
97
91
}
98
92
99
93
// / Parse and check SPE brstack as LBR.
100
94
void parseAndCheckBrstackEvents (
101
- uint64_t PID, const std::vector<MockBranchInfo> &ExpectedSamples) {
95
+ uint64_t PID,
96
+ const std::vector<std::pair<Trace, TakenBranchInfo>> &ExpectedSamples) {
102
97
DataAggregator DA (" <pseudo input>" );
103
98
DA.ParsingBuf = opts::ReadPerfEvents;
104
99
DA.BC = BC.get ();
@@ -107,18 +102,19 @@ struct PerfSpeEventsTestHelper : public testing::Test {
107
102
108
103
DA.parseBranchEvents ();
109
104
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);
113
108
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 ; });
117
114
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 );
122
118
}
123
119
}
124
120
};
@@ -147,16 +143,20 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
147
143
" 1234 0xf001/0xf002/MN/-/-/8/COND/-\n "
148
144
" 1234 0xc456/0xc789/M/-/-/13/-/-\n " ;
149
145
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 }}};
160
160
161
161
parseAndCheckBrstackEvents (1234 , ExpectedSamples);
162
162
}
0 commit comments