51
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Definitions for the class CATParseTraceFile.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "../inc/ATCommonDefines.h"
|
|
20 |
#include "../inc/CATParseTraceFile.h"
|
|
21 |
#include "../inc/catdatasaver.h"
|
|
22 |
#include "../inc/CATDatParser.h"
|
|
23 |
#include "../inc/CATProcessData.h"
|
|
24 |
|
|
25 |
#include <time.h>
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// CATParseTraceFile::CATParseTraceFile
|
|
31 |
// Constructor.
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
CATParseTraceFile::CATParseTraceFile()
|
|
34 |
{
|
|
35 |
LOG_FUNC_ENTRY("CATParseTraceFile::CATParseTraceFile");
|
|
36 |
m_DataSaver.SetPrintFlag( false );
|
|
37 |
}
|
|
38 |
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
// CATParseTraceFile::StartParse
|
|
41 |
// Main function to start trace parsing.
|
|
42 |
// -----------------------------------------------------------------------------
|
|
43 |
bool CATParseTraceFile::StartParse( const char* pFileName, const char* pOutputFileName, const char* pCleanedTraceFile )
|
|
44 |
{
|
|
45 |
LOG_FUNC_ENTRY("CATParseTraceFile::StartParse");
|
|
46 |
|
|
47 |
// Return value, will be changed to true if process start found.
|
|
48 |
bool bRet = false;
|
|
49 |
bool bCreateCleanedTraces = false;
|
|
50 |
|
|
51 |
// Check pointers
|
|
52 |
if ( pFileName == NULL )
|
|
53 |
return bRet;
|
|
54 |
|
|
55 |
if( pOutputFileName == NULL )
|
|
56 |
return bRet;
|
|
57 |
|
|
58 |
if ( ! FileExists( pFileName ) )
|
|
59 |
{
|
|
60 |
cout << AT_MSG << "Error, input file \""
|
|
61 |
<< pFileName
|
|
62 |
<< "\" does not exist." << endl;
|
|
63 |
return bRet;
|
|
64 |
}
|
|
65 |
|
|
66 |
ofstream cleanedTraces;
|
|
67 |
|
|
68 |
// check is creation of file needed
|
|
69 |
if( pCleanedTraceFile != NULL )
|
|
70 |
{
|
|
71 |
// if yes open file for cleaned traces
|
|
72 |
// (<AT> messages with cleaned timestamps)
|
|
73 |
bCreateCleanedTraces = true;
|
|
74 |
|
|
75 |
cleanedTraces.open(pCleanedTraceFile);
|
|
76 |
|
|
77 |
if( !cleanedTraces.good() )
|
|
78 |
{
|
|
79 |
printf( "Can not open file: %s\n", pCleanedTraceFile );
|
|
80 |
return bRet;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
// Open data file
|
52
|
85 |
ifstream in( pFileName, ios::binary );
|
51
|
86 |
|
|
87 |
// Check file opened ok
|
|
88 |
if ( !in.good() )
|
|
89 |
return false;
|
|
90 |
|
|
91 |
// Get stream size
|
|
92 |
size_t streamPos = in.tellg();
|
|
93 |
in.seekg( 0, ios::end);
|
|
94 |
size_t streamEnd = in.tellg();
|
|
95 |
in.seekg( 0, ios::beg);
|
|
96 |
|
|
97 |
//Origianl characters (not filtered).
|
|
98 |
char cOriginalLineFromFile[MAX_LINE_LENGTH];
|
|
99 |
|
|
100 |
vector<CProcessData> vProcessList;
|
|
101 |
int iProcessIDinList = -1;
|
|
102 |
|
|
103 |
bool bFileVersionSaved = false;
|
|
104 |
// Read lines
|
|
105 |
while( streamPos < streamEnd )
|
|
106 |
{
|
|
107 |
// Get one line. Don't use stream flags to determinate end of file
|
|
108 |
// it can be found too early because trace can contain "anything".
|
|
109 |
in.getline( cOriginalLineFromFile, MAX_LINE_LENGTH );
|
|
110 |
|
|
111 |
// Refresh position
|
|
112 |
streamPos = in.tellg();
|
|
113 |
|
|
114 |
// Check has bad bit flag raised. (i.e. device problems reading data)
|
|
115 |
if( in.bad() )
|
|
116 |
{
|
|
117 |
cout << AT_MSG << "Integrity error reading the trace file, reading aborted." << endl;
|
|
118 |
return false;
|
|
119 |
}
|
|
120 |
//Filtered characters.
|
|
121 |
char cLineFromFile[MAX_LINE_LENGTH];
|
|
122 |
char* pFiltered = cLineFromFile;
|
|
123 |
|
|
124 |
//Loop thru all characters in original line.
|
|
125 |
for( size_t i = 0 ; cOriginalLineFromFile[i] != 0 ; i++ )
|
|
126 |
{
|
|
127 |
//If character in line is not in invalid character array append it
|
|
128 |
//to filtered line.
|
|
129 |
if ( strchr( cINVALID_TRACE_FILE_CHARS, cOriginalLineFromFile[i] ) == 0 )
|
|
130 |
*pFiltered++ = cOriginalLineFromFile[i];
|
|
131 |
}
|
|
132 |
*pFiltered++ = 0; //Add null termination to filtered line.
|
|
133 |
|
|
134 |
if( !bFileVersionSaved && *cLineFromFile != 0 )
|
|
135 |
{
|
|
136 |
bFileVersionSaved = true;
|
|
137 |
m_DataSaver.AddString( AT_DATA_FILE_VERSION );
|
|
138 |
m_DataSaver.AddLineToLast();
|
|
139 |
}
|
|
140 |
|
|
141 |
// Is there main ID?
|
|
142 |
if( strstr( cLineFromFile, MAIN_ID ) != NULL )
|
|
143 |
{
|
|
144 |
string sRestOfLine( cLineFromFile );
|
|
145 |
string sTemp("");
|
|
146 |
unsigned __int64 iTimeStamp(0);
|
|
147 |
string sTime("");
|
|
148 |
string sLineStart("");
|
|
149 |
|
|
150 |
// Get part of line before main id. This should contain time info
|
|
151 |
sLineStart = GetStringUntilMainId( sRestOfLine );
|
|
152 |
// Get message's time stamp in microseconds
|
|
153 |
iTimeStamp = ParseTimeStamp( sLineStart );
|
|
154 |
// store whole line from MAIN_ID - to be logged to cleaned traces file
|
|
155 |
string sLineToCleanedFile( sRestOfLine );
|
|
156 |
|
|
157 |
// Get main ID
|
|
158 |
sTemp = GetStringUntilNextSpace( sRestOfLine );
|
|
159 |
|
|
160 |
// Is there more data in line?
|
|
161 |
if( sRestOfLine.empty() )
|
|
162 |
{
|
|
163 |
continue;
|
|
164 |
}
|
|
165 |
|
|
166 |
// Get next argument
|
|
167 |
sTemp = GetStringUntilNextSpace( sRestOfLine );
|
|
168 |
// This might be process id, device info message or error message
|
|
169 |
if ( sTemp.compare( ERROR_OCCURED ) == 0 )
|
|
170 |
{
|
|
171 |
// Api mismatch between s60 side and atool.exe
|
|
172 |
if ( sRestOfLine.find( INCORRECT_ATOOL_VERSION ) != string::npos )
|
|
173 |
{
|
|
174 |
cout << "Test run failed because version conflict between device binaries\nand the atool.exe version used to build the application." << endl;
|
|
175 |
size_t pS = sRestOfLine.find_first_of('[');
|
|
176 |
size_t pE = sRestOfLine.find_first_of(']');
|
|
177 |
size_t pSL = sRestOfLine.find_last_of('[');
|
|
178 |
size_t pEL = sRestOfLine.find_last_of(']');
|
|
179 |
if ( pS != string::npos && pE != string::npos && pSL != string::npos && pEL != string::npos )
|
|
180 |
{
|
|
181 |
string deviceVer = sRestOfLine.substr( pS+1, pE-pS-1 );
|
|
182 |
string atoolVer = sRestOfLine.substr( pSL+1, pEL-pSL-1 );
|
|
183 |
cout << "\tdevice: " << deviceVer << endl
|
|
184 |
<< "\tatool.exe: " << atoolVer << endl;
|
|
185 |
}
|
|
186 |
}
|
|
187 |
else
|
|
188 |
cout << sRestOfLine << endl;
|
|
189 |
continue;
|
|
190 |
}
|
|
191 |
|
|
192 |
if ( sTemp.compare( LABEL_DEVICE_INFO ) == 0 )
|
|
193 |
{
|
|
194 |
|
|
195 |
if( vProcessList[iProcessIDinList].bProcessOnGoing == false )
|
|
196 |
continue;
|
|
197 |
|
|
198 |
// get time string from timestamp
|
|
199 |
sTime = GetTimeFromTimeStamp( iTimeStamp, vProcessList[iProcessIDinList].iTimeSpan );
|
|
200 |
|
|
201 |
// device info line, log it to cleaned file for carbide
|
|
202 |
if( bCreateCleanedTraces )
|
|
203 |
{
|
|
204 |
// add message to cleaned traces file
|
|
205 |
cleanedTraces << sTime << " "; //add time
|
|
206 |
cleanedTraces << MAIN_ID << " "; //add MAIN_ID
|
|
207 |
cleanedTraces << LABEL_DEVICE_INFO << " "; //add Message type
|
|
208 |
cleanedTraces << sRestOfLine << "\n"; //add the rest of the line
|
|
209 |
}
|
|
210 |
continue;
|
|
211 |
}
|
|
212 |
|
|
213 |
unsigned long iProcessID = _httoi( sTemp.c_str() );
|
|
214 |
// todo to be removed when reallocations are implemented
|
|
215 |
string sProcessID = sTemp;
|
|
216 |
|
|
217 |
iProcessIDinList = -1;
|
|
218 |
// Find process from list
|
|
219 |
for( unsigned int i = 0 ; i < vProcessList.size() ; i++ )
|
|
220 |
{
|
|
221 |
if( vProcessList[i].iProcessID == iProcessID )
|
|
222 |
{
|
|
223 |
iProcessIDinList = i;
|
|
224 |
break;
|
|
225 |
}
|
|
226 |
}
|
|
227 |
// Is Process ID found from list?
|
|
228 |
if( iProcessIDinList == -1 )
|
|
229 |
{
|
|
230 |
CProcessData ProcessData;
|
|
231 |
ProcessData.bProcessOnGoing = false;
|
|
232 |
ProcessData.iProcessID = iProcessID;
|
|
233 |
vProcessList.push_back( ProcessData );
|
|
234 |
iProcessIDinList = (int)vProcessList.size() - 1;
|
|
235 |
}
|
|
236 |
|
|
237 |
// Remove spaces from end of line
|
|
238 |
while( sRestOfLine[sRestOfLine.size()-1] == ' ' )
|
|
239 |
{
|
|
240 |
sRestOfLine.resize( sRestOfLine.size()-1 );
|
|
241 |
}
|
|
242 |
|
|
243 |
string sWholeTempLine( sRestOfLine );
|
|
244 |
|
|
245 |
// Get command
|
|
246 |
sTemp = GetStringUntilNextSpace( sRestOfLine );
|
|
247 |
|
|
248 |
// Use c style string for easy comparisong of command.
|
|
249 |
const char* pCommand = sTemp.c_str();
|
|
250 |
|
|
251 |
// Process start.
|
|
252 |
if( ! _stricmp( pCommand, LABEL_PROCESS_START ) )
|
|
253 |
{
|
|
254 |
bRet = true; // Set return value true we found start.
|
|
255 |
vProcessList[iProcessIDinList].vData.push_back( sWholeTempLine );
|
|
256 |
vProcessList[iProcessIDinList].bProcessOnGoing = true;
|
|
257 |
|
|
258 |
// remove <processName> <processID> part
|
|
259 |
GetStringUntilNextSpace( sRestOfLine );
|
|
260 |
GetStringUntilNextSpace( sRestOfLine );
|
|
261 |
// get time
|
|
262 |
sTemp = GetStringUntilNextSpace( sRestOfLine );
|
|
263 |
unsigned __int64 iTemp(0);
|
|
264 |
sscanf_s( sTemp.c_str(), "%016I64x", &iTemp);
|
|
265 |
//calculate span between PCS time and PCS timestamp
|
|
266 |
vProcessList[iProcessIDinList].iTimeSpan = iTemp - iTimeStamp;
|
|
267 |
|
|
268 |
if( bCreateCleanedTraces )
|
|
269 |
{
|
|
270 |
// add message to cleaned traces file
|
|
271 |
cleanedTraces << sTemp << " "; //add time
|
|
272 |
cleanedTraces << MAIN_ID << " "; //add MAIN_ID
|
|
273 |
cleanedTraces << sProcessID << " "; //add process ID
|
|
274 |
cleanedTraces << sWholeTempLine << "\n"; //add the rest of the line
|
|
275 |
}
|
|
276 |
|
|
277 |
continue;
|
|
278 |
}
|
|
279 |
|
|
280 |
// Check is process ongoing if not skip other tags.
|
|
281 |
if( vProcessList[iProcessIDinList].bProcessOnGoing == false )
|
|
282 |
continue;
|
|
283 |
|
|
284 |
// get time string from timestamp
|
|
285 |
sTime = GetTimeFromTimeStamp( iTimeStamp, vProcessList[iProcessIDinList].iTimeSpan );
|
|
286 |
|
52
|
287 |
if( bCreateCleanedTraces )
|
51
|
288 |
{
|
52
|
289 |
cleanedTraces << sTime << " "; //add time
|
|
290 |
cleanedTraces << sLineToCleanedFile << "\n"; //add the rest of the line
|
|
291 |
}
|
51
|
292 |
|
52
|
293 |
// Allocation header
|
|
294 |
if ( ! _stricmp( pCommand, ALLOCH_ID ) )
|
51
|
295 |
{
|
|
296 |
// Add alloc
|
|
297 |
vProcessList[iProcessIDinList].AllocH( sRestOfLine, sTime );
|
|
298 |
|
|
299 |
// Subtests running?
|
|
300 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
301 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
302 |
{
|
|
303 |
if( viSubTestIter->bRunning )
|
|
304 |
{
|
|
305 |
// Save alloc also to sub test
|
|
306 |
viSubTestIter->AllocH( sRestOfLine, sTime );
|
|
307 |
}
|
|
308 |
viSubTestIter++;
|
|
309 |
}
|
|
310 |
}
|
|
311 |
// Allocation fragment (call stack).
|
|
312 |
else if ( ! _stricmp( pCommand, ALLOCF_ID ) )
|
|
313 |
{
|
|
314 |
// Add alloc fragment
|
|
315 |
vProcessList[iProcessIDinList].AllocF( sRestOfLine, sTime );
|
|
316 |
|
|
317 |
// Subtests running?
|
|
318 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
319 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
320 |
{
|
|
321 |
if( viSubTestIter->bRunning )
|
|
322 |
{
|
|
323 |
// Save alloc fragment also to sub test
|
|
324 |
viSubTestIter->AllocF( sRestOfLine, sTime );
|
|
325 |
}
|
|
326 |
viSubTestIter++;
|
|
327 |
}
|
|
328 |
}
|
52
|
329 |
//Reallocation header
|
51
|
330 |
else if ( ! _stricmp( pCommand, REALLOCH_ID ) )
|
|
331 |
{
|
52
|
332 |
// todo add reallocation flag?
|
|
333 |
|
|
334 |
string sFreeLine = "";
|
|
335 |
string sAllocLine = "";
|
|
336 |
|
51
|
337 |
// Add free
|
|
338 |
|
|
339 |
// get 'free' line from realloc line
|
|
340 |
string sFreeRestOfLine = sRestOfLine;
|
52
|
341 |
|
51
|
342 |
sFreeLine.append( GetStringUntilNextSpace( sFreeRestOfLine, true ) ); //append freed memory address
|
|
343 |
sFreeLine.append( " " );
|
|
344 |
// next two strings are for 'alloc' (address and size) - lets remove them
|
|
345 |
GetStringUntilNextSpace( sFreeRestOfLine, true );
|
|
346 |
GetStringUntilNextSpace( sFreeRestOfLine, true );
|
|
347 |
// add rest of line to 'free' line
|
|
348 |
sFreeLine.append( sFreeRestOfLine );
|
|
349 |
//add 'free' line
|
|
350 |
vProcessList[iProcessIDinList].FreeH( sFreeLine, sTime );
|
|
351 |
|
|
352 |
// Add alloc
|
|
353 |
|
|
354 |
//get 'alloc' line from realloc line
|
52
|
355 |
// first string is for 'free' (address), lets remove it first
|
51
|
356 |
GetStringUntilNextSpace( sRestOfLine );
|
52
|
357 |
sAllocLine = sRestOfLine;
|
51
|
358 |
// add 'alloc' line
|
52
|
359 |
vProcessList[iProcessIDinList].AllocH( sAllocLine, sTime );
|
51
|
360 |
|
|
361 |
// Subtests running?
|
|
362 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
363 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
364 |
{
|
|
365 |
if( viSubTestIter->bRunning )
|
|
366 |
{
|
|
367 |
// Save realloc also to sub test
|
|
368 |
|
|
369 |
//add 'free' line
|
|
370 |
vProcessList[iProcessIDinList].FreeH( sFreeLine, sTime );
|
|
371 |
|
|
372 |
// add 'alloc' line
|
52
|
373 |
vProcessList[iProcessIDinList].AllocH( sAllocLine, sTime );
|
51
|
374 |
}
|
|
375 |
viSubTestIter++;
|
|
376 |
}
|
|
377 |
}
|
52
|
378 |
// rellocation fragment (call stack)
|
51
|
379 |
else if ( ! _stricmp( pCommand, REALLOCF_ID ) )
|
|
380 |
{
|
52
|
381 |
string sFreeLine = "";
|
|
382 |
string sAllocLine = "";
|
|
383 |
|
|
384 |
// Not used currently.
|
|
385 |
/*
|
51
|
386 |
// Add free fragment
|
|
387 |
|
|
388 |
// get 'free' line from realloc line
|
|
389 |
string sFreeRestOfLine = sRestOfLine;
|
|
390 |
sFreeLine.append( GetStringUntilNextSpace( sFreeRestOfLine, true ) ); //append freed memory address
|
|
391 |
sFreeLine.append( " " );
|
|
392 |
// next string is for 'alloc' (address) - lets remove it
|
|
393 |
GetStringUntilNextSpace( sFreeRestOfLine, true );
|
|
394 |
// add rest of line to 'free' line
|
|
395 |
sFreeLine.append( sFreeRestOfLine );
|
52
|
396 |
|
51
|
397 |
//add 'free' line
|
52
|
398 |
vProcessList[iProcessIDinList].FreeF( sFreeLine, sTime );
|
|
399 |
*/
|
51
|
400 |
|
|
401 |
// Add alloc fragment
|
|
402 |
|
|
403 |
// first string is for 'free' (address), lets remove it first
|
|
404 |
GetStringUntilNextSpace( sRestOfLine, true );
|
52
|
405 |
sAllocLine = sRestOfLine;
|
51
|
406 |
//add 'alloc' line
|
52
|
407 |
vProcessList[iProcessIDinList].AllocF( sAllocLine, sTime );
|
51
|
408 |
|
|
409 |
// Subtests running?
|
|
410 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
411 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
412 |
{
|
|
413 |
if( viSubTestIter->bRunning )
|
|
414 |
{
|
52
|
415 |
// Save realloc fragment also to sub test
|
51
|
416 |
|
52
|
417 |
// Not used currently.
|
|
418 |
/*
|
51
|
419 |
//add 'free' line
|
52
|
420 |
vProcessList[iProcessIDinList].FreeF( sFreeLine, sTime );
|
|
421 |
*/
|
51
|
422 |
|
|
423 |
//add 'alloc' line
|
52
|
424 |
vProcessList[iProcessIDinList].AllocF( sAllocLine, sTime );
|
51
|
425 |
}
|
|
426 |
viSubTestIter++;
|
|
427 |
}
|
|
428 |
}
|
52
|
429 |
// Free header
|
51
|
430 |
else if( ! _stricmp( pCommand, FREEH_ID ) )
|
|
431 |
{
|
|
432 |
// Send free
|
|
433 |
vProcessList[iProcessIDinList].FreeH( sRestOfLine, sTime );
|
|
434 |
|
|
435 |
// Subtests running?
|
|
436 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
437 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
438 |
{
|
|
439 |
if( viSubTestIter->bRunning )
|
|
440 |
{
|
|
441 |
// Send free to subtest
|
|
442 |
viSubTestIter->FreeH( sRestOfLine, sTime );
|
|
443 |
}
|
|
444 |
viSubTestIter++;
|
|
445 |
}
|
|
446 |
|
|
447 |
}
|
52
|
448 |
// Free fragment
|
51
|
449 |
else if( ! _stricmp( pCommand, FREEF_ID ) )
|
|
450 |
{
|
|
451 |
// Not used currently.
|
|
452 |
}
|
|
453 |
// Command process end
|
|
454 |
else if( ! _stricmp( pCommand, LABEL_PROCESS_END ) )
|
|
455 |
{
|
52
|
456 |
// add processID and time
|
51
|
457 |
sWholeTempLine.append(" ");
|
|
458 |
sWholeTempLine.append( sProcessID );
|
|
459 |
sWholeTempLine.append(" ");
|
|
460 |
sWholeTempLine.append( sTime );
|
|
461 |
|
|
462 |
// Set process has ended.
|
|
463 |
vProcessList[iProcessIDinList].bProcessOnGoing = false;
|
|
464 |
|
|
465 |
// Save leaks
|
|
466 |
vector<string> vLeaks;
|
|
467 |
vector<string>::iterator viLeaks;
|
|
468 |
vProcessList[iProcessIDinList].GetLeakList( vLeaks );
|
|
469 |
for ( viLeaks = vLeaks.begin(); viLeaks != vLeaks.end(); viLeaks++ )
|
|
470 |
{
|
|
471 |
sTemp.clear();
|
|
472 |
sTemp.append( LABEL_MEM_LEAK );
|
|
473 |
sTemp.append( " " );
|
|
474 |
sTemp.append( *viLeaks );
|
|
475 |
vProcessList[iProcessIDinList].vData.push_back( sTemp );
|
|
476 |
}
|
|
477 |
vProcessList[iProcessIDinList].ClearAllocs();
|
|
478 |
|
|
479 |
vector<string>::iterator viHandleIter = vProcessList[iProcessIDinList].vHandleLeaks.begin();
|
|
480 |
// Print handle leaks
|
|
481 |
while( viHandleIter != vProcessList[iProcessIDinList].vHandleLeaks.end() )
|
|
482 |
{
|
|
483 |
sTemp.clear();
|
|
484 |
sTemp.append( viHandleIter->c_str() );
|
|
485 |
vProcessList[iProcessIDinList].vData.push_back( sTemp );
|
|
486 |
viHandleIter++;
|
|
487 |
}
|
|
488 |
// Clear handle leaks from list
|
|
489 |
vProcessList[iProcessIDinList].vHandleLeaks.clear();
|
|
490 |
|
|
491 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
492 |
// Print sub test leaks
|
|
493 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
494 |
{
|
|
495 |
// Print sub test start
|
|
496 |
string sLine( LABEL_TEST_START ); sLine.append( " " );
|
|
497 |
sLine.append( viSubTestIter->sStartTime ); sLine.append( " " );
|
|
498 |
sLine.append( viSubTestIter->sSubTestName ); sLine.append( " " );
|
|
499 |
sLine.append( viSubTestIter->sSubTestStartHandleCount );
|
|
500 |
vProcessList[iProcessIDinList].vData.push_back( sLine );
|
|
501 |
sLine.clear();
|
|
502 |
|
|
503 |
// DLL Loads.
|
|
504 |
for( vector<string>::iterator it = viSubTestIter->vData.begin();
|
|
505 |
it != viSubTestIter->vData.end(); it++ )
|
|
506 |
{
|
|
507 |
vProcessList[iProcessIDinList].vData.push_back( (*it) );
|
|
508 |
}
|
|
509 |
|
|
510 |
// Subtest leaks.
|
|
511 |
vector<string> vSubLeaks;
|
|
512 |
vector<string>::iterator viSubLeaks;
|
|
513 |
viSubTestIter->GetLeakList( vSubLeaks );
|
|
514 |
for ( viSubLeaks = vSubLeaks.begin(); viSubLeaks != vSubLeaks.end(); viSubLeaks++ )
|
|
515 |
{
|
|
516 |
sLine.append( LABEL_MEM_LEAK );
|
|
517 |
sLine.append( " " );
|
|
518 |
sLine.append( *viSubLeaks );
|
|
519 |
vProcessList[iProcessIDinList].vData.push_back( sLine );
|
|
520 |
sLine.clear();
|
|
521 |
}
|
|
522 |
viSubTestIter->ClearAllocs();
|
|
523 |
|
|
524 |
if( !viSubTestIter->sEndTime.empty() )
|
|
525 |
{
|
|
526 |
// Print sub test end
|
|
527 |
sLine.append( LABEL_TEST_END ); sLine.append( " " );
|
|
528 |
sLine.append( viSubTestIter->sEndTime ); sLine.append( " " );
|
|
529 |
sLine.append( viSubTestIter->sSubTestName ); sLine.append( " " );
|
|
530 |
sLine.append( viSubTestIter->sSubTestEndHandleCount );
|
|
531 |
vProcessList[iProcessIDinList].vData.push_back( sLine );
|
|
532 |
}
|
|
533 |
viSubTestIter++;
|
|
534 |
}
|
|
535 |
|
|
536 |
// Clear sub tests from list
|
|
537 |
vProcessList[iProcessIDinList].vSubTests.clear();
|
|
538 |
vProcessList[iProcessIDinList].vData.push_back( sWholeTempLine );
|
|
539 |
}
|
52
|
540 |
// Handle leak
|
51
|
541 |
else if( ! _stricmp( pCommand, LABEL_HANDLE_LEAK ) )
|
|
542 |
{
|
|
543 |
// Make whole line
|
|
544 |
sTemp.append( " " );
|
|
545 |
sTemp.append( sRestOfLine );
|
|
546 |
vProcessList[iProcessIDinList].vHandleLeaks.push_back( sTemp );
|
|
547 |
}
|
52
|
548 |
// Dll load
|
51
|
549 |
else if( ! _stricmp( pCommand, LABEL_DLL_LOAD ) )
|
|
550 |
{
|
52
|
551 |
// add time
|
51
|
552 |
sWholeTempLine.append( " " );
|
|
553 |
sWholeTempLine.append( sTime );
|
|
554 |
|
|
555 |
// Add module load to process data.
|
|
556 |
vProcessList[iProcessIDinList].vData.push_back( sWholeTempLine );
|
|
557 |
// Add module load to subtest data if test running.
|
|
558 |
for( vector<CSubTestData>::iterator it = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
559 |
it != vProcessList[iProcessIDinList].vSubTests.end(); it++ )
|
|
560 |
{
|
|
561 |
if( it->bRunning )
|
|
562 |
it->vData.push_back( sWholeTempLine );
|
|
563 |
}
|
|
564 |
|
|
565 |
}
|
52
|
566 |
// Dll unload
|
51
|
567 |
else if( ! _stricmp( pCommand, LABEL_DLL_UNLOAD ) )
|
|
568 |
{
|
52
|
569 |
// add time
|
51
|
570 |
sWholeTempLine.append( " " );
|
|
571 |
sWholeTempLine.append( sTime );
|
|
572 |
|
|
573 |
// Add module load to process data.
|
|
574 |
vProcessList[iProcessIDinList].vData.push_back( sWholeTempLine );
|
|
575 |
// Add module unload to subtest data if test running.
|
|
576 |
for( vector<CSubTestData>::iterator it = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
577 |
it != vProcessList[iProcessIDinList].vSubTests.end(); it++ )
|
|
578 |
{
|
|
579 |
if( it->bRunning )
|
|
580 |
it->vData.push_back( sWholeTempLine );
|
|
581 |
}
|
|
582 |
}
|
|
583 |
else if( sTemp.find( LABEL_LOGGING_CANCELLED ) != string::npos ||
|
|
584 |
sTemp.find( LABEL_PROCESS_END ) != string::npos || sTemp.find( LABEL_ERROR_OCCURED ) != string::npos ||
|
|
585 |
sTemp.find( LABEL_HANDLE_LEAK ) != string::npos )
|
|
586 |
{
|
|
587 |
vProcessList[iProcessIDinList].vData.push_back( sWholeTempLine );
|
|
588 |
}
|
52
|
589 |
// Subtest start
|
51
|
590 |
else if( ! _stricmp( pCommand, LABEL_TEST_START ) )
|
|
591 |
{
|
|
592 |
bRet = true; // Set return value true we found start.
|
|
593 |
// Get sub test time
|
|
594 |
string sSubTestTime = GetStringUntilNextSpace( sRestOfLine );
|
|
595 |
// Get sub test name
|
|
596 |
string sSubTestName = GetStringUntilNextSpace( sRestOfLine );
|
|
597 |
// Get sub test start handle count
|
|
598 |
string sSubTestStartHandleCount = GetStringUntilNextSpace( sRestOfLine );
|
|
599 |
|
|
600 |
CSubTestData SubTestData;
|
|
601 |
SubTestData.bRunning = true;
|
|
602 |
SubTestData.sStartTime = sSubTestTime;
|
|
603 |
SubTestData.sSubTestName = sSubTestName;
|
|
604 |
SubTestData.sSubTestStartHandleCount = sSubTestStartHandleCount.c_str();
|
|
605 |
|
|
606 |
vProcessList[iProcessIDinList].vSubTests.push_back( SubTestData );
|
|
607 |
}
|
52
|
608 |
// Subtest end
|
51
|
609 |
else if( ! _stricmp( pCommand, LABEL_TEST_END ) )
|
|
610 |
{
|
|
611 |
// Get sub test time
|
|
612 |
string sSubTestEnd = GetStringUntilNextSpace( sRestOfLine );
|
|
613 |
// Get sub test name
|
|
614 |
string sSubTestName = GetStringUntilNextSpace( sRestOfLine );
|
|
615 |
// Get sub test end handle count
|
|
616 |
string sSubTestEndHandleCount = GetStringUntilNextSpace( sRestOfLine );
|
|
617 |
|
|
618 |
// Find subtest
|
|
619 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[iProcessIDinList].vSubTests.begin();
|
|
620 |
while( viSubTestIter != vProcessList[iProcessIDinList].vSubTests.end() )
|
|
621 |
{
|
|
622 |
if( viSubTestIter->sSubTestName == sSubTestName && viSubTestIter->sEndTime.empty() )
|
|
623 |
{
|
|
624 |
viSubTestIter->sEndTime = sSubTestEnd;
|
|
625 |
viSubTestIter->bRunning = false;
|
|
626 |
viSubTestIter->sSubTestEndHandleCount = sSubTestEndHandleCount.c_str();
|
|
627 |
}
|
|
628 |
viSubTestIter++;
|
|
629 |
}
|
|
630 |
}
|
52
|
631 |
// Thread start
|
51
|
632 |
else if( ! _stricmp( pCommand, LABEL_THREAD_START ) )
|
|
633 |
{
|
|
634 |
//currently not used
|
|
635 |
}
|
52
|
636 |
// Thread end
|
51
|
637 |
else if( ! _stricmp( pCommand, LABEL_THREAD_END ) )
|
|
638 |
{
|
|
639 |
//currently not used
|
|
640 |
}
|
|
641 |
else
|
|
642 |
{
|
52
|
643 |
// unknown tag, only logged it to cleaned file for carbide
|
51
|
644 |
}
|
|
645 |
}
|
|
646 |
}
|
|
647 |
|
|
648 |
if( bCreateCleanedTraces )
|
|
649 |
{
|
|
650 |
// close stream
|
|
651 |
cleanedTraces.close();
|
|
652 |
}
|
|
653 |
|
|
654 |
// Print all saved data from processes
|
|
655 |
for( unsigned int i = 0 ; i < vProcessList.size() ; i++ )
|
|
656 |
{
|
|
657 |
// Print saved lines
|
|
658 |
for( unsigned int iDataCounter = 0 ; iDataCounter < vProcessList[i].vData.size() ; iDataCounter++ )
|
|
659 |
{
|
|
660 |
m_DataSaver.AddString( vProcessList[i].vData[iDataCounter].c_str() );
|
|
661 |
m_DataSaver.AddLineToLast();
|
|
662 |
}
|
|
663 |
|
|
664 |
string sTemp;
|
|
665 |
|
|
666 |
// Save leaks
|
|
667 |
vector<string> vLeaks;
|
|
668 |
vector<string>::iterator viLeaks;
|
|
669 |
vProcessList[i].GetLeakList( vLeaks );
|
|
670 |
for ( viLeaks = vLeaks.begin(); viLeaks != vLeaks.end(); viLeaks++ )
|
|
671 |
{
|
|
672 |
sTemp.clear();
|
|
673 |
sTemp.append( LABEL_MEM_LEAK );
|
|
674 |
sTemp.append( " " );
|
|
675 |
sTemp.append( *viLeaks );
|
|
676 |
m_DataSaver.AddString( sTemp.c_str() );
|
|
677 |
m_DataSaver.AddLineToLast();
|
|
678 |
}
|
|
679 |
|
|
680 |
vector<string>::iterator viHandleIter = vProcessList[i].vHandleLeaks.begin();
|
|
681 |
// Print handle leaks, if there is data left, there was no process end.
|
|
682 |
while( viHandleIter != vProcessList[i].vHandleLeaks.end() )
|
|
683 |
{
|
|
684 |
sTemp.clear();
|
|
685 |
sTemp.append( viHandleIter->c_str() );
|
|
686 |
m_DataSaver.AddString( sTemp.c_str() );
|
|
687 |
m_DataSaver.AddLineToLast();
|
|
688 |
viHandleIter++;
|
|
689 |
}
|
|
690 |
vector<CSubTestData>::iterator viSubTestIter = vProcessList[i].vSubTests.begin();
|
|
691 |
// Print sub test data, if there is data left, there was no process end.
|
|
692 |
while( viSubTestIter != vProcessList[i].vSubTests.end() )
|
|
693 |
{
|
|
694 |
// Print sub test start
|
|
695 |
string sLine( LABEL_TEST_START ); sLine.append( " " );
|
|
696 |
sLine.append( viSubTestIter->sStartTime ); sLine.append( " " );
|
|
697 |
sLine.append( viSubTestIter->sSubTestName ); sLine.append( " " );
|
|
698 |
sLine.append( viSubTestIter->sSubTestStartHandleCount );
|
|
699 |
m_DataSaver.AddString( sLine.c_str() );
|
|
700 |
m_DataSaver.AddLineToLast();
|
|
701 |
sLine.clear();
|
|
702 |
|
|
703 |
// DLL Loads.
|
|
704 |
for( vector<string>::iterator it = viSubTestIter->vData.begin();
|
|
705 |
it != viSubTestIter->vData.end(); it++ )
|
|
706 |
{
|
|
707 |
m_DataSaver.AddString( (*it).c_str() );
|
|
708 |
m_DataSaver.AddLineToLast();
|
|
709 |
}
|
|
710 |
|
|
711 |
// Subtest leaks.
|
|
712 |
vector<string> vSubLeaks;
|
|
713 |
vector<string>::iterator viSubLeaks;
|
|
714 |
viSubTestIter->GetLeakList( vSubLeaks );
|
|
715 |
for ( viSubLeaks = vSubLeaks.begin(); viSubLeaks != vSubLeaks.end(); viSubLeaks++ )
|
|
716 |
{
|
|
717 |
sLine.append( LABEL_MEM_LEAK );
|
|
718 |
sLine.append( " " );
|
|
719 |
sLine.append( *viSubLeaks );
|
|
720 |
m_DataSaver.AddString( sLine.c_str() );
|
|
721 |
m_DataSaver.AddLineToLast();
|
|
722 |
sLine.clear();
|
|
723 |
}
|
|
724 |
|
|
725 |
// Print sub test end
|
|
726 |
sLine.append( LABEL_TEST_END ); sLine.append( " " );
|
|
727 |
sLine.append( viSubTestIter->sEndTime ); sLine.append( " " );
|
|
728 |
sLine.append( viSubTestIter->sSubTestName ); sLine.append( " " );
|
|
729 |
sLine.append( viSubTestIter->sSubTestEndHandleCount );
|
|
730 |
m_DataSaver.AddString( sLine.c_str() );
|
|
731 |
m_DataSaver.AddLineToLast();
|
|
732 |
|
|
733 |
viSubTestIter++;
|
|
734 |
}
|
|
735 |
}
|
|
736 |
// Save lines to file.
|
|
737 |
m_DataSaver.SaveLinesToFile( pOutputFileName, TEXT_DATA );
|
|
738 |
// Close file.
|
|
739 |
in.close();
|
|
740 |
return bRet;
|
|
741 |
}
|
|
742 |
|
|
743 |
// -----------------------------------------------------------------------------
|
|
744 |
// CATParseTraceFile::GetDataSaver
|
|
745 |
// Gets data saver object.
|
|
746 |
// -----------------------------------------------------------------------------
|
|
747 |
CATDataSaver* CATParseTraceFile::GetDataSaver(void)
|
|
748 |
{
|
|
749 |
LOG_LOW_FUNC_ENTRY("CATParseTraceFile::GetDataSaver");
|
|
750 |
return &m_DataSaver;
|
|
751 |
}
|
|
752 |
|
|
753 |
|
|
754 |
// -----------------------------------------------------------------------------
|
|
755 |
// CATBase::GetTimeFromTimeStamp
|
|
756 |
// Gets time from timestamp in microseconds as string
|
|
757 |
// -----------------------------------------------------------------------------
|
|
758 |
string CATParseTraceFile::GetTimeFromTimeStamp( unsigned __int64 iTimeStamp, unsigned __int64 iTimeSpan )
|
|
759 |
{
|
|
760 |
unsigned __int64 iTime = iTimeStamp + iTimeSpan;
|
|
761 |
stringstream ss;
|
|
762 |
ss << std::hex << iTime;
|
|
763 |
|
|
764 |
return ss.str();
|
|
765 |
}
|
|
766 |
|
|
767 |
//EOF
|