sl@0
|
1 |
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "analyse.h"
|
sl@0
|
17 |
#include "trace.h"
|
sl@0
|
18 |
#include "tracer.h"
|
sl@0
|
19 |
#include "distribution.h"
|
sl@0
|
20 |
#include "activity.h"
|
sl@0
|
21 |
#include "nonxip.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
#ifdef __MSVCDOTNET__
|
sl@0
|
24 |
#include <strstream>
|
sl@0
|
25 |
#include <iomanip>
|
sl@0
|
26 |
#else //!__MSVCDOTNET__
|
sl@0
|
27 |
#include <strstrea.h>
|
sl@0
|
28 |
#include <iomanip.h>
|
sl@0
|
29 |
#endif //__MSVCDOTNET__
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <ctype.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
Analyse::TAction Analyse::sAction;
|
sl@0
|
34 |
Analyse::TFormat Analyse::sFormat;
|
sl@0
|
35 |
Analyse::TPartition Analyse::sPartition;
|
sl@0
|
36 |
int Analyse::sOptions;
|
sl@0
|
37 |
std::vector<const char*> Analyse::sTraces;
|
sl@0
|
38 |
const char* Analyse::sRomFile;
|
sl@0
|
39 |
const char* Analyse::sThread;
|
sl@0
|
40 |
const char* Analyse::sDll;
|
sl@0
|
41 |
const char* Analyse::sFunction;
|
sl@0
|
42 |
unsigned Analyse::sBase;
|
sl@0
|
43 |
unsigned Analyse::sLim;
|
sl@0
|
44 |
unsigned Analyse::sBuckets = 100;
|
sl@0
|
45 |
unsigned Analyse::sBucketSize;
|
sl@0
|
46 |
double Analyse::sCutOff;
|
sl@0
|
47 |
unsigned Analyse::sBeginSample;
|
sl@0
|
48 |
unsigned Analyse::sEndSample = 0xffffffffu;
|
sl@0
|
49 |
|
sl@0
|
50 |
|
sl@0
|
51 |
NonXIP gNonXIP; //
|
sl@0
|
52 |
|
sl@0
|
53 |
//namespace {
|
sl@0
|
54 |
|
sl@0
|
55 |
void PartitionByDll::File(const char* aName)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iCurrentFile = aName;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
bool PartitionByDll::Symbol(const char*, PC aPc, int)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
bool is_added = false;
|
sl@0
|
63 |
if (iCurrentFile)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
if (iLastFile && Analyse::Match(iLastFile, iMatch))
|
sl@0
|
66 |
{
|
sl@0
|
67 |
Add(iLastFileAddress, aPc, iLastFile);
|
sl@0
|
68 |
is_added = true;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
iLastFile = iCurrentFile;
|
sl@0
|
71 |
iLastFileAddress = aPc;
|
sl@0
|
72 |
iCurrentFile = 0;
|
sl@0
|
73 |
}
|
sl@0
|
74 |
return is_added;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
|
sl@0
|
78 |
PartitionByFunction::PartitionByFunction(const char* aFile, const char* aFunction)
|
sl@0
|
79 |
:iFile(aFile), iFunction(aFunction), iActive(false)
|
sl@0
|
80 |
{}
|
sl@0
|
81 |
|
sl@0
|
82 |
void PartitionByFunction::File(const char* aName)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
iActive = Analyse::Match(aName, iFile);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
bool PartitionByFunction::Symbol(const char* aSymbol, PC aPc, int aLength)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
bool is_added = false;
|
sl@0
|
90 |
if (iActive && Analyse::Match(aSymbol, iFunction))
|
sl@0
|
91 |
{
|
sl@0
|
92 |
Add(aPc, aPc + aLength, aSymbol);
|
sl@0
|
93 |
is_added = true;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
return is_added;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
class FindFunction : public SymbolFile::Parser
|
sl@0
|
101 |
{
|
sl@0
|
102 |
public:
|
sl@0
|
103 |
FindFunction(const char* aFile, const char* aFunction);
|
sl@0
|
104 |
void File(const char* aName);
|
sl@0
|
105 |
bool Symbol(const char* aName, PC aPc, int aLength);
|
sl@0
|
106 |
void Done(PC aFirstPc=0, PC aLastPc=0, int aModuleId=0);
|
sl@0
|
107 |
private:
|
sl@0
|
108 |
const char* iFile;
|
sl@0
|
109 |
const char* iFunction;
|
sl@0
|
110 |
bool iActive;
|
sl@0
|
111 |
public:
|
sl@0
|
112 |
PC iPc;
|
sl@0
|
113 |
int iLength;
|
sl@0
|
114 |
};
|
sl@0
|
115 |
|
sl@0
|
116 |
FindFunction::FindFunction(const char* aFile, const char* aFunction)
|
sl@0
|
117 |
:iFile(aFile), iFunction(aFunction), iActive(false), iPc(0)
|
sl@0
|
118 |
{}
|
sl@0
|
119 |
|
sl@0
|
120 |
void FindFunction::File(const char* aName)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
if (iPc == 0)
|
sl@0
|
123 |
iActive = Analyse::Match(aName, iFile);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
bool FindFunction::Symbol(const char* aSymbol, PC aPc, int aLength)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
bool is_added = false;
|
sl@0
|
129 |
if (iPc == 0 && iActive && Analyse::Match(aSymbol, iFunction))
|
sl@0
|
130 |
{
|
sl@0
|
131 |
iPc = aPc;
|
sl@0
|
132 |
iLength = aLength;
|
sl@0
|
133 |
is_added = true;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
return is_added;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
void FindFunction::Done(PC aFirstPc, PC aLastPc, int aModuleId)
|
sl@0
|
139 |
{}
|
sl@0
|
140 |
|
sl@0
|
141 |
//}; // local namepsace
|
sl@0
|
142 |
|
sl@0
|
143 |
|
sl@0
|
144 |
// entry point
|
sl@0
|
145 |
|
sl@0
|
146 |
int main(int argc,char *argv[])
|
sl@0
|
147 |
{
|
sl@0
|
148 |
switch(Analyse::ProcessCommandLine(argc,argv))
|
sl@0
|
149 |
{
|
sl@0
|
150 |
case 1:
|
sl@0
|
151 |
Analyse::ExplainUsage();
|
sl@0
|
152 |
return 1;
|
sl@0
|
153 |
case 2:
|
sl@0
|
154 |
Analyse::ExplainConfigUsage();
|
sl@0
|
155 |
return 1;
|
sl@0
|
156 |
}
|
sl@0
|
157 |
Analyse::Run();
|
sl@0
|
158 |
return 0;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
// Class Analyse
|
sl@0
|
162 |
|
sl@0
|
163 |
void Analyse::Information()
|
sl@0
|
164 |
{
|
sl@0
|
165 |
cout << "\nEPOC Profile Analyser Version " << MajorVersion << '.' \
|
sl@0
|
166 |
<< setw(2) << MinorVersion << "(build " << setw(3) << setfill('0') << Build \
|
sl@0
|
167 |
<< ")\nCopyright (c) Symbian Limited 2000. All rights reserved.\n\n" << flush;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
void Analyse::ExplainUsage()
|
sl@0
|
171 |
{
|
sl@0
|
172 |
Information();
|
sl@0
|
173 |
cout << "Usage: Analyse [options] tracefile\n" \
|
sl@0
|
174 |
" -h display this information\n" \
|
sl@0
|
175 |
" -l generate a trace listing\n" \
|
sl@0
|
176 |
" -p generate a profile distribution\n" \
|
sl@0
|
177 |
" -v generate a activity trace\n" \
|
sl@0
|
178 |
" -r <symbols> supply a Rom symbol file\n" \
|
sl@0
|
179 |
" -s<range> restrict the profile to the samples specified\n" \
|
sl@0
|
180 |
" This is specified either as <start>-<end> or\n" \
|
sl@0
|
181 |
" as <start>+<length> in decimal\n" \
|
sl@0
|
182 |
" -n include NULL thread\n" \
|
sl@0
|
183 |
" -t <thread> profile threads matching the pattern\n" \
|
sl@0
|
184 |
" -d <dll> profile DLL (or EXE) matching the pattern\n" \
|
sl@0
|
185 |
" -f <function> profile the function matching the pattern\n" \
|
sl@0
|
186 |
" -a<range> profile the address range specified\n" \
|
sl@0
|
187 |
" This is specified either as <start>-<end> or\n" \
|
sl@0
|
188 |
" as <start>+<length> in hexadecimal\n" \
|
sl@0
|
189 |
" -bd partition the profile by dll/exe\n" \
|
sl@0
|
190 |
" -bf partition the profile by function\n" \
|
sl@0
|
191 |
" -bs<n> partition the profile into buckets of size n\n" \
|
sl@0
|
192 |
" -bn<n> partition the profile into approx. n buckets\n" \
|
sl@0
|
193 |
" -c<n> set the cutoff value for discarding output\n" \
|
sl@0
|
194 |
" -m... setformat options:\n" \
|
sl@0
|
195 |
" p|s|x use percentages/samples/excel for output\n" \
|
sl@0
|
196 |
" z output zero values instead of blanks\n" \
|
sl@0
|
197 |
" t do not show thread break-down\n" \
|
sl@0
|
198 |
" o do not include the <other> bucket\n" \
|
sl@0
|
199 |
" -z <rofs> supply a ROFS symbol file\n" \
|
sl@0
|
200 |
" -o <oby> supply an OBY file\n" \
|
sl@0
|
201 |
" -x <config> supply a config file\n" \
|
sl@0
|
202 |
" -h config display an example of config file\n" \
|
sl@0
|
203 |
<< flush;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
void Analyse::ExplainConfigUsage()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
Information();
|
sl@0
|
209 |
cout << "Example of config file:" << endl << endl;
|
sl@0
|
210 |
cout << "[Common]" << endl;
|
sl@0
|
211 |
cout << "TraceFile=PROFILER.DAT" << endl;
|
sl@0
|
212 |
cout << "Mode=listing|profile|activity" << endl;
|
sl@0
|
213 |
cout << "SymbolFile=core4r.bin.symbol" << endl;
|
sl@0
|
214 |
cout << "Range=100-200 | 100+100" << endl;
|
sl@0
|
215 |
cout << "IncludeNullThread=0|1" << endl;
|
sl@0
|
216 |
cout << "[Profile]" << endl;
|
sl@0
|
217 |
cout << "Thread=" << endl;
|
sl@0
|
218 |
cout << "Dll=" << endl;
|
sl@0
|
219 |
cout << "Function=" << endl;
|
sl@0
|
220 |
cout << "Range=1f1a+20 | 1f1a-1f3a" << endl;
|
sl@0
|
221 |
cout << "[Partition]" << endl;
|
sl@0
|
222 |
cout << "Mode=dll|function" << endl;
|
sl@0
|
223 |
cout << "BucketSize=" << endl;
|
sl@0
|
224 |
cout << "NumberOfBuckets=" << endl;
|
sl@0
|
225 |
cout << "[Format]" << endl;
|
sl@0
|
226 |
cout << "Mode=percentages|samples|excel" << endl;
|
sl@0
|
227 |
cout << "ZeroValues=0|1" << endl;
|
sl@0
|
228 |
cout << "NoOthers=0|1" << endl;
|
sl@0
|
229 |
cout << "TotalOnly=0|1" << endl;
|
sl@0
|
230 |
cout << "[NonXIP]" << endl;
|
sl@0
|
231 |
cout << "ObyFile1=myrofs.oby" << endl;
|
sl@0
|
232 |
cout << "RofsSymbolFile1=rofs.bin.symbol" << endl;
|
sl@0
|
233 |
cout << flush;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
class Options
|
sl@0
|
237 |
{
|
sl@0
|
238 |
struct Entry
|
sl@0
|
239 |
{
|
sl@0
|
240 |
const char* iName;
|
sl@0
|
241 |
int iOption;
|
sl@0
|
242 |
};
|
sl@0
|
243 |
const static Entry KOptions[];
|
sl@0
|
244 |
static int Compare(const char* aLhs, const char* aRhs);
|
sl@0
|
245 |
public:
|
sl@0
|
246 |
static int Get(istrstream& aStr);
|
sl@0
|
247 |
};
|
sl@0
|
248 |
|
sl@0
|
249 |
|
sl@0
|
250 |
const Options::Entry Options::KOptions[] =
|
sl@0
|
251 |
{
|
sl@0
|
252 |
{"activity",'v'},
|
sl@0
|
253 |
{"address", 'a'},
|
sl@0
|
254 |
{"by", 'b'},
|
sl@0
|
255 |
{"cutoff", 'c'},
|
sl@0
|
256 |
{"dll", 'd'},
|
sl@0
|
257 |
{"excel", 'x'},
|
sl@0
|
258 |
{"format", 'm'},
|
sl@0
|
259 |
{"function",'f'},
|
sl@0
|
260 |
{"help", 'h'},
|
sl@0
|
261 |
{"listing", 'l'},
|
sl@0
|
262 |
{"null", 'n'},
|
sl@0
|
263 |
{"number", 'n'},
|
sl@0
|
264 |
{"other", 'o'},
|
sl@0
|
265 |
{"percent", 'p'},
|
sl@0
|
266 |
{"profile", 'p'},
|
sl@0
|
267 |
{"rom", 'r'},
|
sl@0
|
268 |
{"samples", 's'},
|
sl@0
|
269 |
{"size", 's'},
|
sl@0
|
270 |
{"thread", 't'},
|
sl@0
|
271 |
{"total", 't'},
|
sl@0
|
272 |
{"zero", 'z'},
|
sl@0
|
273 |
{"oby", 'o'},
|
sl@0
|
274 |
{"rofs", 'z'},
|
sl@0
|
275 |
{"config", 'x'},
|
sl@0
|
276 |
};
|
sl@0
|
277 |
|
sl@0
|
278 |
inline int min(int a, int b)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
return a < b ? a : b;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
int Options::Compare(const char* aLhs, const char* aRhs)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
int len = min(strlen(aLhs), strlen(aRhs));
|
sl@0
|
286 |
return strnicmp(aLhs, aRhs, len);
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
int Options::Get(istrstream& aStr)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
int pos = aStr.tellg();
|
sl@0
|
292 |
const char* s = aStr.str() + pos;
|
sl@0
|
293 |
|
sl@0
|
294 |
if (strlen(s) >= 3)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
int l = 0, r = sizeof(KOptions)/sizeof(KOptions[0]);
|
sl@0
|
297 |
do
|
sl@0
|
298 |
{
|
sl@0
|
299 |
int m = (l + r ) >> 1;
|
sl@0
|
300 |
const Entry& e = KOptions[m];
|
sl@0
|
301 |
int k = Compare(s, e.iName);
|
sl@0
|
302 |
if (k < 0)
|
sl@0
|
303 |
r = m;
|
sl@0
|
304 |
else if (k > 0)
|
sl@0
|
305 |
l = m + 1;
|
sl@0
|
306 |
else
|
sl@0
|
307 |
{
|
sl@0
|
308 |
// found a match
|
sl@0
|
309 |
aStr.ignore(strlen(e.iName));
|
sl@0
|
310 |
return e.iOption;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
} while (l < r);
|
sl@0
|
313 |
}
|
sl@0
|
314 |
// no match
|
sl@0
|
315 |
return aStr.get();
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
int Analyse::ProcessCommandLine(int argc, char ** argv)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
int initial_argc = argc;
|
sl@0
|
321 |
char ** initial_argv = argv;
|
sl@0
|
322 |
// added 2-nd pass. on the 1-st just look for config file
|
sl@0
|
323 |
for(int pass = 0;pass < 2;pass++)
|
sl@0
|
324 |
{
|
sl@0
|
325 |
argc = initial_argc;
|
sl@0
|
326 |
argv = initial_argv;
|
sl@0
|
327 |
while (--argc>0)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
istrstream arg(*++argv);
|
sl@0
|
330 |
int c = arg.get();
|
sl@0
|
331 |
if (c != '/' && c != '-')
|
sl@0
|
332 |
{
|
sl@0
|
333 |
if (pass == 0) continue;
|
sl@0
|
334 |
sTraces.clear();
|
sl@0
|
335 |
sTraces.push_back(arg.str());
|
sl@0
|
336 |
continue;
|
sl@0
|
337 |
}
|
sl@0
|
338 |
c = Options::Get(arg);
|
sl@0
|
339 |
if (tolower(c) != 'x' && pass == 0)
|
sl@0
|
340 |
continue;
|
sl@0
|
341 |
switch (c)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
case 'h': case 'H': case '?':
|
sl@0
|
344 |
if (--argc > 0 && !stricmp(*++argv,"config"))
|
sl@0
|
345 |
return 2;
|
sl@0
|
346 |
return 1;
|
sl@0
|
347 |
case 'l': case 'L':
|
sl@0
|
348 |
sAction = ETrace;
|
sl@0
|
349 |
break;
|
sl@0
|
350 |
case 'p': case 'P':
|
sl@0
|
351 |
sAction = EProfile;
|
sl@0
|
352 |
break;
|
sl@0
|
353 |
case 'v': case 'V':
|
sl@0
|
354 |
sAction = EActivity;
|
sl@0
|
355 |
break;
|
sl@0
|
356 |
case 'r': case 'R':
|
sl@0
|
357 |
if (--argc == 0)
|
sl@0
|
358 |
Abort("No symbol file specified for option '-r'");
|
sl@0
|
359 |
sRomFile = *++argv;
|
sl@0
|
360 |
break;
|
sl@0
|
361 |
case 's': case 'S':
|
sl@0
|
362 |
sOptions |= ERange;
|
sl@0
|
363 |
arg >> sBeginSample;
|
sl@0
|
364 |
c = arg.get();
|
sl@0
|
365 |
arg >> sEndSample;
|
sl@0
|
366 |
if (c == '+')
|
sl@0
|
367 |
sEndSample += sBeginSample;
|
sl@0
|
368 |
else if (c != '-')
|
sl@0
|
369 |
return 1;
|
sl@0
|
370 |
break;
|
sl@0
|
371 |
case 'n': case 'N':
|
sl@0
|
372 |
sOptions|=ENull;
|
sl@0
|
373 |
break;
|
sl@0
|
374 |
case 't': case 'T':
|
sl@0
|
375 |
if (--argc == 0)
|
sl@0
|
376 |
Abort("No thread name specified for option '-t'");
|
sl@0
|
377 |
sThread = *++argv;
|
sl@0
|
378 |
break;
|
sl@0
|
379 |
case 'd': case 'D':
|
sl@0
|
380 |
if (--argc == 0)
|
sl@0
|
381 |
Abort("No DLL name specified for option '-d'");
|
sl@0
|
382 |
sDll = *++argv;
|
sl@0
|
383 |
break;
|
sl@0
|
384 |
case 'f': case 'F':
|
sl@0
|
385 |
if (--argc == 0)
|
sl@0
|
386 |
Abort("No function name specified for option '-f'");
|
sl@0
|
387 |
sFunction = *++argv;
|
sl@0
|
388 |
break;
|
sl@0
|
389 |
case 'a': case 'A':
|
sl@0
|
390 |
sOptions |= EAddress;
|
sl@0
|
391 |
arg >> hex >> sBase;
|
sl@0
|
392 |
c = arg.get();
|
sl@0
|
393 |
arg >> hex >> sLim;
|
sl@0
|
394 |
if (c == '+')
|
sl@0
|
395 |
sLim += sBase;
|
sl@0
|
396 |
else if (c != '-')
|
sl@0
|
397 |
return 1;
|
sl@0
|
398 |
break;
|
sl@0
|
399 |
case 'b': case 'B':
|
sl@0
|
400 |
switch (c = Options::Get(arg))
|
sl@0
|
401 |
{
|
sl@0
|
402 |
case 'd': case 'D':
|
sl@0
|
403 |
sPartition = EDll;
|
sl@0
|
404 |
break;
|
sl@0
|
405 |
case 'f': case 'F':
|
sl@0
|
406 |
sPartition = EFunction;
|
sl@0
|
407 |
break;
|
sl@0
|
408 |
case 'n': case 'N':
|
sl@0
|
409 |
sPartition = EBuckets;
|
sl@0
|
410 |
arg >> dec >> sBuckets;
|
sl@0
|
411 |
break;
|
sl@0
|
412 |
case 's': case 'S':
|
sl@0
|
413 |
sPartition = ESize;
|
sl@0
|
414 |
arg >> dec >> sBucketSize;
|
sl@0
|
415 |
break;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
break;
|
sl@0
|
418 |
case 'c': case 'C':
|
sl@0
|
419 |
arg >> sCutOff;
|
sl@0
|
420 |
break;
|
sl@0
|
421 |
case 'm': case 'M':
|
sl@0
|
422 |
while ((c = Options::Get(arg)) != EOF)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
switch (c)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
case 'p': case 'P':
|
sl@0
|
427 |
sFormat = EPercent;
|
sl@0
|
428 |
break;
|
sl@0
|
429 |
case 's': case 'S':
|
sl@0
|
430 |
sFormat = ESamples;
|
sl@0
|
431 |
break;
|
sl@0
|
432 |
case 'x': case 'X':
|
sl@0
|
433 |
sFormat = EExcel;
|
sl@0
|
434 |
break;
|
sl@0
|
435 |
case 'z': case 'Z':
|
sl@0
|
436 |
sOptions |= EZeros;
|
sl@0
|
437 |
break;
|
sl@0
|
438 |
case 'o': case 'O':
|
sl@0
|
439 |
sOptions |= ENoOther;
|
sl@0
|
440 |
break;
|
sl@0
|
441 |
case 't': case 'T':
|
sl@0
|
442 |
sOptions |= ETotalOnly;
|
sl@0
|
443 |
break;
|
sl@0
|
444 |
default:
|
sl@0
|
445 |
arg.putback(c);
|
sl@0
|
446 |
break;
|
sl@0
|
447 |
}
|
sl@0
|
448 |
}
|
sl@0
|
449 |
break;
|
sl@0
|
450 |
case 'o': case 'O':
|
sl@0
|
451 |
if (--argc == 0)
|
sl@0
|
452 |
Abort("No OBY file name specified for option '-o'");
|
sl@0
|
453 |
gNonXIP.AddObyFile(*++argv);
|
sl@0
|
454 |
break;
|
sl@0
|
455 |
case 'z': case 'Z':
|
sl@0
|
456 |
if (--argc == 0)
|
sl@0
|
457 |
Abort("No ROFS symbol file name specified for option '-z'");
|
sl@0
|
458 |
gNonXIP.AddSymbolFile(*++argv);
|
sl@0
|
459 |
break;
|
sl@0
|
460 |
case 'x': case 'X':
|
sl@0
|
461 |
if (--argc == 0)
|
sl@0
|
462 |
Abort("No config file name specified for option '-x'");
|
sl@0
|
463 |
if (pass == 0)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
switch(ProcessCfgFile(*++argv))
|
sl@0
|
466 |
{
|
sl@0
|
467 |
case ENoCfgFile:
|
sl@0
|
468 |
Abort("Error no config file name specified for option '-x'");
|
sl@0
|
469 |
case EErrorCfgFile:
|
sl@0
|
470 |
Abort("Error in config file");
|
sl@0
|
471 |
}
|
sl@0
|
472 |
}
|
sl@0
|
473 |
else
|
sl@0
|
474 |
++argv;
|
sl@0
|
475 |
break;
|
sl@0
|
476 |
default: // unrecognised option
|
sl@0
|
477 |
arg.putback(c);
|
sl@0
|
478 |
break;
|
sl@0
|
479 |
}
|
sl@0
|
480 |
if (!arg || arg.get() != EOF)
|
sl@0
|
481 |
{
|
sl@0
|
482 |
cerr << "Unrecognised option \'" << arg.str() << '\'' << endl;
|
sl@0
|
483 |
Abort();
|
sl@0
|
484 |
}
|
sl@0
|
485 |
} // while
|
sl@0
|
486 |
} // for(pass)
|
sl@0
|
487 |
if (sTraces.empty())
|
sl@0
|
488 |
Abort("No trace files specified");
|
sl@0
|
489 |
return sTraces.size() != 1;
|
sl@0
|
490 |
}
|
sl@0
|
491 |
|
sl@0
|
492 |
CodeSpace* Analyse::CreateCodeSpace(SymbolFile* aSymbols, NonXIP *aNonXIP)
|
sl@0
|
493 |
{
|
sl@0
|
494 |
if (Option(EAddress))
|
sl@0
|
495 |
{
|
sl@0
|
496 |
unsigned size;
|
sl@0
|
497 |
if (Partition() == ESize)
|
sl@0
|
498 |
size = sBucketSize;
|
sl@0
|
499 |
else
|
sl@0
|
500 |
size = (sLim - sBase) / sBuckets;
|
sl@0
|
501 |
return new AddressCodeSpace(sBase, sLim, size, AddressCodeSpace::EAbsolute);
|
sl@0
|
502 |
}
|
sl@0
|
503 |
|
sl@0
|
504 |
MappedCodeSpace * mapped_code_space = 0;
|
sl@0
|
505 |
if (aSymbols == 0)
|
sl@0
|
506 |
{
|
sl@0
|
507 |
MappedCodeSpace* mapped_code_space = new MappedCodeSpace();
|
sl@0
|
508 |
if (aNonXIP)
|
sl@0
|
509 |
aNonXIP->SetMappedCodeSpace(mapped_code_space);
|
sl@0
|
510 |
return mapped_code_space;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
for (;;)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
switch (Partition())
|
sl@0
|
516 |
{
|
sl@0
|
517 |
case EDefault:
|
sl@0
|
518 |
if (sFunction != 0)
|
sl@0
|
519 |
{
|
sl@0
|
520 |
sPartition = ESize;
|
sl@0
|
521 |
sBucketSize = 4;
|
sl@0
|
522 |
}
|
sl@0
|
523 |
else if (sDll != 0)
|
sl@0
|
524 |
sPartition = EFunction;
|
sl@0
|
525 |
else
|
sl@0
|
526 |
sPartition = EDll;
|
sl@0
|
527 |
break;
|
sl@0
|
528 |
case EDll:
|
sl@0
|
529 |
{
|
sl@0
|
530 |
PartitionByDll p(sDll);
|
sl@0
|
531 |
mapped_code_space = new MappedCodeSpace(*aSymbols,p);
|
sl@0
|
532 |
if (aNonXIP)
|
sl@0
|
533 |
aNonXIP->SetMappedCodeSpace(mapped_code_space);
|
sl@0
|
534 |
return mapped_code_space;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
case EFunction:
|
sl@0
|
537 |
{
|
sl@0
|
538 |
PartitionByFunction p(sDll, sFunction);
|
sl@0
|
539 |
mapped_code_space = new MappedCodeSpace(*aSymbols,p);
|
sl@0
|
540 |
if (aNonXIP)
|
sl@0
|
541 |
aNonXIP->SetMappedCodeSpace(mapped_code_space);
|
sl@0
|
542 |
return mapped_code_space;
|
sl@0
|
543 |
}
|
sl@0
|
544 |
case ESize:
|
sl@0
|
545 |
case EBuckets:
|
sl@0
|
546 |
if (sFunction == 0)
|
sl@0
|
547 |
sPartition = EFunction;
|
sl@0
|
548 |
else
|
sl@0
|
549 |
{
|
sl@0
|
550 |
FindFunction f(sDll, sFunction);
|
sl@0
|
551 |
aSymbols->Parse(f);
|
sl@0
|
552 |
if (f.iPc == 0)
|
sl@0
|
553 |
{
|
sl@0
|
554 |
cerr << "Cannot find function '" << sFunction << '\'';
|
sl@0
|
555 |
if (sDll)
|
sl@0
|
556 |
cerr << " in '" << sDll << '\'';
|
sl@0
|
557 |
cerr << endl;
|
sl@0
|
558 |
Abort();
|
sl@0
|
559 |
}
|
sl@0
|
560 |
unsigned size = (Partition() == ESize) ? sBucketSize : f.iLength / sBuckets;
|
sl@0
|
561 |
return new AddressCodeSpace(f.iPc, f.iPc + f.iLength, size, AddressCodeSpace::ERelative);
|
sl@0
|
562 |
}
|
sl@0
|
563 |
break;
|
sl@0
|
564 |
}
|
sl@0
|
565 |
}
|
sl@0
|
566 |
}
|
sl@0
|
567 |
|
sl@0
|
568 |
Sampler* Analyse::CreateSampler(SymbolFile* aSymbols, NonXIP *aNonXIP)
|
sl@0
|
569 |
{
|
sl@0
|
570 |
switch (Action())
|
sl@0
|
571 |
{
|
sl@0
|
572 |
case ETrace:
|
sl@0
|
573 |
{
|
sl@0
|
574 |
MappedCodeSpace * mapped_code_space = 0;
|
sl@0
|
575 |
if (aSymbols == 0)
|
sl@0
|
576 |
//return new Tracer(0);
|
sl@0
|
577 |
mapped_code_space = new MappedCodeSpace();
|
sl@0
|
578 |
else
|
sl@0
|
579 |
{
|
sl@0
|
580 |
PartitionByFunction p(0, 0);
|
sl@0
|
581 |
mapped_code_space = new MappedCodeSpace(*aSymbols,p);
|
sl@0
|
582 |
}
|
sl@0
|
583 |
if (aNonXIP) aNonXIP->SetMappedCodeSpace(mapped_code_space);
|
sl@0
|
584 |
return new Tracer(mapped_code_space);
|
sl@0
|
585 |
}
|
sl@0
|
586 |
case EProfile:
|
sl@0
|
587 |
{
|
sl@0
|
588 |
CodeSpace * code_space = CreateCodeSpace(aSymbols, aNonXIP);
|
sl@0
|
589 |
return new Distribution(*code_space, sCutOff);
|
sl@0
|
590 |
}
|
sl@0
|
591 |
case EActivity:
|
sl@0
|
592 |
return new Activity(Partition() == ESize ? sBucketSize : 100, sBeginSample, sCutOff);
|
sl@0
|
593 |
}
|
sl@0
|
594 |
return 0;
|
sl@0
|
595 |
}
|
sl@0
|
596 |
|
sl@0
|
597 |
void Analyse::Run()
|
sl@0
|
598 |
//
|
sl@0
|
599 |
// The main part of the program
|
sl@0
|
600 |
//
|
sl@0
|
601 |
{
|
sl@0
|
602 |
Information();
|
sl@0
|
603 |
Trace trace;
|
sl@0
|
604 |
trace.Load(sTraces[0], sBeginSample, sEndSample);
|
sl@0
|
605 |
// create map of original/segment names
|
sl@0
|
606 |
gNonXIP.CreateNamesMap();
|
sl@0
|
607 |
|
sl@0
|
608 |
SymbolFile* symbols = 0;
|
sl@0
|
609 |
if (sRomFile)
|
sl@0
|
610 |
symbols = new SymbolFile(sRomFile);
|
sl@0
|
611 |
Sampler* sampler = CreateSampler(symbols, &gNonXIP);
|
sl@0
|
612 |
trace.Decode(*sampler, &gNonXIP);
|
sl@0
|
613 |
|
sl@0
|
614 |
// NonXIP footer messages
|
sl@0
|
615 |
cout << endl << "Row buffer errors:" << gNonXIP.iRowBufferErrors;
|
sl@0
|
616 |
cout << " Cook buffer errors:" << gNonXIP.iCookBufferErrors;
|
sl@0
|
617 |
cout << " Mode:";
|
sl@0
|
618 |
if (gNonXIP.iReportMask & NonXIP::ENonXip)
|
sl@0
|
619 |
cout << "NonXIP";
|
sl@0
|
620 |
else
|
sl@0
|
621 |
cout << "XIP only";
|
sl@0
|
622 |
if (gNonXIP.iReportMask & NonXIP::ENodebugSupport)
|
sl@0
|
623 |
cout << " No debug support from Kernel";
|
sl@0
|
624 |
|
sl@0
|
625 |
cout << endl;
|
sl@0
|
626 |
|
sl@0
|
627 |
cout << flush;
|
sl@0
|
628 |
}
|
sl@0
|
629 |
|
sl@0
|
630 |
bool Analyse::Match(const char* aString, const char* aMatch)
|
sl@0
|
631 |
//
|
sl@0
|
632 |
// Wildcard matching
|
sl@0
|
633 |
// If match string is 0, then matches everything
|
sl@0
|
634 |
//
|
sl@0
|
635 |
{
|
sl@0
|
636 |
if (aMatch == 0)
|
sl@0
|
637 |
return true;
|
sl@0
|
638 |
|
sl@0
|
639 |
const char* star = strchr(aMatch, '*');
|
sl@0
|
640 |
if (star == 0)
|
sl@0
|
641 |
return (stricmp(aString, aMatch) == 0);
|
sl@0
|
642 |
|
sl@0
|
643 |
int mlen = star - aMatch;
|
sl@0
|
644 |
if (strnicmp(aString, aMatch, mlen) != 0)
|
sl@0
|
645 |
return false;
|
sl@0
|
646 |
|
sl@0
|
647 |
const char* end = aString + strlen(aString);
|
sl@0
|
648 |
|
sl@0
|
649 |
for (;;)
|
sl@0
|
650 |
{
|
sl@0
|
651 |
aString += mlen;
|
sl@0
|
652 |
aMatch += mlen + 1;
|
sl@0
|
653 |
star = strchr(aMatch, '*');
|
sl@0
|
654 |
if (star == 0)
|
sl@0
|
655 |
return (stricmp(end - strlen(aMatch), aMatch) == 0);
|
sl@0
|
656 |
mlen = star - aMatch;
|
sl@0
|
657 |
const char* lim = end - mlen;
|
sl@0
|
658 |
for (;;)
|
sl@0
|
659 |
{
|
sl@0
|
660 |
if (aString > lim)
|
sl@0
|
661 |
return false;
|
sl@0
|
662 |
if (strnicmp(aString, aMatch, mlen) == 0)
|
sl@0
|
663 |
break;
|
sl@0
|
664 |
++aString;
|
sl@0
|
665 |
}
|
sl@0
|
666 |
}
|
sl@0
|
667 |
}
|
sl@0
|
668 |
|
sl@0
|
669 |
void Analyse::Abort(char const* aMessage)
|
sl@0
|
670 |
{
|
sl@0
|
671 |
cerr << aMessage << endl;
|
sl@0
|
672 |
Abort();
|
sl@0
|
673 |
}
|
sl@0
|
674 |
|
sl@0
|
675 |
void Analyse::Abort()
|
sl@0
|
676 |
{
|
sl@0
|
677 |
exit(3);
|
sl@0
|
678 |
}
|
sl@0
|
679 |
|
sl@0
|
680 |
void Analyse::Corrupt(char const* aMessage)
|
sl@0
|
681 |
//
|
sl@0
|
682 |
// terminate after detecting a fatal corruption error
|
sl@0
|
683 |
//
|
sl@0
|
684 |
{
|
sl@0
|
685 |
cerr << "\nfatal error: " << aMessage << "\ncannot continue\n" << flush;
|
sl@0
|
686 |
exit(2);
|
sl@0
|
687 |
}
|
sl@0
|
688 |
|
sl@0
|
689 |
ostream& Analyse::Error()
|
sl@0
|
690 |
{
|
sl@0
|
691 |
return cerr << "error: ";
|
sl@0
|
692 |
}
|
sl@0
|
693 |
|
sl@0
|
694 |
ostream& Analyse::Warning()
|
sl@0
|
695 |
{
|
sl@0
|
696 |
return cerr << "warning: ";
|
sl@0
|
697 |
}
|
sl@0
|
698 |
|