|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Help class for debugging/optimizing the command stream. |
|
15 * This is file is not compiled by default. Enable flag |
|
16 * _ALF_PRINT_WS_COMMANDS_ in alfrenderstageplugin.mmp in order |
|
17 * to use it. |
|
18 * |
|
19 * SEE USAGE INSTRUCTIONS IN ALRCOMMANDDEBUG.H |
|
20 */ |
|
21 #include <e32def.h> |
|
22 #include <barsread.h> |
|
23 #include <barsc.h> |
|
24 #include <ConeResLoader.h> |
|
25 #include <s32mem.h> // RDesWriteStream |
|
26 #include <alflogger.h> |
|
27 #include <huiwscanvascommands.h> |
|
28 #include "alfcommanddebug.h" |
|
29 #include <data_caging_path_literals.hrh> |
|
30 #include <alfcommanddescriptions.rsg> |
|
31 #include <gdi.h> |
|
32 #include <uiacceltk/HuiStatic.h> |
|
33 |
|
34 _LIT( KRendererCommandDescriptions,"alfcommanddescriptions.rsc" ); |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // ReadCommandDescriptionsL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CAlfCommandDebug* CAlfCommandDebug::NewL() |
|
41 { |
|
42 CAlfCommandDebug* self = new (ELeave) CAlfCommandDebug; |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // ConstructL |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 void CAlfCommandDebug::ConstructL() |
|
54 { |
|
55 iCommandDescriptions = new (ELeave) RHashMap<TUint32, TCommand> ; |
|
56 iBridgeCommandDescriptions = new (ELeave) RHashMap<TUint32, TCommand> ; |
|
57 ReadCommandDescriptionsL( iCommandDescriptions, R_ALF_COMMAND_DESCRIPTION_ARRAY ); |
|
58 ReadCommandDescriptionsL( iBridgeCommandDescriptions, R_ALF_BRIDGE_COMMAND_DESCRIPTION_ARRAY ); |
|
59 |
|
60 // TODO: define only exe name, TrackProcess can do the parsing |
|
61 #ifdef __WINSCW__ |
|
62 _LIT( KTrackThisProcess, "Z:\\sys\\bin\\matrixmenu.exe"); |
|
63 #else |
|
64 _LIT( KTrackThisProcess, "C:\\sys\\bin\\matrixmenu.exe"); |
|
65 #endif |
|
66 iTrackedProcess.Copy( KTrackThisProcess ); |
|
67 |
|
68 // iMode = EPrintOnlyCommands; |
|
69 iMode = EPrintCommandParameters; |
|
70 // iMode = EPrintSummary; |
|
71 //iMode = EPrintStatisticsForLargeBuffers; |
|
72 |
|
73 switch( iMode ) |
|
74 { |
|
75 default: // 0 |
|
76 { |
|
77 iPrint = EFalse; |
|
78 break; |
|
79 } |
|
80 case EPrintCommandParameters: |
|
81 { |
|
82 iPrintColors = ETrue; |
|
83 iPrintRegions = ETrue; |
|
84 iPrintRects = ETrue; |
|
85 iPrintPoints = ETrue; |
|
86 iPrintHandles = ETrue; |
|
87 iPrintTexts = ETrue; |
|
88 iPrint = ETrue; |
|
89 break; |
|
90 } |
|
91 case EPrintOnlyCommands: |
|
92 { |
|
93 iPrint = ETrue; |
|
94 break; |
|
95 } |
|
96 case EPrintStatistics: |
|
97 { |
|
98 iPrintStatistics = ETrue; |
|
99 iLargeBufferDefinition = 0; |
|
100 break; |
|
101 } |
|
102 case EPrintStatisticsForLargeBuffers: |
|
103 { |
|
104 iPrintStatistics = ETrue; |
|
105 iLargeBufferDefinition = 1500; |
|
106 break; |
|
107 } |
|
108 case EPrintSummary: |
|
109 { |
|
110 iPrintSummary = ETrue; |
|
111 iLargeBufferDefinition = 0; |
|
112 break; |
|
113 } |
|
114 |
|
115 } |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // ReadCommandDescriptionsL |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CAlfCommandDebug::ReadCommandDescriptionsL( RHashMap<TUint32,TCommand>* aDescriptionArray, TInt aId ) |
|
123 { |
|
124 // Read unsupported command resource |
|
125 RFs fs; |
|
126 User::LeaveIfError(fs.Connect()); |
|
127 CleanupClosePushL(fs); |
|
128 RResourceFile resFile; |
|
129 TInt result; |
|
130 |
|
131 TFileName resourceFileName; |
|
132 TPtrC driveLetter = TParsePtrC(RProcess().FileName()).Drive(); |
|
133 resourceFileName.Copy(driveLetter); |
|
134 resourceFileName.Append(KDC_ECOM_RESOURCE_DIR); |
|
135 resourceFileName.Append(KRendererCommandDescriptions); |
|
136 |
|
137 TRAP( result, resFile.OpenL(fs,resourceFileName); ); |
|
138 if (result == KErrNone) |
|
139 { |
|
140 CleanupClosePushL(resFile); |
|
141 resFile.ConfirmSignatureL(0); // offset value. |
|
142 TInt resId = aId; |
|
143 |
|
144 HBufC8* readData = resFile.AllocReadL(resId); |
|
145 // now first get rid of RResourceFile and RFs as they are not needed any more |
|
146 CleanupStack::PopAndDestroy(); // resFile |
|
147 CleanupStack::PopAndDestroy(); // fs |
|
148 CleanupStack::PushL(readData); |
|
149 |
|
150 // now parse it and store the values in cmdTextArray |
|
151 TResourceReader reader; |
|
152 reader.SetBuffer(readData); |
|
153 const TInt count = reader.ReadInt16(); |
|
154 TInt8 commandId; |
|
155 for (TInt i = 0; i < count; i++) |
|
156 { |
|
157 commandId = reader.ReadInt8(); |
|
158 TCommand command; |
|
159 command.iDescription = reader.ReadHBufC16L(); |
|
160 |
|
161 aDescriptionArray->Insert(commandId, command); |
|
162 } |
|
163 CleanupStack::PopAndDestroy(readData); |
|
164 } |
|
165 else |
|
166 { |
|
167 __ALFLOGSTRING1("CAlfRsSendBuffer::ConstructL - WARNING! Failed to read unsupported commands from resource file: %S! Error code:st %d.", &resourceFileName ); |
|
168 CleanupStack::PopAndDestroy(); // fs |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // SetHandle |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C void CAlfCommandDebug::SetHandle( const TInt& aHandle ) |
|
177 { |
|
178 if (!iPrintHandles ) |
|
179 { |
|
180 return; |
|
181 } |
|
182 iText.AppendFormat( _L("Handle: [%d] "), aHandle ); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // SetPoint |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CAlfCommandDebug::SetPoint( const TPoint& aPoint ) |
|
190 { |
|
191 if (!iPrintPoints ) |
|
192 { |
|
193 return; |
|
194 } |
|
195 iText.AppendFormat( _L("Point: (%d,%d) "), aPoint.iX, aPoint.iY ); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // SetRect |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C void CAlfCommandDebug::SetRect( const TRect& aRect ) |
|
203 { |
|
204 if (!iPrintRects ) |
|
205 { |
|
206 return; |
|
207 } |
|
208 iText.AppendFormat( _L("Rect: (%d,%d)-(%d,%d) "), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // SetRegion |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CAlfCommandDebug::SetRegion( const TRegion& aRegion) |
|
216 { |
|
217 _LIT( KDescRegion, "Region of %d"); |
|
218 if (!iPrintRegions ) |
|
219 { |
|
220 return; |
|
221 } |
|
222 /*if ( iText.MaxLength() < iText.Length() + KDescRegion->Length() ) |
|
223 { |
|
224 return; |
|
225 }*/ |
|
226 iText.AppendFormat( KDescRegion, aRegion.Count() ); |
|
227 for( TInt i = 0; i < aRegion.Count() ; i++ ) |
|
228 { |
|
229 TRect rect = aRegion[i]; |
|
230 iText.AppendFormat( _L("[%d]: Rect: (%d,%d)-(%d,%d) "), i, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY ); |
|
231 } |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // SetRegion |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 EXPORT_C void CAlfCommandDebug::SetText( TPtr& aText ) |
|
239 { |
|
240 if (!iPrintTexts ) |
|
241 { |
|
242 return; |
|
243 } |
|
244 iText.AppendFormat( _L("Text: [%S] "), &aText ); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // SetColor |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 EXPORT_C void CAlfCommandDebug::SetColor( TRgb& aColor ) |
|
252 { |
|
253 if (!iPrintColors ) |
|
254 { |
|
255 return; |
|
256 } |
|
257 iText.AppendFormat( _L("Color: R[%d]G[%d]B[%d] A[%d] "), aColor.Red(), aColor.Green(), aColor.Blue(), aColor.Alpha() ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // Print |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 EXPORT_C void CAlfCommandDebug::Print() |
|
265 { |
|
266 if ( iPrint ) |
|
267 { |
|
268 RDebug::Print(_L("%S"), &iText ); |
|
269 } |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // AdjustCommand |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 EXPORT_C void CAlfCommandDebug::SetDescription(const TUint8& aCommand, TInt aDescriptionList ) |
|
277 { |
|
278 TInt32 commandId = aCommand; |
|
279 TCommand* command = NULL; |
|
280 |
|
281 if ( aDescriptionList == R_ALF_COMMAND_DESCRIPTION_ARRAY ) |
|
282 { |
|
283 command = iCommandDescriptions->Find(commandId); |
|
284 } |
|
285 else |
|
286 { |
|
287 // assuming, aDescriptionList is R_ALF_BRIDGE_COMMAND_DESCRIPTION_ARRAY |
|
288 command = iBridgeCommandDescriptions->Find(commandId); |
|
289 } |
|
290 iTotalCmdCount++; |
|
291 |
|
292 if (command ) |
|
293 { |
|
294 HBufC16* buf = command->iDescription; |
|
295 iText.Format( _L("Cmd: %S - "), buf ); |
|
296 } |
|
297 else |
|
298 { |
|
299 iText.Format( _L("Cmd: %d - "), aCommand ); |
|
300 } |
|
301 } |
|
302 // --------------------------------------------------------------------------- |
|
303 // PrintDescription |
|
304 // |
|
305 // Note, you can enable/disable command at run-time in debugger by modifying |
|
306 // printCommands variable. |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 EXPORT_C void CAlfCommandDebug::SetDescriptionAndSize(const TUint8& aCommand, |
|
310 const TInt& aParametersSize, TInt aDescriptionList ) |
|
311 { |
|
312 TInt32 commandId = aCommand; |
|
313 TCommand* command = NULL; |
|
314 |
|
315 if ( aDescriptionList == R_ALF_COMMAND_DESCRIPTION_ARRAY ) |
|
316 { |
|
317 command = iCommandDescriptions->Find(commandId); |
|
318 } |
|
319 else |
|
320 { |
|
321 // assuming, aDescriptionList is R_ALF_BRIDGE_COMMAND_DESCRIPTION_ARRAY |
|
322 command = iBridgeCommandDescriptions->Find(commandId); |
|
323 } |
|
324 |
|
325 if ( command ) |
|
326 { |
|
327 command->iCount++; |
|
328 command->iSize = sizeof(TUint8) + aParametersSize; |
|
329 iTotalCmdSize += command->iSize; |
|
330 } |
|
331 iTotalCmdCount++; |
|
332 |
|
333 if ( !iPrint ) |
|
334 { |
|
335 // empty the string. Otherwise parameters start piling up to iText |
|
336 iText.Format(_L("")); |
|
337 return; |
|
338 } |
|
339 |
|
340 if (command) |
|
341 { |
|
342 HBufC16* buf = command->iDescription; |
|
343 iText.Format( _L("Cmd: %S (%d/Size: %d) "), buf, aCommand, command->iSize ); |
|
344 } |
|
345 else |
|
346 { |
|
347 iText.Format( _L("Cmd: %d"), aCommand ); |
|
348 } |
|
349 |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // AdjustCommand |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 EXPORT_C void CAlfCommandDebug::AdjustCommand(const TUint8& aCommand, |
|
357 TInt aAdjustment) |
|
358 { |
|
359 TCommand* command = NULL; |
|
360 |
|
361 command = iCommandDescriptions->Find(aCommand); |
|
362 |
|
363 if (command) |
|
364 { |
|
365 command->iCount--; |
|
366 |
|
367 iTotalCmdCount--; |
|
368 iTotalCmdSize += aAdjustment; |
|
369 } |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // StartFrame |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 EXPORT_C void CAlfCommandDebug::StartFrame() |
|
377 { |
|
378 // clear statistics |
|
379 for (TInt i = 0; i < EAlfLastCommand; i++) |
|
380 { |
|
381 TCommand* command = iCommandDescriptions->Find(i); |
|
382 if (command) |
|
383 { |
|
384 command->iCount = 0; |
|
385 } |
|
386 } |
|
387 iTotalCmdCount = 0; |
|
388 iTotalCmdSize = 0; |
|
389 |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // EndFrame |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 EXPORT_C void CAlfCommandDebug::EndFrame() |
|
397 { |
|
398 if (iPrintSummary) |
|
399 { |
|
400 RDebug::Print(_L("CAlfCommandDebug::EndFrame, Commands: %d, Size %d"), |
|
401 iTotalCmdCount, |
|
402 iTotalCmdSize ); |
|
403 |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // PrintStatistic |
|
409 // |
|
410 // Note, you can enable iPrintStatistics at run-time in debugger |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 EXPORT_C void CAlfCommandDebug::PrintStatistic() |
|
414 { |
|
415 if (iPrintStatistics && iTotalCmdSize > iLargeBufferDefinition ) |
|
416 { |
|
417 for (TInt i = 0; i < EAlfLastCommand; i++) |
|
418 { |
|
419 TCommand* command = iCommandDescriptions->Find(i); |
|
420 if (command) |
|
421 { |
|
422 TInt totalSize = command->iCount * command->iSize; |
|
423 RDebug::Print( |
|
424 _L("Cmd: %S - Count: %d - Size: %d (%d)"), command->iDescription, |
|
425 command->iCount, totalSize, command->iSize); |
|
426 } |
|
427 } |
|
428 iFrameTotalSize += iTotalCmdSize; |
|
429 iFrameCount++; |
|
430 TInt averageFrame = iFrameTotalSize / iFrameCount; |
|
431 RDebug::Print(_L("Total, Count: %d, Size %d (average: %d)"), iTotalCmdCount, |
|
432 iTotalCmdSize, averageFrame); |
|
433 } |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // SetPrint |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 EXPORT_C void CAlfCommandDebug::SetPrint( TBool aPrint ) |
|
441 { |
|
442 iPrint = aPrint; |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------------------------- |
|
446 // destructor |
|
447 // |
|
448 // Note, you can enable iPrintStatistics at run-time in debugger |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 EXPORT_C CAlfCommandDebug::~CAlfCommandDebug() |
|
452 { |
|
453 delete iCommandDescriptions; |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------------------------- |
|
457 // DebugPrintControlGroupOrder |
|
458 // Can be used only from CAlfBridge |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 EXPORT_C TFileName CAlfCommandDebug::WServClientFileName( TInt aClientWindowGroupId, RWsSession& aSession ) |
|
462 { |
|
463 |
|
464 TFileName processName; |
|
465 if( aClientWindowGroupId != KErrNotFound || aClientWindowGroupId != 0 ) |
|
466 { |
|
467 TThreadId threadId; |
|
468 TInt error = aSession.GetWindowGroupClientThreadId( aClientWindowGroupId, threadId ); |
|
469 if( error ) |
|
470 { |
|
471 } |
|
472 else |
|
473 { |
|
474 RThread thread; |
|
475 TInt err = thread.Open( threadId ); |
|
476 if( !err ) |
|
477 { |
|
478 RProcess process; |
|
479 err = thread.Process( process ); |
|
480 if( !err ) |
|
481 { |
|
482 processName = process.FileName(); |
|
483 } |
|
484 process.Close(); |
|
485 } |
|
486 thread.Close(); |
|
487 } |
|
488 } |
|
489 return processName; |
|
490 } |
|
491 |
|
492 // --------------------------------------------------------------------------- |
|
493 // TrackProcess |
|
494 // --------------------------------------------------------------------------- |
|
495 // |
|
496 EXPORT_C TBool CAlfCommandDebug::TrackProcess( HBufC16* aFileName ) |
|
497 { |
|
498 // this is separate function to allow in the future tracking of multiple processes |
|
499 return aFileName->Compare( iTrackedProcess ) == 0; |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // Text |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 EXPORT_C TDesC16& CAlfCommandDebug::Text() |
|
507 { |
|
508 return iText; |
|
509 } |