|
1 /* |
|
2 * Copyright (c) 2007 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: Includes some common defines used in the GOOM monitor app |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef GOOMTRACES_H |
|
20 #define GOOMTRACES_H |
|
21 |
|
22 #include "traceconfiguration.hrh" |
|
23 #include "tracedefs.h" |
|
24 |
|
25 #ifdef TRACE_INTO_FILE |
|
26 #include <flogger.h> // RFileLogger |
|
27 #else |
|
28 #include <e32debug.h> // RDebug |
|
29 #endif |
|
30 |
|
31 |
|
32 //----------------------------------------------------------------------------- |
|
33 // Constants |
|
34 //----------------------------------------------------------------------------- |
|
35 // |
|
36 |
|
37 /** |
|
38 * Prefix error trace |
|
39 */ |
|
40 #define _PREFIX_ERROR( aMsg ) _PREFIX_TRACE( "[ERROR: %d]: " L##aMsg ) |
|
41 |
|
42 /** |
|
43 * Prefix info trace. |
|
44 */ |
|
45 #define _PREFIX_INFO( aMsg ) _PREFIX_TRACE( "[INFO]: " L##aMsg ) |
|
46 |
|
47 /** |
|
48 * Define needed directories if TRACE_INTO_FILE macro in use |
|
49 */ |
|
50 #ifdef TRACE_INTO_FILE |
|
51 |
|
52 _LIT( KDir, "goommonitor" ); |
|
53 _LIT( KFile, "goommonitor_log.txt" ); |
|
54 _LIT( KFullPath, "c:\\logs\\goommonitor\\" ); |
|
55 |
|
56 #endif |
|
57 |
|
58 //----------------------------------------------------------------------------- |
|
59 // Error trace macros |
|
60 //----------------------------------------------------------------------------- |
|
61 // |
|
62 #ifdef ERROR_TRACE |
|
63 |
|
64 /** |
|
65 * Error trace definitions. |
|
66 */ |
|
67 #ifdef TRACE_INTO_FILE |
|
68 |
|
69 #define ERROR( aErr, aMsg )\ |
|
70 {\ |
|
71 if( aErr < KErrNone )\ |
|
72 {\ |
|
73 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
74 _PREFIX_ERROR( aMsg ), aErr );\ |
|
75 }\ |
|
76 } |
|
77 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
78 {\ |
|
79 if( aErr < KErrNone )\ |
|
80 {\ |
|
81 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
82 _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
83 }\ |
|
84 } |
|
85 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
86 {\ |
|
87 if( aErr < KErrNone )\ |
|
88 {\ |
|
89 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
90 _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
91 }\ |
|
92 } |
|
93 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
94 {\ |
|
95 if( aErr < KErrNone )\ |
|
96 {\ |
|
97 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
98 _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
99 }\ |
|
100 } |
|
101 |
|
102 #else//TRACE_INTO_FILE not defined |
|
103 |
|
104 #define ERROR( aErr, aMsg )\ |
|
105 {\ |
|
106 if( aErr < KErrNone )\ |
|
107 {\ |
|
108 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\ |
|
109 }\ |
|
110 } |
|
111 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
112 {\ |
|
113 if( aErr < KErrNone )\ |
|
114 {\ |
|
115 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
116 }\ |
|
117 } |
|
118 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
119 {\ |
|
120 if( aErr < KErrNone )\ |
|
121 {\ |
|
122 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
123 }\ |
|
124 } |
|
125 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
126 {\ |
|
127 if( aErr < KErrNone )\ |
|
128 {\ |
|
129 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
130 }\ |
|
131 } |
|
132 |
|
133 #endif//TRACE_INTO_FILE |
|
134 |
|
135 #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg ) |
|
136 #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 ) |
|
137 #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 ) |
|
138 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 ) |
|
139 |
|
140 #define ERROR_PARAM(_p) _p |
|
141 |
|
142 #define TRAPD_ERR( aErr, aStmt ) TRAPD( aErr, aStmt ) |
|
143 #define TRAP_ERR( aErr, aStmt ) TRAP( aErr, aStmt ) |
|
144 |
|
145 #define TRAP_AND_LEAVE(_s,_t) \ |
|
146 { TRAPD(_e,_s); ERROR(_e,_t); User::LeaveIfError(_e); } |
|
147 |
|
148 #else//ERROR_TRACE not defined |
|
149 |
|
150 #define ERROR( aErr, aMsg ) |
|
151 #define ERROR_1( aErr, aMsg, aP1 ) |
|
152 #define ERROR_2( aErr, aMsg, aP1, aP2 ) |
|
153 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 ) |
|
154 #define ERROR_GEN( aMsg ) |
|
155 #define ERROR_GEN_1( aMsg, aP1 ) |
|
156 #define ERROR_GEN_2( aMsg, aP1, aP2 ) |
|
157 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) |
|
158 |
|
159 #define ERROR_PARAM(_p) |
|
160 |
|
161 #define TRAPD_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt ) |
|
162 #define TRAP_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt ) |
|
163 |
|
164 #define TRAP_AND_LEAVE(_s,_t) { _s; } |
|
165 |
|
166 #endif//ERROR_TRACE |
|
167 |
|
168 //----------------------------------------------------------------------------- |
|
169 // Info trace macros |
|
170 //----------------------------------------------------------------------------- |
|
171 // |
|
172 #ifdef INFO_TRACE |
|
173 |
|
174 /** |
|
175 * Info log message definitions. |
|
176 */ |
|
177 #ifdef TRACE_INTO_FILE |
|
178 |
|
179 #define TRACES( aMsg )\ |
|
180 {\ |
|
181 RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, \ |
|
182 _PREFIX_INFO( aMsg ) );\ |
|
183 } |
|
184 #define TRACES1( aMsg, aP1 )\ |
|
185 {\ |
|
186 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
187 _PREFIX_INFO( aMsg ), aP1 );\ |
|
188 } |
|
189 #define TRACES2( aMsg, aP1, aP2 )\ |
|
190 {\ |
|
191 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
192 _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
193 } |
|
194 #define TRACES3( aMsg, aP1, aP2, aP3 )\ |
|
195 {\ |
|
196 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
197 _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
198 } |
|
199 #define TRACES4( aMsg, aP1, aP2, aP3, aP4 )\ |
|
200 {\ |
|
201 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
202 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\ |
|
203 } |
|
204 #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 )\ |
|
205 {\ |
|
206 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
207 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\ |
|
208 } |
|
209 |
|
210 #else//TRACE_INTO_FILE not defined |
|
211 |
|
212 #define TRACES( aMsg )\ |
|
213 {\ |
|
214 RDebug::Print( _PREFIX_INFO( aMsg ) );\ |
|
215 } |
|
216 #define TRACES1( aMsg, aP1 )\ |
|
217 {\ |
|
218 RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\ |
|
219 } |
|
220 #define TRACES2( aMsg, aP1, aP2 )\ |
|
221 {\ |
|
222 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
223 } |
|
224 #define TRACES3( aMsg, aP1, aP2, aP3 )\ |
|
225 {\ |
|
226 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
227 } |
|
228 #define TRACES4( aMsg, aP1, aP2, aP3, aP4 )\ |
|
229 {\ |
|
230 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\ |
|
231 } |
|
232 #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 )\ |
|
233 {\ |
|
234 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\ |
|
235 } |
|
236 |
|
237 #endif//TRACE_INTO_FILE |
|
238 |
|
239 #define TRACES_PARAM( aParam ) aParam |
|
240 |
|
241 #else//INFO_TRACE not defined |
|
242 |
|
243 #define TRACES( aMsg ) |
|
244 #define TRACES1( aMsg, aP1 ) |
|
245 #define TRACES2( aMsg, aP1, aP2 ) |
|
246 #define TRACES3( aMsg, aP1, aP2, aP3 ) |
|
247 #define TRACES4( aMsg, aP1, aP2, aP3, aP4 ) |
|
248 #define TRACES5( aMsg, aP1, aP2, aP3, aP4, aP5 ) |
|
249 #define TRACES_PARAM( aParam ) |
|
250 |
|
251 #endif//INFO_TRACE |
|
252 |
|
253 //----------------------------------------------------------------------------- |
|
254 // Trace current client thread name and process id |
|
255 //----------------------------------------------------------------------------- |
|
256 // |
|
257 #ifdef CLIENT_TRACE |
|
258 |
|
259 #define CLIENT( aMessage )\ |
|
260 {\ |
|
261 RThread thread;\ |
|
262 TInt err = aMessage.Client( thread );\ |
|
263 if( err == KErrNone )\ |
|
264 {\ |
|
265 RProcess process;\ |
|
266 err = thread.Process( process );\ |
|
267 if( err == KErrNone )\ |
|
268 {\ |
|
269 TPtrC thredName( thread.Name() );\ |
|
270 TUid processUid( process.SecureId() );\ |
|
271 TRACES2( "Current client process UID: [%x], thread name: [%S]",\ |
|
272 processUid,\ |
|
273 &thredName );\ |
|
274 }\ |
|
275 process.Close();\ |
|
276 }\ |
|
277 thread.Close();\ |
|
278 } |
|
279 |
|
280 #else |
|
281 |
|
282 #define CLIENT( aMessage ) |
|
283 |
|
284 #endif |
|
285 |
|
286 //----------------------------------------------------------------------------- |
|
287 // Function trace macros |
|
288 //----------------------------------------------------------------------------- |
|
289 // |
|
290 #ifdef FUNC_TRACE |
|
291 |
|
292 #include <e32base.h> // TCleanupItem |
|
293 |
|
294 /** |
|
295 * Function logging definitions. |
|
296 */ |
|
297 #ifdef TRACE_INTO_FILE |
|
298 |
|
299 #define FUNC( aMsg, aP1 )\ |
|
300 {\ |
|
301 TPtrC8 trace( _S8( aMsg ) );\ |
|
302 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\ |
|
303 }\ |
|
304 |
|
305 #else//TRACE_INTO_FILE not defined |
|
306 |
|
307 #define FUNC( aMsg, aP1 )\ |
|
308 {\ |
|
309 RDebug::Printf( aMsg, aP1 );\ |
|
310 }\ |
|
311 |
|
312 #endif//TRACE_INTO_FILE |
|
313 |
|
314 /** |
|
315 * Function trace helper class. |
|
316 * |
|
317 * NOTE: |
|
318 * LC -methods cannot be trapped. Therefore if LC -method leaves |
|
319 * END trace is used instead of LEAVE trace. |
|
320 * If you have an idea how to round this problem please tell. |
|
321 */ |
|
322 _LIT8( KFuncNameTerminator, "(" ); |
|
323 _LIT8( KFuncLeavePatternL, "L" ); |
|
324 class TFuncLog |
|
325 { |
|
326 public: |
|
327 static void Cleanup( TAny* aPtr ) |
|
328 { |
|
329 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
330 self->iLeft = ETrue; |
|
331 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected |
|
332 } |
|
333 inline TFuncLog( const char* aFunc ) : |
|
334 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
335 iLeft( EFalse ), |
|
336 iCleanupItem( Cleanup, this ), |
|
337 iCanLeave( EFalse ) |
|
338 { |
|
339 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
340 if( pos != KErrNotFound ) |
|
341 { |
|
342 iFunc.Set( iFunc.Left( pos ) ); |
|
343 iCanLeave = !iFunc.Right( |
|
344 KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL ); |
|
345 if ( iCanLeave ) |
|
346 { |
|
347 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
348 } |
|
349 } |
|
350 FUNC( _PREFIX_CHAR("%S-START"), &iFunc ); |
|
351 } |
|
352 |
|
353 inline ~TFuncLog() |
|
354 { |
|
355 if ( !iLeft ) |
|
356 { |
|
357 if ( iCanLeave ) |
|
358 { |
|
359 CleanupStack::Pop( this ); // Pop the cleanup item |
|
360 } |
|
361 FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished |
|
362 } |
|
363 } |
|
364 |
|
365 private: // Data |
|
366 TPtrC8 iFunc; |
|
367 TBool iLeft; |
|
368 TCleanupItem iCleanupItem; |
|
369 TBool iCanLeave; |
|
370 }; |
|
371 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ ); |
|
372 |
|
373 #else//FUNC_TRACE not defined |
|
374 |
|
375 #define FUNC_LOG |
|
376 |
|
377 #endif//FUNC_TRACE |
|
378 |
|
379 //----------------------------------------------------------------------------- |
|
380 // Timestamp trace macros |
|
381 //----------------------------------------------------------------------------- |
|
382 // |
|
383 #ifdef TIMESTAMP_TRACE |
|
384 |
|
385 #define PREFIX_TIMESTAMP( aCaption ) _PREFIX_TRACE_2("[TIMESTAMP] (%d:%02d:%02d.%06d us) ",aCaption) |
|
386 #define CURRENT_TIME( aDt ) TDateTime aDt; { TTime t; t.HomeTime(); aDt = t.DateTime(); } |
|
387 #define EXTRACT_TIME( aDt ) aDt.Hour(), aDt.Minute(), aDt.Second(), aDt.MicroSecond() |
|
388 |
|
389 #ifdef TRACE_INTO_FILE |
|
390 |
|
391 #define TIMESTAMP( aCaption )\ |
|
392 {\ |
|
393 CURRENT_TIME( dt );\ |
|
394 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
395 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\ |
|
396 } |
|
397 |
|
398 #define TIMESTAMP_1( aCaption, aP1 )\ |
|
399 {\ |
|
400 CURRENT_TIME( dt );\ |
|
401 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
402 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\ |
|
403 } |
|
404 |
|
405 #define TIMESTAMP_2( aCaption, aP1, aP2 )\ |
|
406 {\ |
|
407 CURRENT_TIME( dt );\ |
|
408 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
409 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\ |
|
410 } |
|
411 |
|
412 #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\ |
|
413 {\ |
|
414 CURRENT_TIME( dt );\ |
|
415 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
416 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\ |
|
417 } |
|
418 |
|
419 #else//TRACE_INTO_FILE not defined |
|
420 |
|
421 #define TIMESTAMP( aCaption )\ |
|
422 {\ |
|
423 CURRENT_TIME( dt );\ |
|
424 RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\ |
|
425 } |
|
426 |
|
427 #define TIMESTAMP_1( aCaption, aP1 )\ |
|
428 {\ |
|
429 CURRENT_TIME( dt );\ |
|
430 RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\ |
|
431 } |
|
432 |
|
433 #define TIMESTAMP_2( aCaption, aP1, aP2 )\ |
|
434 {\ |
|
435 CURRENT_TIME( dt );\ |
|
436 RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\ |
|
437 } |
|
438 |
|
439 #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\ |
|
440 {\ |
|
441 CURRENT_TIME( dt );\ |
|
442 RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\ |
|
443 } |
|
444 |
|
445 #endif//TRACE_INTO_FILE |
|
446 |
|
447 #else//TIMESTAMP_TRACE not defined |
|
448 |
|
449 #define TIMESTAMP( aCaption ) |
|
450 #define TIMESTAMP_1( aCaption, aP1 ) |
|
451 #define TIMESTAMP_2( aCaption, aP1, aP2 ) |
|
452 #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 ) |
|
453 |
|
454 #endif//TIMESTAMP_TRACE |
|
455 |
|
456 #ifdef _DEBUG |
|
457 |
|
458 #include <e32debug.h> // RDebug |
|
459 |
|
460 static void Panic( const TDesC8& aFileName, const TInt aLineNum ) |
|
461 { |
|
462 TPath name; |
|
463 name.Copy( aFileName ); |
|
464 RDebug::Print( _L( "Assertion failed in file=%S, line=%d" ), &name, aLineNum ); |
|
465 User::Invariant(); |
|
466 } |
|
467 |
|
468 #define ASSERT_ALWAYS_TRACE Panic( _L8(__FILE__), __LINE__ ); |
|
469 #define ASSERT_TRACE( _s ) if ( !( _s ) ) { ASSERT_ALWAYS_TRACE; } |
|
470 |
|
471 #else // _DEBUG |
|
472 |
|
473 #define ASSERT_ALWAYS_TRACE |
|
474 #define ASSERT_TRACE( _s ) |
|
475 |
|
476 #endif // _DEBUG |
|
477 |
|
478 #define TRACE_MATRIX( aMsg, aMatrix ) \ |
|
479 TRACES( aMsg ); \ |
|
480 TRACES( "------------------------------------------------" ); \ |
|
481 TRACES3( " [%f %f %f]", (TReal)(aMatrix)[0], (TReal)(aMatrix)[1], (TReal)(aMatrix)[2] ); \ |
|
482 TRACES3( "Matrix [%f %f %f]", (TReal)(aMatrix)[3], (TReal)(aMatrix)[4], (TReal)(aMatrix)[5] ); \ |
|
483 TRACES3( " [%f %f %f]", (TReal)(aMatrix)[6], (TReal)(aMatrix)[7], (TReal)(aMatrix)[8] ); \ |
|
484 TRACES( "------------------------------------------------" ); |
|
485 |
|
486 #endif // GOOMTRACES_H |
|
487 |
|
488 // End of File |