|
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 #ifndef PROFILEUTILMACRO_H |
|
19 #define PROFILEUTILMACRO_H |
|
20 /* |
|
21 // MACROS to be defined to use profiling |
|
22 PROFILE_TIME |
|
23 PROFILE_RAM_USAGE |
|
24 PROFILE_HEAP_USAGE |
|
25 PRINT_TO_CONSOLE_TIME_DIFF |
|
26 PRINT_TO_CONSOLE_RAM_DIFF |
|
27 PRINT_TO_CONSOLE_HEAP_DIFF |
|
28 */ |
|
29 |
|
30 #if defined(PROFILE_TIME) || defined(PROFILE_RAM_USAGE) || defined(PROFILE_HEAP_USAGE) |
|
31 #include <e32debug.h> |
|
32 #include <hal.h> |
|
33 #endif |
|
34 |
|
35 #ifdef PROFILE_TIME |
|
36 #define TAG_TIME_PROFILING_BEGIN \ |
|
37 TTime beginProfilingTime; \ |
|
38 beginProfilingTime.HomeTime() |
|
39 |
|
40 #define TAG_TIME_PROFILING_BEGIN_NO_VAR_DEF \ |
|
41 beginProfilingTime.HomeTime() |
|
42 |
|
43 #define TAG_TIME_PROFILING_END \ |
|
44 TTime endProfilingTime; \ |
|
45 endProfilingTime.HomeTime(); \ |
|
46 TTimeIntervalMicroSeconds diffInMicroSecs = endProfilingTime.MicroSecondsFrom(beginProfilingTime) |
|
47 |
|
48 #define TAG_TIME_PROFILING_END_NO_VAR_DEF \ |
|
49 endProfilingTime.HomeTime(); \ |
|
50 diffInMicroSecs = endProfilingTime.MicroSecondsFrom(beginProfilingTime) |
|
51 |
|
52 #define PRINT_TO_CONSOLE_TIME_DIFF \ |
|
53 RDebug::Printf("VPROFILEDAT: %s : Time taken[%u]microseconds ", __PRETTY_FUNCTION__, diffInMicroSecs.Int64()) |
|
54 |
|
55 #define PRINT_TO_CONSOLE_HOME_TIME \ |
|
56 TTime homeTime; \ |
|
57 homeTime.HomeTime(); \ |
|
58 RDebug::Printf("VPROFILEDAT: %s : Home Time [%u]microseconds ", __PRETTY_FUNCTION__, homeTime.Int64()) |
|
59 |
|
60 #define PRINT_TO_CONSOLE_HOME_TIME_NO_VAR_DEF \ |
|
61 homeTime.HomeTime(); \ |
|
62 RDebug::Printf("VPROFILEDAT: %s : Home Time [%u]microseconds ", __PRETTY_FUNCTION__, homeTime.Int64()) |
|
63 |
|
64 #else /* Empty macros */ |
|
65 #define TAG_TIME_PROFILING_BEGIN |
|
66 #define TAG_TIME_PROFILING_BEGIN_NO_VAR_DEF |
|
67 #define TAG_TIME_PROFILING_END |
|
68 #define TAG_TIME_PROFILING_END_NO_VAR_DEF |
|
69 #define PRINT_TO_CONSOLE_TIME_DIFF |
|
70 #define PRINT_TO_CONSOLE_HOME_TIME |
|
71 #define PRINT_TO_CONSOLE_HOME_TIME_NO_VAR_DEF |
|
72 #endif /*PROFILE_TIME*/ |
|
73 |
|
74 #ifdef PROFILE_RAM_USAGE |
|
75 #define TAG_RAM_PROFILING_BEGIN \ |
|
76 TInt beginProfilingRAM; \ |
|
77 TInt err1 = HAL::Get(HALData::EMemoryRAMFree, beginProfilingRAM) |
|
78 |
|
79 #define TAG_RAM_PROFILING_END \ |
|
80 TInt endProfilingRAM; \ |
|
81 TInt err2 = HAL::Get(HALData::EMemoryRAMFree, endProfilingRAM) |
|
82 |
|
83 #define PRINT_TO_CONSOLE_RAM_DIFF \ |
|
84 if ((err1 == KErrNone) && (err2 == KErrNone)) \ |
|
85 { \ |
|
86 TInt diffRAM = (beginProfilingRAM - endProfilingRAM); \ |
|
87 if ( diffRAM > 0 ) \ |
|
88 { \ |
|
89 RDebug::Printf("VPROFILEDAT: %s : RAM used[%u]bytes ", __PRETTY_FUNCTION__, diffRAM); \ |
|
90 } \ |
|
91 else \ |
|
92 { \ |
|
93 RDebug::Printf("VPROFILEDAT: %s : RAM freed[%u]bytes ", __PRETTY_FUNCTION__, (-diffRAM)); \ |
|
94 } \ |
|
95 } \ |
|
96 else \ |
|
97 { \ |
|
98 RDebug::Printf("VPROFILEDAT: %s : Error1[%d] Error2[%d] ", __PRETTY_FUNCTION__, err1, err2); \ |
|
99 } |
|
100 |
|
101 #else /* Empty macros */ |
|
102 #define TAG_RAM_PROFILING_BEGIN |
|
103 #define TAG_RAM_PROFILING_END |
|
104 #define PRINT_TO_CONSOLE_RAM_DIFF |
|
105 #endif /*PROFILE_RAM_USAGE*/ |
|
106 |
|
107 #ifdef PROFILE_HEAP_USAGE |
|
108 #define TAG_DEFAULT_HEAP_PROFILING_BEGIN \ |
|
109 TInt beginProfilingHEAPBiggestBlock; \ |
|
110 TInt beginProfilingHEAP = User::Available(beginProfilingHEAPBiggestBlock) \ |
|
111 |
|
112 #define TAG_DEFAULT_HEAP_PROFILING_END \ |
|
113 TInt endProfilingHEAPBiggestBlock; \ |
|
114 TInt endProfilingHEAP = User::Available(endProfilingHEAPBiggestBlock) \ |
|
115 |
|
116 #define PRINT_TO_CONSOLE_HEAP_DIFF \ |
|
117 TInt diffHEAP = beginProfilingHEAP - endProfilingHEAP; \ |
|
118 if ( diffHEAP > 0 ) \ |
|
119 { \ |
|
120 RDebug::Printf("VPROFILEDAT: %s : HEAP used[%u]bytes ", __PRETTY_FUNCTION__, diffHEAP); \ |
|
121 } \ |
|
122 else \ |
|
123 { \ |
|
124 RDebug::Printf("VPROFILEDAT: %s : HEAP freed[%u]bytes ", __PRETTY_FUNCTION__, (-diffHEAP)); \ |
|
125 } |
|
126 #else /* Empty macros */ |
|
127 #define TAG_DEFAULT_HEAP_PROFILING_BEGIN |
|
128 #define TAG_DEFAULT_HEAP_PROFILING_END |
|
129 #define PRINT_TO_CONSOLE_HEAP_DIFF |
|
130 #endif /*PROFILE_HEAP_USAGE*/ |
|
131 |
|
132 #endif /* PROFILEUTILMACRO_H */ |