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