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