-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcounters.cpp
More file actions
246 lines (221 loc) · 8.28 KB
/
counters.cpp
File metadata and controls
246 lines (221 loc) · 8.28 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
__ __ ______ _______ _______ ______ ________
/ \ / | / \ / \ / \ / \ / |
$$ \ /$$ |/$$$$$$ |$$$$$$$ |$$$$$$$ |/$$$$$$ |$$$$$$$$/
$$$ \ /$$$ |$$ | $$/ $$ |__$$ |$$ |__$$ |$$ | $$ |$$ |__
$$$$ /$$$$ |$$ | $$ $$/ $$ $$< $$ | $$ |$$ |
$$ $$ $$/$$ |$$ | __ $$$$$$$/ $$$$$$$ |$$ | $$ |$$$$$/
$$ |$$$/ $$ |$$ \__/ |$$ | $$ | $$ |$$ \__$$ |$$ |
$$ | $/ $$ |$$ $$/ $$ | $$ | $$ |$$ $$/ $$ |
$$/ $$/ $$$$$$/ $$/ $$/ $$/ $$$$$$/ $$/
A Memory and Communication Profiler
* This file is a part of MCPROF.
* https://bitbucket.org/imranashraf/mcprof
*
* Copyright (c) 2014-2016 TU Delft, The Netherlands.
* All rights reserved.
*
* MCPROF is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MCPROF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MCPROF. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Imran Ashraf
*
*/
#include "globals.h"
#include "shadow.h"
#include "counters.h"
#include "commatrix.h"
#include "symbols.h"
#include "callstack.h"
map<IDNoType,u64> instrCounts;
map<IDNoType,u64> callCounts;
map<IDNoType,u64> funcReads;
map<IDNoType,u64> funcWrites;
map<IDNoType,u64> objReads;
map<IDNoType,u64> objWrites;
// AE/PE
map<IDNoType,double> objTotalACount;
map<IDNoType,double> objTotalPCount;
extern Symbols symTable;
extern bool ShowUnknown;
void PrintInstrCount()
{
map<IDNoType,u64>::iterator iter;
cout << setw(30) << "Function Name" << setw(12) << "# Instr." << endl;
for( iter = instrCounts.begin(); iter != instrCounts.end(); iter++ )
{
IDNoType fid = iter->first;
if(!ShowUnknown && fid==UnknownID)
continue;
else
{
u64 instrs = iter->second;
cout << setw(30) << symTable.GetSymName(fid) << setw(10) << instrs << endl;
}
}
cout << setw(30) << "Total" << setw(10) << TotalInstrCount() << endl;
}
void PrintInstrPercents()
{
ofstream fout;
string exefname("execProfile.dat");
ECHO("Printing flat execution profile in " << exefname);
OpenOutFile(exefname, fout);
multimap<u64, IDNoType> instrCountsSorted = flipMap(instrCounts);
multimap<u64,IDNoType>::reverse_iterator iter;
fout << setw(10) << "Total Calls " << setw(15) << "%Exec.Instr." << setw(16) << "Exec.Instr." << "\t\t" << "Name" << endl;
fout << " #==================================================================" <<endl;
for( iter = instrCountsSorted.rbegin(); iter != instrCountsSorted.rend(); ++iter )
{
IDNoType fid = iter->second;
if(!ShowUnknown && fid==UnknownID)
continue;
else
{
fout << setw(10) << GetCallCount(fid)
<< setw(15) << GetInstrCountPercent(fid)
<< setw(16) << GetInstrCount(fid)
<< "\t\t" << symTable.GetSymName(fid) << endl;
}
}
fout.close();
}
// The following prints the map without sorting
// void PrintInstrPercents()
// {
// ofstream fout;
// OpenOutFile("execProfile.dat", fout);
//
// map<IDNoType,u64>::iterator iter;
// fout << setw(45) << "Function Name" << setw(12) << "% Instr." << endl;
// for( iter = instrCounts.begin(); iter != instrCounts.end(); iter++ )
// {
// IDNoType fid = iter->first;
// if(!ShowUnknown && fid==UnknownID)
// continue;
// else
// {
// fout << setw(45) << symTable.GetSymName(fid) << setw(10) << GetInstrCountPercent(fid) << endl;
// }
// }
// fout.close();
// }
u64 TotalInstrCount()
{
map<IDNoType,u64>::iterator iter;
u64 total = 0;
for( iter = instrCounts.begin(); iter != instrCounts.end(); iter++)
{
IDNoType fid = iter->first;
if(!ShowUnknown && fid==UnknownID)
continue;
else
total += (iter->second);
}
return total;
}
u64 MaxInstrCount()
{
map<IDNoType,u64>::iterator iter;
u64 max = 0;
for( iter = instrCounts.begin(); iter != instrCounts.end(); iter++)
{
IDNoType fid = iter->first;
if(!ShowUnknown && fid==UnknownID)
continue;
else
{
if( max < (iter->second) )
max = iter->second;
}
}
return max;
}
u64 GetInstrCount(IDNoType fid)
{
return instrCounts[fid];
}
float GetInstrCountPercent(IDNoType fid)
{
u64 count = instrCounts[fid];
return floor( 100.0 * count / TotalInstrCount() );
}
u64 GetCallCount(IDNoType fid)
{
//TODO what if the entry for an fid does not exist?
return callCounts[fid];
}
void PrintMemAccesses()
{
ofstream fout;
string memfname("memProfile.dat");
OpenOutFile(memfname, fout);
ECHO("Printing flat memory access profile in " << memfname);
fout << " This table can be sorted by Total Accesses (-k2) by using bash command:"<<endl;
fout << " tail -n +7 memProfile.dat | sort -k2 -gr" <<endl<<endl;
fout << " Per Function Flat Memory Profile \n";
fout << setw(45) << " Function Name " << "\t ================= Accesses ========= Allocation" <<endl;
fout << setw(45) << " " << setw(14) << "Total" << setw(14) << "Reads" << setw(14) << "Writes "<< " Path" << endl;
fout << " ==========================================================================" <<endl;
map<IDNoType,u64>::iterator fiter;
for( fiter = funcReads.begin(); fiter != funcReads.end(); ++fiter)
{
auto fid = fiter->first;
auto freads = fiter->second;
auto fwrites = funcWrites[fid];
fout << setw(45) << symTable.GetSymName(fid)
<< setw(14) << freads + fwrites
<< setw(14) << freads
<< setw(14) << fwrites
<< " " << symTable.GetSymLocation(fid) << endl;
}
// AE/PE
fout << "\n\n";
fout << " Per Object Flat Memory Profile \n";
fout << setw(45) << " Object Name " << "\t =============== Accesses ============ ==== Efficiency ==== ==== Allocation" <<endl;
fout << setw(45) <<" " << setw(14) <<"Total" << setw(14) <<"Reads" << setw(14) <<"Writes " << setw(14) <<"Alloc %" << setw(14) <<"Prod %" << " Path" << endl;
fout << " ============================================================================================================" <<endl;
set<IDNoType> seenObjects;
map<IDNoType,u64>::iterator oiter;
for( oiter = objReads.begin(); oiter != objReads.end(); ++oiter)
{
auto oid = oiter->first;
seenObjects.insert(oid);
auto oreads = oiter->second;
auto owrites = objWrites[oid];
fout << setw(45) << symTable.GetSymName(oid)
<< setw(14) << oreads + owrites
<< setw(14) << oreads
<< setw(14) << owrites
<< setw(14) << objTotalACount[oid]/symTable.GetTotalSymSize(oid)*100
<< setw(14) << objTotalPCount[oid]/symTable.GetTotalSymSize(oid)*100
<< " " << symTable.GetSymLocation(oid) << endl;
}
for( oiter = objWrites.begin(); oiter != objWrites.end(); ++oiter)
{
auto oid = oiter->first;
if( seenObjects.find(oid) == seenObjects.end() )
{
auto oreads = oiter->second;
auto owrites = objWrites[oid];
fout << setw(45) << symTable.GetSymName(oid)
<< setw(14) << oreads + owrites
<< setw(14) << oreads
<< setw(14) << owrites
<< setw(14) << objTotalACount[oid]/symTable.GetTotalSymSize(oid)*100
<< setw(14) << objTotalPCount[oid]/symTable.GetTotalSymSize(oid)*100
<< " " << symTable.GetSymLocation(oid) << endl;
}
}
fout.close();
}