perfsrv/memspy/CommandLine/Source/MemSpyCommandLine.cpp
author hgs
Tue, 26 Oct 2010 16:20:32 +0300
changeset 62 1c2bb2fc7c87
parent 54 a151135b0cf9
permissions -rw-r--r--
201043
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
52
hgs
parents: 51
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents: 51
diff changeset
     3
 * All rights reserved.
hgs
parents: 51
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 51
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 51
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 51
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 51
diff changeset
     8
 *
hgs
parents: 51
diff changeset
     9
 * Initial Contributors:
hgs
parents: 51
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 51
diff changeset
    11
 *
hgs
parents: 51
diff changeset
    12
 * Contributors:
hgs
parents: 51
diff changeset
    13
 *
hgs
parents: 51
diff changeset
    14
 * Description:
hgs
parents: 51
diff changeset
    15
 *
hgs
parents: 51
diff changeset
    16
 */
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "MemSpyCommandLine.h"
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
// System includes
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
#include <bacline.h>
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include <bautils.h>
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include <memspyengineclientinterface.h>
30
hgs
parents: 20
diff changeset
    24
#include <memspysession.h>
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
#include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
// User includes
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "MemSpyCommands.h"
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
30
hgs
parents: 20
diff changeset
    30
/*
52
hgs
parents: 51
diff changeset
    31
 CMemSpyCommandLine::CMemSpyCommandLine()
hgs
parents: 51
diff changeset
    32
 {	
hgs
parents: 51
diff changeset
    33
 }
hgs
parents: 51
diff changeset
    34
 */
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
30
hgs
parents: 20
diff changeset
    36
CMemSpyCommandLine::CMemSpyCommandLine( CConsoleBase& aConsole )
52
hgs
parents: 51
diff changeset
    37
	 :CActive(EPriorityHigh), iConsole(aConsole)
hgs
parents: 51
diff changeset
    38
	{
hgs
parents: 51
diff changeset
    39
	CActiveScheduler::Add(this);
hgs
parents: 51
diff changeset
    40
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
CMemSpyCommandLine::~CMemSpyCommandLine()
52
hgs
parents: 51
diff changeset
    43
	{
30
hgs
parents: 20
diff changeset
    44
	Cancel();
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
52
hgs
parents: 51
diff changeset
    46
	if (iMemSpySession)
hgs
parents: 51
diff changeset
    47
		{
hgs
parents: 51
diff changeset
    48
		iMemSpySession->Close();
hgs
parents: 51
diff changeset
    49
		}
hgs
parents: 51
diff changeset
    50
	delete iMemSpySession;
hgs
parents: 51
diff changeset
    51
	iFsSession.Close();
hgs
parents: 51
diff changeset
    52
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
void CMemSpyCommandLine::ConstructL()
52
hgs
parents: 51
diff changeset
    55
	{
hgs
parents: 51
diff changeset
    56
	User::LeaveIfError(iFsSession.Connect());
hgs
parents: 51
diff changeset
    57
	iMemSpySession = new (ELeave) RMemSpySession();
hgs
parents: 51
diff changeset
    58
	ConnectToMemSpyL();
hgs
parents: 51
diff changeset
    59
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
52
hgs
parents: 51
diff changeset
    61
CMemSpyCommandLine* CMemSpyCommandLine::NewLC(CConsoleBase& aConsole)
hgs
parents: 51
diff changeset
    62
	{
hgs
parents: 51
diff changeset
    63
	CMemSpyCommandLine* self = new (ELeave) CMemSpyCommandLine(aConsole);
hgs
parents: 51
diff changeset
    64
	CleanupStack::PushL(self);
hgs
parents: 51
diff changeset
    65
	self->ConstructL();
hgs
parents: 51
diff changeset
    66
	return self;
hgs
parents: 51
diff changeset
    67
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
52
hgs
parents: 51
diff changeset
    69
void CMemSpyCommandLine::PerformOpL(const CCommandLineArguments& aCommandLine)
hgs
parents: 51
diff changeset
    70
	{
hgs
parents: 51
diff changeset
    71
	const TInt count = aCommandLine.Count();
hgs
parents: 51
diff changeset
    72
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::PerformOpL() - START - arg count: %d, this: 0x%08x", count, this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
54
hgs
parents: 52
diff changeset
    74
	if (count > 1)
52
hgs
parents: 51
diff changeset
    75
		{
hgs
parents: 51
diff changeset
    76
		// Get main command
hgs
parents: 51
diff changeset
    77
		TBuf<KMemSpyCommandLineMaxLength> command;
hgs
parents: 51
diff changeset
    78
		command.Copy(aCommandLine.Arg(1));
hgs
parents: 51
diff changeset
    79
		command.UpperCase();
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
52
hgs
parents: 51
diff changeset
    81
		// Extract arguments into array
hgs
parents: 51
diff changeset
    82
		CDesCArrayFlat* args = new (ELeave) CDesCArrayFlat(4);
hgs
parents: 51
diff changeset
    83
		CleanupStack::PushL(args);
hgs
parents: 51
diff changeset
    84
		for (TInt i = 2; i < count; i++)
hgs
parents: 51
diff changeset
    85
			{
hgs
parents: 51
diff changeset
    86
			args->AppendL(aCommandLine.Arg(i));
hgs
parents: 51
diff changeset
    87
			}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
52
hgs
parents: 51
diff changeset
    89
		// Perform op
hgs
parents: 51
diff changeset
    90
		PerformSingleOpL(command, *args);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
52
hgs
parents: 51
diff changeset
    92
		// Tidy up
hgs
parents: 51
diff changeset
    93
		CleanupStack::PopAndDestroy(args);
hgs
parents: 51
diff changeset
    94
		}
54
hgs
parents: 52
diff changeset
    95
	else if ( count == 1 )
hgs
parents: 52
diff changeset
    96
		{
62
hgs
parents: 54
diff changeset
    97
		PrintHelp();
54
hgs
parents: 52
diff changeset
    98
		}
52
hgs
parents: 51
diff changeset
    99
	else
hgs
parents: 51
diff changeset
   100
		{
hgs
parents: 51
diff changeset
   101
		User::Leave(KErrUnderflow);
hgs
parents: 51
diff changeset
   102
		}
hgs
parents: 51
diff changeset
   103
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
52
hgs
parents: 51
diff changeset
   105
void CMemSpyCommandLine::PerformSingleOpL(const TDesC& aCommand, const CDesCArray& aParameters)
hgs
parents: 51
diff changeset
   106
	{
hgs
parents: 51
diff changeset
   107
	// Record duration
hgs
parents: 51
diff changeset
   108
	TTime timeStart;
hgs
parents: 51
diff changeset
   109
	timeStart.HomeTime();
hgs
parents: 51
diff changeset
   110
	const TInt paramCount = aParameters.Count();
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
#ifdef _DEBUG
52
hgs
parents: 51
diff changeset
   113
	TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - START - command: %S, paramCount: %d, this: 0x%08x"), &aCommand, paramCount, this ) );
hgs
parents: 51
diff changeset
   114
	for (TInt i = 0; i < paramCount; i++)
hgs
parents: 51
diff changeset
   115
		{
hgs
parents: 51
diff changeset
   116
		const TPtrC pParam(aParameters[i]);
hgs
parents: 51
diff changeset
   117
		TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - param[%02d] = [%S]"), i, &pParam ) );
hgs
parents: 51
diff changeset
   118
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
#else
52
hgs
parents: 51
diff changeset
   120
	RDebug::Print( _L("[MemSpyCmdLine] COMMAND: [%S] {%02d}..."), &aCommand, paramCount );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
#endif
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
52
hgs
parents: 51
diff changeset
   123
	TFileName batchFile;
hgs
parents: 51
diff changeset
   124
	batchFile.Append(aCommand);
hgs
parents: 51
diff changeset
   125
hgs
parents: 51
diff changeset
   126
	TInt err = KErrNotSupported;
hgs
parents: 51
diff changeset
   127
	TInt error = KErrNotSupported;
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
52
hgs
parents: 51
diff changeset
   129
	// --- HELP
hgs
parents: 51
diff changeset
   130
	if ( aCommand.CompareF( KMemSpyCmdHelp1) == 0 || 
hgs
parents: 51
diff changeset
   131
		aCommand.CompareF(KMemSpyCmdHelp2) == 0 || 
hgs
parents: 51
diff changeset
   132
		aCommand.CompareF(KMemSpyCmdHelp3) == 0 || 
hgs
parents: 51
diff changeset
   133
		aCommand.CompareF(KMemSpyCmdHelp4) == 0)
hgs
parents: 51
diff changeset
   134
		{
62
hgs
parents: 54
diff changeset
   135
		PrintHelp();
52
hgs
parents: 51
diff changeset
   136
		}
hgs
parents: 51
diff changeset
   137
	// --- OUTPUT
hgs
parents: 51
diff changeset
   138
	//TODO: directory option to be added
hgs
parents: 51
diff changeset
   139
	else if (aCommand.CompareF(KMemSpyCmdOutput) == 0) //change output mode   
hgs
parents: 51
diff changeset
   140
		{
hgs
parents: 51
diff changeset
   141
		if (paramCount >= 1)
30
hgs
parents: 20
diff changeset
   142
			{
52
hgs
parents: 51
diff changeset
   143
			if (aParameters[0].CompareF(KMemSpyCmdOutputParameterFile) == 0)
30
hgs
parents: 20
diff changeset
   144
				{
52
hgs
parents: 51
diff changeset
   145
				if (paramCount == 2)
30
hgs
parents: 20
diff changeset
   146
					{
hgs
parents: 20
diff changeset
   147
					TBuf<KMaxFileName> directory;
52
hgs
parents: 51
diff changeset
   148
					directory.Copy(aParameters[1]);
hgs
parents: 51
diff changeset
   149
					iMemSpySession->SwitchOutputToFileL(directory);
30
hgs
parents: 20
diff changeset
   150
					}
hgs
parents: 20
diff changeset
   151
				else
hgs
parents: 20
diff changeset
   152
					{
52
hgs
parents: 51
diff changeset
   153
					iMemSpySession->SwitchOutputToFileL(KNullDesC);
30
hgs
parents: 20
diff changeset
   154
					}
hgs
parents: 20
diff changeset
   155
				}
hgs
parents: 20
diff changeset
   156
			else if( aParameters[0].CompareF( KMemSpyCmdOutputParameterTrace ) == 0)
hgs
parents: 20
diff changeset
   157
				{
hgs
parents: 20
diff changeset
   158
				TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - this: 0x%08x - Output Trace", this ) );
hgs
parents: 20
diff changeset
   159
				iMemSpySession->SwitchOutputToTraceL();
hgs
parents: 20
diff changeset
   160
				}
52
hgs
parents: 51
diff changeset
   161
			}
hgs
parents: 51
diff changeset
   162
		}
hgs
parents: 51
diff changeset
   163
	// --- HEAP DUMP    
hgs
parents: 51
diff changeset
   164
	else if (aCommand.CompareF(KMemSpyCmdHeapDump) == 0)
hgs
parents: 51
diff changeset
   165
		{
hgs
parents: 51
diff changeset
   166
		RedrawStatusMessage(KHeapDumpMessage);
hgs
parents: 51
diff changeset
   167
hgs
parents: 51
diff changeset
   168
		if (paramCount == 0) // no parameter - dump all heap data + kernel heap at the end
hgs
parents: 51
diff changeset
   169
			{
hgs
parents: 51
diff changeset
   170
hgs
parents: 51
diff changeset
   171
			TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - this: 0x%08x - Heap_Dump (all threads)", this ) );
30
hgs
parents: 20
diff changeset
   172
			// Dump heap data for all threads - Thread agnostic operation					
hgs
parents: 20
diff changeset
   173
			iMemSpySession->OutputHeapData();
hgs
parents: 20
diff changeset
   174
			// Dump kernel heap data
hgs
parents: 20
diff changeset
   175
			iMemSpySession->OutputThreadHeapDataL( KMemSpyClientServerThreadIdKernel );					
hgs
parents: 20
diff changeset
   176
			}
52
hgs
parents: 51
diff changeset
   177
		else if (paramCount >= 1)
30
hgs
parents: 20
diff changeset
   178
			{
52
hgs
parents: 51
diff changeset
   179
			if (aParameters[0].CompareF(KMemSpyCmdHeapDumpParameterAll) == 0)
30
hgs
parents: 20
diff changeset
   180
				{
52
hgs
parents: 51
diff changeset
   181
				iMemSpySession->OutputHeapData();
30
hgs
parents: 20
diff changeset
   182
				iMemSpySession->OutputThreadHeapDataL( KMemSpyClientServerThreadIdKernel );				
hgs
parents: 20
diff changeset
   183
				}
hgs
parents: 20
diff changeset
   184
			else if( aParameters[0].CompareF( KMemSpyCmdHeapDumpParameterKernel ) == 0 )
hgs
parents: 20
diff changeset
   185
				{
hgs
parents: 20
diff changeset
   186
				TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - this: 0x%08x - Heap_DumpKernel", this ) );
hgs
parents: 20
diff changeset
   187
				iMemSpySession->OutputThreadHeapDataL( KMemSpyClientServerThreadIdKernel );				
hgs
parents: 20
diff changeset
   188
				}
hgs
parents: 20
diff changeset
   189
			else
52
hgs
parents: 51
diff changeset
   190
				{
30
hgs
parents: 20
diff changeset
   191
				// Dump heap data for named thread - filter
52
hgs
parents: 51
diff changeset
   192
				const TPtrC pThreadName(aParameters[0]);
hgs
parents: 51
diff changeset
   193
				TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - this: 0x%08x - Heap_Dump (%S)"), this, &pThreadName ) );
hgs
parents: 51
diff changeset
   194
				iMemSpySession->OutputThreadHeapDataL(pThreadName);
30
hgs
parents: 20
diff changeset
   195
				}
52
hgs
parents: 51
diff changeset
   196
			}
30
hgs
parents: 20
diff changeset
   197
		}
52
hgs
parents: 51
diff changeset
   198
hgs
parents: 51
diff changeset
   199
	// --- SYSTEM WIDE MEMORY TRACKING    
hgs
parents: 51
diff changeset
   200
	else if (aCommand.CompareF(KMemSpyCmdSwmt) == 0)
hgs
parents: 51
diff changeset
   201
		{
hgs
parents: 51
diff changeset
   202
		RedrawStatusMessage(KSWMTMessage);
hgs
parents: 51
diff changeset
   203
hgs
parents: 51
diff changeset
   204
		TInt categories(0);
30
hgs
parents: 20
diff changeset
   205
		TName threadNameFilter;
52
hgs
parents: 51
diff changeset
   206
hgs
parents: 51
diff changeset
   207
		if (paramCount == 0) //default state -> "dumpnow" command with "all" categories
30
hgs
parents: 20
diff changeset
   208
			{
hgs
parents: 20
diff changeset
   209
			TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - this: 0x%08x - dumpnow command", this ) );
hgs
parents: 20
diff changeset
   210
			TInt category = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
52
hgs
parents: 51
diff changeset
   211
			iMemSpySession->SetSwmtCategoriesL(category);
hgs
parents: 51
diff changeset
   212
			iMemSpySession->ForceSwmtUpdateL();
30
hgs
parents: 20
diff changeset
   213
			}
52
hgs
parents: 51
diff changeset
   214
		else if (paramCount >= 1)
30
hgs
parents: 20
diff changeset
   215
			{
52
hgs
parents: 51
diff changeset
   216
			const TPtrC pParam(aParameters[0]);
hgs
parents: 51
diff changeset
   217
			if (pParam.CompareF(KMemSpyCmdSwmtParameterStarttimer) == 0) // "starttimer" - start tracking
30
hgs
parents: 20
diff changeset
   218
				{
hgs
parents: 20
diff changeset
   219
				TInt result(0);
hgs
parents: 20
diff changeset
   220
				categories = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
52
hgs
parents: 51
diff changeset
   221
				iMemSpySession->SetSwmtTimerIntervalL(KMemSpySysMemTrackerConfigMinTimerPeriod);
hgs
parents: 51
diff changeset
   222
hgs
parents: 51
diff changeset
   223
				if (paramCount >= 2) // user gave some optional parameters - <categories> or <value in seconds>
hgs
parents: 51
diff changeset
   224
					{
hgs
parents: 51
diff changeset
   225
					TLex lex(aParameters[1]);
hgs
parents: 51
diff changeset
   226
					if (lex.Val(result) == KErrNone) //if 2nd parameter is not number, then parse parameters
hgs
parents: 51
diff changeset
   227
						{
30
hgs
parents: 20
diff changeset
   228
						if( result >= KMemSpySysMemTrackerConfigMinTimerPeriod && result <= KMemSpySysMemTrackerConfigMaxTimerPeriod )
hgs
parents: 20
diff changeset
   229
							{
52
hgs
parents: 51
diff changeset
   230
							iMemSpySession->SetSwmtTimerIntervalL( result );							
hgs
parents: 51
diff changeset
   231
							}
hgs
parents: 51
diff changeset
   232
						}
hgs
parents: 51
diff changeset
   233
					TRAP( err, ParseSWMTParametersL( aParameters, categories, threadNameFilter) );
hgs
parents: 51
diff changeset
   234
					}
hgs
parents: 51
diff changeset
   235
30
hgs
parents: 20
diff changeset
   236
				//if( !err )
hgs
parents: 20
diff changeset
   237
				//	{
52
hgs
parents: 51
diff changeset
   238
				/*
hgs
parents: 51
diff changeset
   239
				 _LIT( KPressS, "Press 's' to stop the timer " );
hgs
parents: 51
diff changeset
   240
				 iConsole.Write( KPressS );
hgs
parents: 51
diff changeset
   241
				 
hgs
parents: 51
diff changeset
   242
				 iCommandPromptPos = iConsole.CursorPos();					
hgs
parents: 51
diff changeset
   243
				 RedrawInputPrompt();					
hgs
parents: 51
diff changeset
   244
				 WaitForInput();
hgs
parents: 51
diff changeset
   245
				 */
hgs
parents: 51
diff changeset
   246
hgs
parents: 51
diff changeset
   247
				iMemSpySession->StartSwmtTimerL();
hgs
parents: 51
diff changeset
   248
hgs
parents: 51
diff changeset
   249
				//CActiveScheduler::Start();									
30
hgs
parents: 20
diff changeset
   250
				//	}	
hgs
parents: 20
diff changeset
   251
				}
52
hgs
parents: 51
diff changeset
   252
			else if (pParam.CompareF(KMemSpyCmdSwmtParameterStoptimer) == 0) // "stoptime" - stop tracking
30
hgs
parents: 20
diff changeset
   253
				{
hgs
parents: 20
diff changeset
   254
				iMemSpySession->StopSwmtTimerL();
hgs
parents: 20
diff changeset
   255
				}
52
hgs
parents: 51
diff changeset
   256
			else if (pParam.CompareF(KMemSpyCmdSwmtParameterDumpnow) == 0) // "dumpnow" - runs one tracking cycle (CmdSWMT_ForceUpdate before)
30
hgs
parents: 20
diff changeset
   257
				{
hgs
parents: 20
diff changeset
   258
				categories = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
52
hgs
parents: 51
diff changeset
   259
				if (paramCount >= 2) // user gave some optional parameters - <categories>
30
hgs
parents: 20
diff changeset
   260
					{
hgs
parents: 20
diff changeset
   261
					TRAP( err, ParseSWMTParametersL( aParameters, categories, threadNameFilter) );
52
hgs
parents: 51
diff changeset
   262
					}
hgs
parents: 51
diff changeset
   263
hgs
parents: 51
diff changeset
   264
				if (!err)
30
hgs
parents: 20
diff changeset
   265
					{
52
hgs
parents: 51
diff changeset
   266
					iMemSpySession->SetSwmtCategoriesL(categories);
30
hgs
parents: 20
diff changeset
   267
					iMemSpySession->ForceSwmtUpdateL();
52
hgs
parents: 51
diff changeset
   268
					}
hgs
parents: 51
diff changeset
   269
				}
30
hgs
parents: 20
diff changeset
   270
			else //no parameters ("starttimer / stoptimer / dumpnow"), just categories / thread filter
52
hgs
parents: 51
diff changeset
   271
			//so dumpnow is used as default with category / thread specified
30
hgs
parents: 20
diff changeset
   272
				{
hgs
parents: 20
diff changeset
   273
				TRAP( err, ParseSWMTParametersL( aParameters, categories, threadNameFilter) );
52
hgs
parents: 51
diff changeset
   274
				if (!err)
30
hgs
parents: 20
diff changeset
   275
					{
52
hgs
parents: 51
diff changeset
   276
					iMemSpySession->SetSwmtCategoriesL(categories);
hgs
parents: 51
diff changeset
   277
					if (threadNameFilter.Length() > 0)
30
hgs
parents: 20
diff changeset
   278
						{
52
hgs
parents: 51
diff changeset
   279
						iMemSpySession->SetSwmtFilter(threadNameFilter);
30
hgs
parents: 20
diff changeset
   280
						}
52
hgs
parents: 51
diff changeset
   281
					}
hgs
parents: 51
diff changeset
   282
				iMemSpySession->ForceSwmtUpdateL();
30
hgs
parents: 20
diff changeset
   283
				}
hgs
parents: 20
diff changeset
   284
			}
52
hgs
parents: 51
diff changeset
   285
		}
hgs
parents: 51
diff changeset
   286
	// --- KILL SERVER
hgs
parents: 51
diff changeset
   287
	else if (aCommand.CompareF(KMemSpyCmdKillServer) == 0)
hgs
parents: 51
diff changeset
   288
		{
hgs
parents: 51
diff changeset
   289
		}
hgs
parents: 51
diff changeset
   290
hgs
parents: 51
diff changeset
   291
	// RedrawStatusMessage();   
hgs
parents: 51
diff changeset
   292
hgs
parents: 51
diff changeset
   293
	TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::PerformSingleOpL() - END - err: %d, this: 0x%08x, cmd: %S" ), err, this, &aCommand ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
52
hgs
parents: 51
diff changeset
   295
	// Calculate duration
hgs
parents: 51
diff changeset
   296
	TTime timeEnd;
hgs
parents: 51
diff changeset
   297
	timeEnd.HomeTime();
hgs
parents: 51
diff changeset
   298
	TTimeIntervalSeconds interval(0);
hgs
parents: 51
diff changeset
   299
	timeEnd.SecondsFrom(timeStart, interval);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
52
hgs
parents: 51
diff changeset
   301
	// Print some info
hgs
parents: 51
diff changeset
   302
	if (err != KErrNone)
hgs
parents: 51
diff changeset
   303
		{
hgs
parents: 51
diff changeset
   304
		RDebug::Print( _L("[MemSpyCmdLine] COMMAND: [%S] {%02d} {%08d sec} => ERROR: %d"), &aCommand, paramCount, interval.Int(), err );
hgs
parents: 51
diff changeset
   305
		}
hgs
parents: 51
diff changeset
   306
	else
hgs
parents: 51
diff changeset
   307
		{
hgs
parents: 51
diff changeset
   308
		RDebug::Print( _L("[MemSpyCmdLine] COMMAND: [%S] {%02d} {%08d sec} => OK"), &aCommand, paramCount, interval.Int() );
hgs
parents: 51
diff changeset
   309
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
52
hgs
parents: 51
diff changeset
   311
	// Spacer
hgs
parents: 51
diff changeset
   312
	RDebug::Printf(" ");
hgs
parents: 51
diff changeset
   313
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   315
void CMemSpyCommandLine::ConnectToMemSpyL()
52
hgs
parents: 51
diff changeset
   316
	{
hgs
parents: 51
diff changeset
   317
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - START - this: 0x%08x", this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
52
hgs
parents: 51
diff changeset
   319
	TInt err = iMemSpySession->Connect();
hgs
parents: 51
diff changeset
   320
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - connect #1 err: %d, this: 0x%08x", err, this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   321
52
hgs
parents: 51
diff changeset
   322
	if (err == KErrNotFound)
hgs
parents: 51
diff changeset
   323
		{
hgs
parents: 51
diff changeset
   324
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - launching MemSpy... - this: 0x%08x", this ) );
hgs
parents: 51
diff changeset
   325
		LaunchMemSpyL();
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   326
52
hgs
parents: 51
diff changeset
   327
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - launched MemSpy - this: 0x%08x", this ) );
hgs
parents: 51
diff changeset
   328
		err = iMemSpy->Connect();
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   329
52
hgs
parents: 51
diff changeset
   330
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - connect #2 err: %d, this: 0x%08x", err, this ) );
hgs
parents: 51
diff changeset
   331
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
52
hgs
parents: 51
diff changeset
   333
	User::LeaveIfError(err);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
52
hgs
parents: 51
diff changeset
   335
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ConnectToMemSpyL() - END - ok - this: 0x%08x", this ) );
hgs
parents: 51
diff changeset
   336
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
void CMemSpyCommandLine::LaunchMemSpyL()
52
hgs
parents: 51
diff changeset
   339
	{
hgs
parents: 51
diff changeset
   340
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - START - this: 0x%08x", this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
52
hgs
parents: 51
diff changeset
   342
	TInt err = KErrGeneral;
hgs
parents: 51
diff changeset
   343
	RProcess proc;
hgs
parents: 51
diff changeset
   344
hgs
parents: 51
diff changeset
   345
	// Try to run server first
hgs
parents: 51
diff changeset
   346
	err = proc.Create(KMemSpyProcessName0, KNullDesC);
hgs
parents: 51
diff changeset
   347
	if (err == KErrNone)
hgs
parents: 51
diff changeset
   348
		{
20
hgs
parents: 0
diff changeset
   349
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - Create server process successfully... - this: 0x%08x", this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   350
20
hgs
parents: 0
diff changeset
   351
		TRequestStatus status;
52
hgs
parents: 51
diff changeset
   352
		proc.Rendezvous(status);
20
hgs
parents: 0
diff changeset
   353
		proc.Resume();
hgs
parents: 0
diff changeset
   354
hgs
parents: 0
diff changeset
   355
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - MemSpy resumed, waiting for Rendezvous... - this: 0x%08x", this ) );
hgs
parents: 0
diff changeset
   356
52
hgs
parents: 51
diff changeset
   357
		User::WaitForRequest(status);
20
hgs
parents: 0
diff changeset
   358
		err = status.Int();
hgs
parents: 0
diff changeset
   359
		proc.Close();
hgs
parents: 0
diff changeset
   360
hgs
parents: 0
diff changeset
   361
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - Rendezvous complete: %d, this: 0x%08x", err, this ) );
52
hgs
parents: 51
diff changeset
   362
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   363
52
hgs
parents: 51
diff changeset
   364
	// If server is not available, try with s60 UI
hgs
parents: 51
diff changeset
   365
	if (err != KErrNone)
hgs
parents: 51
diff changeset
   366
		{
hgs
parents: 51
diff changeset
   367
		err = proc.Create(KMemSpyProcessName1, KNullDesC);
hgs
parents: 51
diff changeset
   368
		if (err == KErrNone)
20
hgs
parents: 0
diff changeset
   369
			{
hgs
parents: 0
diff changeset
   370
			TFullName fullName;
52
hgs
parents: 51
diff changeset
   371
			proc.FullName(fullName);
20
hgs
parents: 0
diff changeset
   372
			TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - Create S60 UI process successfully... - this: 0x%08x, name: %S"), this, &fullName ) );
52
hgs
parents: 51
diff changeset
   373
20
hgs
parents: 0
diff changeset
   374
			TRequestStatus status;
52
hgs
parents: 51
diff changeset
   375
			proc.Rendezvous(status);
20
hgs
parents: 0
diff changeset
   376
			proc.Resume();
52
hgs
parents: 51
diff changeset
   377
20
hgs
parents: 0
diff changeset
   378
			TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - MemSpy resumed, waiting for Rendezvous... - this: 0x%08x", this ) );
52
hgs
parents: 51
diff changeset
   379
			User::WaitForRequest(status);
20
hgs
parents: 0
diff changeset
   380
			err = status.Int();
hgs
parents: 0
diff changeset
   381
			proc.Close();
52
hgs
parents: 51
diff changeset
   382
20
hgs
parents: 0
diff changeset
   383
			TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - Rendezvous complete: %d, this: 0x%08x", err, this ) );
hgs
parents: 0
diff changeset
   384
			}
52
hgs
parents: 51
diff changeset
   385
		}
hgs
parents: 51
diff changeset
   386
hgs
parents: 51
diff changeset
   387
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - final error: %d, this: 0x%08x", err, this ) );
hgs
parents: 51
diff changeset
   388
	User::LeaveIfError(err);
hgs
parents: 51
diff changeset
   389
	User::After(10 * 1000000);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   390
52
hgs
parents: 51
diff changeset
   391
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::LaunchMemSpyL() - END - ok - this: 0x%08x", this ) );
hgs
parents: 51
diff changeset
   392
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   393
52
hgs
parents: 51
diff changeset
   394
CDesCArray* CMemSpyCommandLine::ReadLinesL(RFile& aFile)
hgs
parents: 51
diff changeset
   395
	{
hgs
parents: 51
diff changeset
   396
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - START - this: 0x%08x", this ) );
hgs
parents: 51
diff changeset
   397
	CDesCArrayFlat* lines = new (ELeave) CDesCArrayFlat(10);
hgs
parents: 51
diff changeset
   398
	CleanupStack::PushL(lines);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   399
52
hgs
parents: 51
diff changeset
   400
	TInt size = 0;
hgs
parents: 51
diff changeset
   401
	User::LeaveIfError(aFile.Size(size));
hgs
parents: 51
diff changeset
   402
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x, file size: %d", this, size ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   403
52
hgs
parents: 51
diff changeset
   404
	// Read file
hgs
parents: 51
diff changeset
   405
	HBufC8* narrowBuf = HBufC8::NewLC(size);
hgs
parents: 51
diff changeset
   406
	TPtr8 pBufNarrow(narrowBuf->Des());
hgs
parents: 51
diff changeset
   407
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x, reading file..." ) );
hgs
parents: 51
diff changeset
   408
	User::LeaveIfError(aFile.Read(pBufNarrow));
hgs
parents: 51
diff changeset
   409
	if (pBufNarrow.Length() <= 2)
hgs
parents: 51
diff changeset
   410
		{
hgs
parents: 51
diff changeset
   411
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x - BAD FILE LENGTH", this ) );
hgs
parents: 51
diff changeset
   412
		User::Leave(KErrCorrupt);
hgs
parents: 51
diff changeset
   413
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
52
hgs
parents: 51
diff changeset
   415
	// Look for BOM and convert to unicode
hgs
parents: 51
diff changeset
   416
	HBufC* unicodeText = HBufC::NewL(size);
hgs
parents: 51
diff changeset
   417
	TPtr pUnicodeText(unicodeText->Des());
hgs
parents: 51
diff changeset
   418
	if (pBufNarrow[0] == 0xFF && pBufNarrow[1] == 0xFE)
hgs
parents: 51
diff changeset
   419
		{
hgs
parents: 51
diff changeset
   420
		// It's unicode... and we don't want the BOM, hence -2
hgs
parents: 51
diff changeset
   421
		const TInt textLength = size - 2;
hgs
parents: 51
diff changeset
   422
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x - UNICODE TEXT - textLength: %d", this, textLength / 2 ) );
hgs
parents: 51
diff changeset
   423
		Mem::Copy( (TUint8 *)pUnicodeText.Ptr(), pBufNarrow.Ptr() + 2, textLength );
hgs
parents: 51
diff changeset
   424
		pUnicodeText.SetLength(textLength / 2);
hgs
parents: 51
diff changeset
   425
		}
hgs
parents: 51
diff changeset
   426
	else
hgs
parents: 51
diff changeset
   427
		{
hgs
parents: 51
diff changeset
   428
		// It's ASCII, convert it to unicode...
hgs
parents: 51
diff changeset
   429
		TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x - ASCII TEXT - textLength: %d", this, size ) );
hgs
parents: 51
diff changeset
   430
		for (TInt i = 0; i < size; i++)
hgs
parents: 51
diff changeset
   431
			{
hgs
parents: 51
diff changeset
   432
			pUnicodeText.Append(pBufNarrow[i]);
hgs
parents: 51
diff changeset
   433
			}
hgs
parents: 51
diff changeset
   434
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   435
52
hgs
parents: 51
diff changeset
   436
	// Discard old narrow text
hgs
parents: 51
diff changeset
   437
	CleanupStack::PopAndDestroy(narrowBuf);
hgs
parents: 51
diff changeset
   438
	CleanupStack::PushL(unicodeText);
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   439
52
hgs
parents: 51
diff changeset
   440
	// Try to extract lines of text...
hgs
parents: 51
diff changeset
   441
	HBufC* line = HBufC::NewLC(1024);
hgs
parents: 51
diff changeset
   442
	TPtr pLine(line->Des());
hgs
parents: 51
diff changeset
   443
	const TInt length = unicodeText->Length();
hgs
parents: 51
diff changeset
   444
	for (TInt i = 0; i < length; i++)
hgs
parents: 51
diff changeset
   445
		{
hgs
parents: 51
diff changeset
   446
		const TChar c(pUnicodeText[i]);
hgs
parents: 51
diff changeset
   447
		//
hgs
parents: 51
diff changeset
   448
		if (c == '\r' || c == '\n')
hgs
parents: 51
diff changeset
   449
			{
hgs
parents: 51
diff changeset
   450
			pLine.Trim();
hgs
parents: 51
diff changeset
   451
			if (pLine.Length())
hgs
parents: 51
diff changeset
   452
				{
hgs
parents: 51
diff changeset
   453
				TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x - LINE[%03d] %S"), this, lines->Count(), line ) );
hgs
parents: 51
diff changeset
   454
				lines->AppendL(pLine);
hgs
parents: 51
diff changeset
   455
				}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   456
52
hgs
parents: 51
diff changeset
   457
			pLine.Zero();
hgs
parents: 51
diff changeset
   458
			}
hgs
parents: 51
diff changeset
   459
		else
hgs
parents: 51
diff changeset
   460
			{
hgs
parents: 51
diff changeset
   461
			pLine.Append(c);
hgs
parents: 51
diff changeset
   462
			}
hgs
parents: 51
diff changeset
   463
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   464
52
hgs
parents: 51
diff changeset
   465
	// Save last line, just in cae it didn't end with a CR/LF
hgs
parents: 51
diff changeset
   466
	pLine.Trim();
hgs
parents: 51
diff changeset
   467
	if (pLine.Length())
hgs
parents: 51
diff changeset
   468
		{
hgs
parents: 51
diff changeset
   469
		TRACE( RDebug::Print( _L("[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - this: 0x%08x - LINE[%03d] %S"), this, lines->Count(), line ) );
hgs
parents: 51
diff changeset
   470
		lines->AppendL(pLine);
hgs
parents: 51
diff changeset
   471
		}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   472
52
hgs
parents: 51
diff changeset
   473
	CleanupStack::PopAndDestroy(2, unicodeText); // line & unicodeText
hgs
parents: 51
diff changeset
   474
	CleanupStack::Pop(lines);
hgs
parents: 51
diff changeset
   475
	TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine::ReadLinesL() - END - this: 0x%08x", this ) );
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   476
52
hgs
parents: 51
diff changeset
   477
	return lines;
hgs
parents: 51
diff changeset
   478
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   479
52
hgs
parents: 51
diff changeset
   480
void CMemSpyCommandLine::ParseSWMTParametersL(const CDesCArray& aParameters,TInt& aCategories, TDes& aFilter)
hgs
parents: 51
diff changeset
   481
	{
hgs
parents: 51
diff changeset
   482
	TInt result(0);
hgs
parents: 51
diff changeset
   483
	// Check if the first parameter is a number.
hgs
parents: 51
diff changeset
   484
	// In that case other parameters are ignored.
hgs
parents: 51
diff changeset
   485
	TLex lex(aParameters[0]);
hgs
parents: 51
diff changeset
   486
	if (lex.Val(result) != KErrNone)
hgs
parents: 51
diff changeset
   487
		{
hgs
parents: 51
diff changeset
   488
		// Parameters were given in text form:
hgs
parents: 51
diff changeset
   489
		const TInt count(aParameters.Count());
hgs
parents: 51
diff changeset
   490
		for (TInt i = 0; i < count; i++)
hgs
parents: 51
diff changeset
   491
			{
hgs
parents: 51
diff changeset
   492
			lex = aParameters[i]; //check if num.
hgs
parents: 51
diff changeset
   493
			if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeHeap) == 0)
hgs
parents: 51
diff changeset
   494
				result
hgs
parents: 51
diff changeset
   495
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap;
hgs
parents: 51
diff changeset
   496
			//| TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHeap;
hgs
parents: 51
diff changeset
   497
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeChunk) == 0)
hgs
parents: 51
diff changeset
   498
				result
hgs
parents: 51
diff changeset
   499
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryLocalChunks
hgs
parents: 51
diff changeset
   500
								| TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalChunks;
hgs
parents: 51
diff changeset
   501
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeCode) == 0)
hgs
parents: 51
diff changeset
   502
				result
hgs
parents: 51
diff changeset
   503
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMLoadedCode;
hgs
parents: 51
diff changeset
   504
			//else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeStack) == 0)
hgs
parents: 51
diff changeset
   505
			//	result
hgs
parents: 51
diff changeset
   506
			//			|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks;
hgs
parents: 51
diff changeset
   507
			//else if ( aParameters[i].CompareF( KMemSpyCmdSWMTTypeGlobalData ) == 0 )
hgs
parents: 51
diff changeset
   508
			//    result |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData;
hgs
parents: 51
diff changeset
   509
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeRamDrive) == 0)
hgs
parents: 51
diff changeset
   510
				result
hgs
parents: 51
diff changeset
   511
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMDrive;
hgs
parents: 51
diff changeset
   512
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeOpenFile) == 0)
hgs
parents: 51
diff changeset
   513
				result
hgs
parents: 51
diff changeset
   514
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryOpenFiles;
hgs
parents: 51
diff changeset
   515
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeDiskSpace) == 0)
hgs
parents: 51
diff changeset
   516
				result
hgs
parents: 51
diff changeset
   517
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryDiskusage;
hgs
parents: 51
diff changeset
   518
			//else if ( aParameters[i].CompareF( KMemSpyCmdSWMTTypeFbserv ) == 0 ) // enables both FABS and BITM 
hgs
parents: 51
diff changeset
   519
			//    result |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryBitmapHandles;
hgs
parents: 51
diff changeset
   520
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeHandleGeneric)
hgs
parents: 51
diff changeset
   521
					== 0) // enables both HGEN and HPAS
hgs
parents: 51
diff changeset
   522
				result
hgs
parents: 51
diff changeset
   523
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHandles;
hgs
parents: 51
diff changeset
   524
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeFileServerCache)
hgs
parents: 51
diff changeset
   525
					== 0)
hgs
parents: 51
diff changeset
   526
				result
hgs
parents: 51
diff changeset
   527
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryFileServerCache;
hgs
parents: 51
diff changeset
   528
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeSystemMemory)
hgs
parents: 51
diff changeset
   529
					== 0)
hgs
parents: 51
diff changeset
   530
				result
hgs
parents: 51
diff changeset
   531
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory;
hgs
parents: 51
diff changeset
   532
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeWindowGroup)
hgs
parents: 51
diff changeset
   533
					== 0)
hgs
parents: 51
diff changeset
   534
				result
hgs
parents: 51
diff changeset
   535
						|= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryWindowGroups;
hgs
parents: 51
diff changeset
   536
			else if (aParameters[i].CompareF(KMemSpyCmdSWMTTypeAll) == 0) //"all" category added
hgs
parents: 51
diff changeset
   537
				result
hgs
parents: 51
diff changeset
   538
						= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
hgs
parents: 51
diff changeset
   539
			else if (aParameters[i].CompareF(KMemSpyCmdSwmtParameterDumpnow)
hgs
parents: 51
diff changeset
   540
					== 0 || aParameters[i].CompareF(
hgs
parents: 51
diff changeset
   541
					KMemSpyCmdSwmtParameterStarttimer) == 0
hgs
parents: 51
diff changeset
   542
					|| aParameters[i].CompareF(KMemSpyCmdSwmtParameterStoptimer)
hgs
parents: 51
diff changeset
   543
							== 0)
hgs
parents: 51
diff changeset
   544
				{
hgs
parents: 51
diff changeset
   545
				TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine:: command parameter") );
hgs
parents: 51
diff changeset
   546
				}
hgs
parents: 51
diff changeset
   547
			else if (lex.Val(result) == KErrNone)
hgs
parents: 51
diff changeset
   548
				{
hgs
parents: 51
diff changeset
   549
				TRACE( RDebug::Printf( "[MemSpyCmdLine] CMemSpyCommandLine:: number - timer period") );
hgs
parents: 51
diff changeset
   550
				}
hgs
parents: 51
diff changeset
   551
			else// if ( aParameters[i].Find( KMemSpyCmdSWMTTypeHeapFilter ) == 0 )
hgs
parents: 51
diff changeset
   552
				{
hgs
parents: 51
diff changeset
   553
				aFilter.Copy(aParameters[i].Right(aParameters[i].Length() - 11));
hgs
parents: 51
diff changeset
   554
				}
hgs
parents: 51
diff changeset
   555
			/*  else
hgs
parents: 51
diff changeset
   556
			 {
hgs
parents: 51
diff changeset
   557
			 //User::Leave( KErrNotSupported );            	            
hgs
parents: 51
diff changeset
   558
			 }*/
hgs
parents: 51
diff changeset
   559
			}
hgs
parents: 51
diff changeset
   560
		}
hgs
parents: 51
diff changeset
   561
	else if (aParameters.Count() > 1)//&& aParameters[1].Find( KMemSpyCmdSWMTTypeHeapFilter ) == 0 )
hgs
parents: 51
diff changeset
   562
		{
hgs
parents: 51
diff changeset
   563
		aFilter.Copy(aParameters[1].Right(aParameters[1].Length() - 11));
hgs
parents: 51
diff changeset
   564
		}
hgs
parents: 51
diff changeset
   565
	aCategories = result;
hgs
parents: 51
diff changeset
   566
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   567
52
hgs
parents: 51
diff changeset
   568
TInt CMemSpyCommandLine::FindBatchFile(TDes &aFileName)
hgs
parents: 51
diff changeset
   569
	{
hgs
parents: 51
diff changeset
   570
	if ( BaflUtils::FileExists( iFsSession, aFileName )) return KErrNone;
hgs
parents: 51
diff changeset
   571
	if ( !FindFile( aFileName, _L("\\") ) ) return KErrNone;
hgs
parents: 51
diff changeset
   572
	if ( !FindFile( aFileName, _L("\\data\\") ) ) return KErrNone;
hgs
parents: 51
diff changeset
   573
	if (!FindFile(aFileName, _L("\\documents\\"))) return KErrNone;
hgs
parents: 51
diff changeset
   574
	if (!FindFile(aFileName, _L("\\temp\\"))) return KErrNone;
hgs
parents: 51
diff changeset
   575
	if (!FindFile(aFileName, _L("\\system\\temp\\"))) return KErrNone;
hgs
parents: 51
diff changeset
   576
	// if ( !FindFile( aFileName, _L("\\private\\1000484b\\") ) ) return KErrNone; // Mail folder KErrPermissionDenied  
hgs
parents: 51
diff changeset
   577
	return KErrNotFound;
hgs
parents: 51
diff changeset
   578
	}
0
a03f92240627 Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   579
52
hgs
parents: 51
diff changeset
   580
TInt CMemSpyCommandLine::FindFile(TDes &aFileName, const TDesC &aDirPath)
hgs
parents: 51
diff changeset
   581
	{
hgs
parents: 51
diff changeset
   582
	TFindFile fileFinder(iFsSession);
hgs
parents: 51
diff changeset
   583
	TInt err = fileFinder.FindByDir(aFileName, aDirPath);
hgs
parents: 51
diff changeset
   584
	if (!err)
hgs
parents: 51
diff changeset
   585
		{
hgs
parents: 51
diff changeset
   586
		aFileName.Copy(fileFinder.File());
hgs
parents: 51
diff changeset
   587
		}
hgs
parents: 51
diff changeset
   588
	return err;
hgs
parents: 51
diff changeset
   589
	}
30
hgs
parents: 20
diff changeset
   590
hgs
parents: 20
diff changeset
   591
//CLI status messages methods
hgs
parents: 20
diff changeset
   592
void CMemSpyCommandLine::RedrawInputPrompt()
52
hgs
parents: 51
diff changeset
   593
	{
hgs
parents: 51
diff changeset
   594
	iConsole.SetCursorPosAbs(iCommandPromptPos);
hgs
parents: 51
diff changeset
   595
	iConsole.ClearToEndOfLine();
hgs
parents: 51
diff changeset
   596
	iConsole.Printf(KMemSpyCLIInputPrompt, &iCommandBuffer);
hgs
parents: 51
diff changeset
   597
	}
30
hgs
parents: 20
diff changeset
   598
hgs
parents: 20
diff changeset
   599
void CMemSpyCommandLine::RedrawStatusMessage()
52
hgs
parents: 51
diff changeset
   600
	{
hgs
parents: 51
diff changeset
   601
	RedrawStatusMessage(KNullDesC);
hgs
parents: 51
diff changeset
   602
	}
30
hgs
parents: 20
diff changeset
   603
52
hgs
parents: 51
diff changeset
   604
void CMemSpyCommandLine::RedrawStatusMessage(const TDesC& aMessage)
hgs
parents: 51
diff changeset
   605
	{
hgs
parents: 51
diff changeset
   606
	iConsole.SetCursorPosAbs(iStatusMessagePos);
hgs
parents: 51
diff changeset
   607
	iConsole.ClearToEndOfLine();
hgs
parents: 51
diff changeset
   608
	iConsole.Write(aMessage);
hgs
parents: 51
diff changeset
   609
	iConsole.Write(KMemSpyCLINewLine);
hgs
parents: 51
diff changeset
   610
	}
30
hgs
parents: 20
diff changeset
   611
hgs
parents: 20
diff changeset
   612
void CMemSpyCommandLine::WaitForInput()
52
hgs
parents: 51
diff changeset
   613
	{
hgs
parents: 51
diff changeset
   614
	ASSERT( !IsActive() );
hgs
parents: 51
diff changeset
   615
	iConsole.Read(iStatus);
hgs
parents: 51
diff changeset
   616
	SetActive();
hgs
parents: 51
diff changeset
   617
	}
30
hgs
parents: 20
diff changeset
   618
hgs
parents: 20
diff changeset
   619
void CMemSpyCommandLine::DoCancel()
52
hgs
parents: 51
diff changeset
   620
	{
hgs
parents: 51
diff changeset
   621
	iConsole.ReadCancel();
hgs
parents: 51
diff changeset
   622
	}
30
hgs
parents: 20
diff changeset
   623
hgs
parents: 20
diff changeset
   624
void CMemSpyCommandLine::RunL()
52
hgs
parents: 51
diff changeset
   625
	{
hgs
parents: 51
diff changeset
   626
	TKeyCode key = iConsole.KeyCode();
hgs
parents: 51
diff changeset
   627
	//
hgs
parents: 51
diff changeset
   628
	if  ( key == EKeyEnter || key == KMemSpyUiS60KeyCodeButtonOk || key == KMemSpyUiS60KeyCodeRockerEnter )
hgs
parents: 51
diff changeset
   629
		{
hgs
parents: 51
diff changeset
   630
		TRAP_IGNORE( ProcessCommandBufferL() );
hgs
parents: 51
diff changeset
   631
		}
hgs
parents: 51
diff changeset
   632
	else
hgs
parents: 51
diff changeset
   633
		{
hgs
parents: 51
diff changeset
   634
		TChar character(key);
hgs
parents: 51
diff changeset
   635
		if (character.IsPrint())
hgs
parents: 51
diff changeset
   636
			{
hgs
parents: 51
diff changeset
   637
			if (iCommandBuffer.Length() < iCommandBuffer.MaxLength())
hgs
parents: 51
diff changeset
   638
				{
hgs
parents: 51
diff changeset
   639
				iCommandBuffer.Append(TChar(key));
hgs
parents: 51
diff changeset
   640
				}
30
hgs
parents: 20
diff changeset
   641
52
hgs
parents: 51
diff changeset
   642
			RedrawInputPrompt();
hgs
parents: 51
diff changeset
   643
			}
hgs
parents: 51
diff changeset
   644
		}
30
hgs
parents: 20
diff changeset
   645
52
hgs
parents: 51
diff changeset
   646
	WaitForInput();
hgs
parents: 51
diff changeset
   647
	}
30
hgs
parents: 20
diff changeset
   648
52
hgs
parents: 51
diff changeset
   649
TInt CMemSpyCommandLine::RunError(TInt aError)
hgs
parents: 51
diff changeset
   650
	{
30
hgs
parents: 20
diff changeset
   651
	return KErrNone;
hgs
parents: 20
diff changeset
   652
	}
hgs
parents: 20
diff changeset
   653
hgs
parents: 20
diff changeset
   654
void CMemSpyCommandLine::ProcessCommandBufferL()
52
hgs
parents: 51
diff changeset
   655
	{
hgs
parents: 51
diff changeset
   656
	iCommandBuffer.Trim();
hgs
parents: 51
diff changeset
   657
	//
30
hgs
parents: 20
diff changeset
   658
#ifdef _DEBUG
52
hgs
parents: 51
diff changeset
   659
	RDebug::Print( _L("[MCon] CMemSpyConsoleMenu::ProcessCommandBufferL() - cmd: [%S]"), &iCommandBuffer );
30
hgs
parents: 20
diff changeset
   660
#endif
52
hgs
parents: 51
diff changeset
   661
	//
hgs
parents: 51
diff changeset
   662
	TBool validCommand = EFalse;
hgs
parents: 51
diff changeset
   663
	if (iCommandBuffer.Length() == 1)
hgs
parents: 51
diff changeset
   664
		{
hgs
parents: 51
diff changeset
   665
		// Reset if not recognised...
hgs
parents: 51
diff changeset
   666
		validCommand = ETrue;
30
hgs
parents: 20
diff changeset
   667
52
hgs
parents: 51
diff changeset
   668
		const TChar cmd = iCommandBuffer[0];
hgs
parents: 51
diff changeset
   669
		switch (cmd)
hgs
parents: 51
diff changeset
   670
			{
hgs
parents: 51
diff changeset
   671
			case 's':
hgs
parents: 51
diff changeset
   672
			case 'S':
hgs
parents: 51
diff changeset
   673
				{
hgs
parents: 51
diff changeset
   674
				iMemSpy->PerformOperation( EMemSpyClientServerOpSystemWideMemoryTrackingTimerStop );
hgs
parents: 51
diff changeset
   675
hgs
parents: 51
diff changeset
   676
				CActiveScheduler::Stop();
hgs
parents: 51
diff changeset
   677
				return;
hgs
parents: 51
diff changeset
   678
				}
hgs
parents: 51
diff changeset
   679
			case 'c':
hgs
parents: 51
diff changeset
   680
			case 'C':
hgs
parents: 51
diff changeset
   681
				CActiveScheduler::Stop();
hgs
parents: 51
diff changeset
   682
				return;
hgs
parents: 51
diff changeset
   683
			default:
hgs
parents: 51
diff changeset
   684
				validCommand = EFalse;
hgs
parents: 51
diff changeset
   685
				break;
hgs
parents: 51
diff changeset
   686
			}
hgs
parents: 51
diff changeset
   687
		}
hgs
parents: 51
diff changeset
   688
	if (!validCommand)
hgs
parents: 51
diff changeset
   689
		{
hgs
parents: 51
diff changeset
   690
		_LIT( KInvalidEntry, "*** ERROR - Invalid Command ***" );
hgs
parents: 51
diff changeset
   691
		RedrawStatusMessage(KInvalidEntry);
hgs
parents: 51
diff changeset
   692
		RedrawInputPrompt();
hgs
parents: 51
diff changeset
   693
		}
hgs
parents: 51
diff changeset
   694
	}
62
hgs
parents: 54
diff changeset
   695
hgs
parents: 54
diff changeset
   696
hgs
parents: 54
diff changeset
   697
void CMemSpyCommandLine::PrintHelp()
hgs
parents: 54
diff changeset
   698
	{
hgs
parents: 54
diff changeset
   699
	iConsole.Write(KHelpMessage);
hgs
parents: 54
diff changeset
   700
	iConsole.Write(KMemSpyCLINewLine);
hgs
parents: 54
diff changeset
   701
	iConsole.Write(KHelpOutputCommand);
hgs
parents: 54
diff changeset
   702
	iConsole.Write(KHelpOutputToFileCommand);
hgs
parents: 54
diff changeset
   703
	iConsole.Write(KHelpHeapDumpCommand);
hgs
parents: 54
diff changeset
   704
	iConsole.Write(KHelpSwmtCommand);
hgs
parents: 54
diff changeset
   705
	iConsole.Write(KHelpKillServerCommand);
hgs
parents: 54
diff changeset
   706
	iConsole.Write(KMemSpyCLINewLine);
hgs
parents: 54
diff changeset
   707
	iConsole.Write(KHelpCommand);
hgs
parents: 54
diff changeset
   708
hgs
parents: 54
diff changeset
   709
	// Show input prompt.
hgs
parents: 54
diff changeset
   710
	iCommandPromptPos = iConsole.CursorPos();
hgs
parents: 54
diff changeset
   711
	RedrawInputPrompt();
hgs
parents: 54
diff changeset
   712
	WaitForInput();
hgs
parents: 54
diff changeset
   713
hgs
parents: 54
diff changeset
   714
	CActiveScheduler::Start();
hgs
parents: 54
diff changeset
   715
	}