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