|
1 /* |
|
2 * Copyright (c) 2006-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: The file defines the debug macros. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __CLOCK_DEBUG_H__ |
|
19 #define __CLOCK_DEBUG_H__ |
|
20 |
|
21 /** The clock debug flag */ |
|
22 #define __CLOCK_DEBUG__ |
|
23 |
|
24 // If the debug flag is not defined, all the macros are null. |
|
25 #ifndef __CLOCK_DEBUG__ |
|
26 |
|
27 #define __TIME_MARK(_var) |
|
28 #define __TIME_ENDMARK(_msg, _var) |
|
29 #define __TIME(_msg, _code) _code; |
|
30 #define __TICK(_msg) |
|
31 #define __HEAP(_msg) |
|
32 #define __PRINT(_fmt, args...) |
|
33 #define __PRINT8(_fmt, args...) |
|
34 #define __PRINTS(_str) |
|
35 #define __PRINT_IF_ERROR(_stmt, _fmt) _stmt; |
|
36 #define __TRAP_AND_PRINT_IF_ERROR(_stmt, _fmt) TRAP_IGNORE(_stmt); |
|
37 |
|
38 #else |
|
39 |
|
40 // System includes. |
|
41 #include <flogger.h> |
|
42 |
|
43 // Constants |
|
44 #ifndef D_LOG_DIR |
|
45 #define D_LOG_DIR _L("clock") // The log directory. |
|
46 #endif |
|
47 |
|
48 #ifndef D_LOG_FILE |
|
49 #define D_LOG_FILE _L("adtu.log") // The log file. |
|
50 #endif |
|
51 |
|
52 |
|
53 // ========== LOCAL FUNCTIONS ================================================= |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // |
|
57 // Performance logging operation, give results in microseconds 10^-6 |
|
58 // The metricts are based on the measurment current value of microseconds in |
|
59 // the begining of operation and in the end. The time difference is actual result |
|
60 // |
|
61 // The logging operations take about 5ms, which should be considered if inner |
|
62 // tag are used. |
|
63 // |
|
64 // Examples: |
|
65 // |
|
66 // __TIME_MARK(t) |
|
67 // DoOperation(...); |
|
68 // __TIME_ENDMARK(_L("Message 1"), t); |
|
69 // |
|
70 // __TIME(_L("Message 1"), DoOperation(...)) |
|
71 // |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 |
|
75 // |
|
76 // Actual implementation of |
|
77 // Logs the microsecond difference between current value and stored earlier |
|
78 // aMsg - textual message stored to the log file |
|
79 // aStart - the start time, the value is set by previous macros |
|
80 // |
|
81 inline void __impl_time_endmark(const TDesC& aMsg, TTime aStart) |
|
82 { |
|
83 TTime now; |
|
84 now.UniversalTime(); |
|
85 TTimeIntervalMicroSeconds delta = now.MicroSecondsFrom(aStart); |
|
86 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[T]\t%S\tTime:\t%Ld"), &aMsg, delta.Int64()); |
|
87 } |
|
88 |
|
89 // |
|
90 // Prints the message and current ms value to the log file |
|
91 // |
|
92 inline void __impl_tick(const TDesC& aMsg) |
|
93 { |
|
94 // Gets the nanokernel tick count. This is the current value of the machine's millisecond tick counter. |
|
95 TUint32 nTick = User::NTickCount(); |
|
96 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[T]\t%S\tMicro Sec:\t%d000"), &aMsg, nTick); |
|
97 } |
|
98 |
|
99 // |
|
100 // Stores the current microsecond value |
|
101 // _var - A name, which will be declared as a TInt, and will receive the current time value. |
|
102 // After the macro, _var remains in scope until the end of its enclosing block. |
|
103 // |
|
104 #define __TIME_MARK(_var) TTime _var;_var.UniversalTime(); |
|
105 |
|
106 // |
|
107 // Logs the microsecond difference between current value and stored earlier |
|
108 // _msg - textual message stored to the log file |
|
109 // _var - the start time, the value is set by previous macros |
|
110 // |
|
111 #define __TIME_ENDMARK(_msg, _var) __impl_time_endmark(_L(_msg), _var); |
|
112 |
|
113 // |
|
114 // Measures the execution of code statement |
|
115 // _msg - textual message stored to the log file |
|
116 // _code - code statements to be measured |
|
117 // |
|
118 #define __TIME(_msg, _code) {TTime _time;_time.UniversalTime();_code;__impl_time_endmark(_L(_msg),_time);}; |
|
119 |
|
120 // |
|
121 // The message and current ms value to the log file |
|
122 // |
|
123 #define __TICK(_msg) __impl_tick(_L(_msg)); |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // Logs the amout of used heap to log file. Notes that the Heap value equals |
|
127 // to the result provided by Goofy tool. |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 inline void __impl_heap(const TDesC& aMsg) |
|
131 { |
|
132 // Log Memory |
|
133 TInt size; |
|
134 User::Heap().AllocSize(size); |
|
135 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[M]\t%S\tAlloc:\t%d\tHeap:\t%d"), &aMsg, size, User::Heap().Size()); |
|
136 } |
|
137 |
|
138 #define __HEAP(_msg) __impl_heap(_L(_msg)); |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 // ---------------------------------------------------------------------------- |
|
143 // |
|
144 inline void __impl_print(TRefByValue<const TDesC16> aFmt, ...) |
|
145 { |
|
146 VA_LIST list; |
|
147 VA_START(list,aFmt); |
|
148 |
|
149 // Log event |
|
150 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, aFmt, list); |
|
151 } |
|
152 |
|
153 inline void __impl_print8(TRefByValue<const TDesC8> aFmt, ...) |
|
154 { |
|
155 VA_LIST list; |
|
156 VA_START(list,aFmt); |
|
157 |
|
158 // Log event |
|
159 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, aFmt, list); |
|
160 } |
|
161 |
|
162 inline void __impl_prints(const TDesC& aMsg) |
|
163 { |
|
164 RFileLogger::WriteFormat(D_LOG_DIR, D_LOG_FILE, EFileLoggingModeAppend, _L("\t[I]\t%S"), &aMsg); |
|
165 } |
|
166 |
|
167 // It is a correct approach to define function-like macroses but GCC give |
|
168 // compilatoin error. |
|
169 // #define __PRINT(_fmt, ...) __impl_print(_L(_fmt), __VA_ARGS__); |
|
170 // #define __PRINT8(_fmt, ...) __impl_print8(_L8(_fmt), __VA_ARGS__); |
|
171 #define __PRINT(_fmt, args...) __impl_print(_L(_fmt), args); |
|
172 // #define __PRINT8(_fmt, args...) __impl_print8(_L8(_fmt), args); |
|
173 #define __PRINTS(_str) __impl_prints(_L(_str)); |
|
174 |
|
175 #define __PRINT_IF_ERROR(_stmt, _fmt) { TInt _error = _stmt; if (_error != KErrNone) __PRINT(_fmt, _error); }; |
|
176 #define __TRAP_AND_PRINT_IF_ERROR(_stmt, _fmt) { TRAPD(_error, _stmt); if (_error != KErrNone) __PRINT(_fmt, _error); }; |
|
177 |
|
178 #endif // __CLOCK_DEBUG__ |
|
179 |
|
180 #endif // __CLOCK_DEBUG_H__ |
|
181 |
|
182 // End of file |