-
Notifications
You must be signed in to change notification settings - Fork 2
/
AtlasStats.cpp
212 lines (176 loc) · 4.79 KB
/
AtlasStats.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "stdafx.h"
#include <list>
#include <cstdlib>
#include <string>
#include "AtlasTypes.h"
#include "AtlasLogger.h"
#include "AtlasStats.h"
StatisticsHandler Stats;
InsertionStatistics::InsertionStatistics()
{
ClearStats();
}
void InsertionStatistics::Init(unsigned int StartPos, unsigned int UpperBound, unsigned int LineStart, const string& BlockName)
{
ClearStats();
this->StartPos = StartPos;
this->LineStart = LineStart;
if (UpperBound != -1)
MaxBound = UpperBound;
Name = BlockName;
}
void InsertionStatistics::AddStats(InsertionStatistics& Stats)
{
ScriptSize += Stats.ScriptSize;
ScriptOverflowed += Stats.ScriptOverflowed;
SpaceRemaining += Stats.SpaceRemaining;
PointerWrites += Stats.PointerWrites;
EmbPointerWrites += Stats.EmbPointerWrites;
AutoPointerWrites += Stats.AutoPointerWrites;
FailedListWrites += Stats.FailedListWrites;
ExtPointerWrites += Stats.ExtPointerWrites;
for (int j = 0; j < CommandCount; j++)
ExecCount[j] += Stats.ExecCount[j];
}
void InsertionStatistics::ClearStats()
{
ScriptSize = 0;
ScriptOverflowed = 0;
SpaceRemaining = 0;
PointerWrites = 0;
EmbPointerWrites = 0;
AutoPointerWrites = 0;
FailedListWrites = 0;
ExtPointerWrites = 0;
StartPos = 0;
MaxBound = -1;
LineStart = 0;
LineEnd = 0;
memset(ExecCount, 0, 4 * CommandCount);
}
void InsertionStatistics::AddCmd(unsigned int CmdNum)
{
ExecCount[CmdNum]++;
switch (CmdNum)
{
case CMD_WUB: case CMD_WBB: case CMD_WHB: case CMD_WLB: case CMD_WHW:
case CMD_W16: case CMD_W24: case CMD_W32: case CMD_WRITEPTR:
case CMD_WUBCUST: case CMD_WBBCUST: case CMD_WHBCUST: case CMD_WLBCUST:
case CMD_WHWCUST:
PointerWrites++;
break;
default:
break;
}
}
bool InsertionStatistics::HasCommands()
{
for (unsigned int i = 0; i < CommandCount; i++)
if (ExecCount[i] != 0)
return true;
return false;
}
InsertionStatistics& InsertionStatistics::operator=(const InsertionStatistics& rhs)
{
if (this == &rhs)
return *this;
ScriptSize = rhs.ScriptSize;
ScriptOverflowed = rhs.ScriptOverflowed;
SpaceRemaining = rhs.SpaceRemaining;
PointerWrites = rhs.PointerWrites;
EmbPointerWrites = rhs.EmbPointerWrites;
StartPos = rhs.StartPos;
MaxBound = rhs.MaxBound;
LineStart = rhs.LineStart;
LineEnd = rhs.LineEnd;
Name = rhs.Name;
for (unsigned int i = 0; i < CommandCount; i++)
ExecCount[i] = rhs.ExecCount[i];
return *this;
}
StatisticsHandler::StatisticsHandler()
{
}
StatisticsHandler::~StatisticsHandler()
{
}
void StatisticsHandler::NewStatsBlock(unsigned int StartPos, unsigned int UpperBound, unsigned int LineStart, const string& BlockName)
{
if (CurBlock.LineStart != 0) // If not first block
{
CurBlock.ScriptOverflowed = 0;
CurBlock.SpaceRemaining = 0;
if (CurBlock.MaxBound != -1) // if there is a MaxBound, calc overflow and remaining space
{
if (CurBlock.StartPos + CurBlock.ScriptSize > CurBlock.MaxBound + 1)
CurBlock.ScriptOverflowed = CurBlock.StartPos + CurBlock.ScriptSize - CurBlock.MaxBound;
else
CurBlock.ScriptOverflowed = 0;
if (CurBlock.MaxBound + 1 > (CurBlock.StartPos + CurBlock.ScriptSize))
CurBlock.SpaceRemaining = CurBlock.MaxBound + 1 - (CurBlock.StartPos + CurBlock.ScriptSize);
else
CurBlock.SpaceRemaining = 0;
}
CurBlock.LineEnd = LineStart;
Stats.push_back(CurBlock);
}
CurBlock.Init(StartPos, UpperBound, LineStart, BlockName);
}
void StatisticsHandler::AddCmd(unsigned int CmdNum)
{
if (CmdNum < CommandCount)
CurBlock.AddCmd(CmdNum);
}
void StatisticsHandler::IncGenPointerWrites()
{
CurBlock.PointerWrites++;
}
void StatisticsHandler::IncEmbPointerWrites()
{
CurBlock.EmbPointerWrites++;
}
void StatisticsHandler::IncAutoPointerWrites()
{
CurBlock.AutoPointerWrites++;
}
void StatisticsHandler::IncFailedListWrites()
{
CurBlock.FailedListWrites++;
}
void StatisticsHandler::IncExtPointerWrites()
{
CurBlock.ExtPointerWrites++;
}
void StatisticsHandler::AddScriptBytes(unsigned int Count)
{
CurBlock.ScriptSize += Count;
}
void StatisticsHandler::End(unsigned int EndLine)
{
if (CurBlock.StartPos + CurBlock.ScriptSize > CurBlock.MaxBound)
CurBlock.ScriptOverflowed = CurBlock.StartPos + CurBlock.ScriptSize - CurBlock.MaxBound;
else
CurBlock.ScriptOverflowed = 0;
if (CurBlock.MaxBound != -1 && CurBlock.MaxBound > (CurBlock.StartPos + CurBlock.ScriptSize))
CurBlock.SpaceRemaining = CurBlock.MaxBound - (CurBlock.StartPos + CurBlock.ScriptSize);
else
CurBlock.SpaceRemaining = 0;
CurBlock.LineEnd = EndLine;
Stats.push_back(CurBlock);
CurBlock.ClearStats();
}
void StatisticsHandler::GenerateTotalStats(InsertionStatistics& Total)
{
if (Stats.empty())
{
ReportBug("Invalid size for statistics list in StatisticsHandler::GenerateTotalStats");
return;
}
else if (Stats.size() == 1)
{
Total = Stats.front();
return;
}
for (ListStatsIt i = Stats.begin(); i != Stats.end(); i++)
Total.AddStats(*i);
}