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