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