|
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: Declaration of the class RAnalyzeToolAllocator. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef ANALYZETOOLALLOCATOR_H |
|
20 #define ANALYZETOOLALLOCATOR_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <u32std.h> |
|
24 #include "codeblock.h" |
|
25 #include "threadstack.h" |
|
26 #include "analyzetoolmemoryallocator.h" |
|
27 #include <analyzetool/analyzetool.h> |
|
28 #include <analyzetool/atcommon.h> |
|
29 #include "analyzetoolfilelog.h" |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * Class which overloads the RAlloctor functions and provides access to |
|
35 * the overloaded functions |
|
36 */ |
|
37 class RAnalyzeToolAllocator : public RAnalyzeToolMemoryAllocator |
|
38 { |
|
39 |
|
40 public: |
|
41 |
|
42 /** |
|
43 * C++ default constructor. |
|
44 * @param aNotFirst Is this first thread using this heap |
|
45 * @param aCodeblocks A reference to array of code segments |
|
46 * @param aMutex A reference to mutex for schedule access to the |
|
47 * shared resources |
|
48 * @param aProcessId A reference to the observed process id |
|
49 * @param aAnalyzeTool Reference to device driver |
|
50 * @param aLogOption The logging option |
|
51 * @param aAllocCallStackSize Max number of stored callstack items when memory allocated |
|
52 * @param aFreeCallStackSize Max number of stored callstack items when memory freed |
|
53 */ |
|
54 RAnalyzeToolAllocator( TBool aNotFirst, |
|
55 RArray<TCodeblock>& aCodeblocks, |
|
56 RMutex& aMutex, |
|
57 TUint aProcessId, |
|
58 RAnalyzeTool& aAnalyzeTool, |
|
59 TUint32 aLogOption, |
|
60 TUint32 aAllocCallStackSize, |
|
61 TUint32 aFreeCallStackSize, |
|
62 RATFileLog& iLogFile ); |
|
63 /** |
|
64 * Destructor. |
|
65 */ |
|
66 ~RAnalyzeToolAllocator(); |
|
67 |
|
68 /** |
|
69 * Allocates a cell of specified size from the heap. |
|
70 * @param aSize The size of the cell to be allocated from the heap. |
|
71 * @return TAny* A pointer to the allocated cell. |
|
72 */ |
|
73 TAny* Alloc( TInt aSize ); |
|
74 |
|
75 /** |
|
76 * Frees the specified cell and returns it to the heap. |
|
77 * @param aPtr A pointer to a cell to be freed. |
|
78 */ |
|
79 void Free( TAny* aPtr ); |
|
80 |
|
81 /** |
|
82 * Increases or decreases the size of an existing cell. |
|
83 * @param aPtr A pointer to the cell to be reallocated. |
|
84 * @param aSize The new size of the cell. This may be bigger |
|
85 * or smaller than the size of the original cell. |
|
86 * @param aMode Flags controlling the reallocation. |
|
87 * @return TAny* A pointer to the reallocated cell. This may be the |
|
88 * same as the original pointer supplied through aCell. |
|
89 */ |
|
90 //lint --e{1735} suppress "Virtual function has default parameter" |
|
91 TAny* ReAlloc( TAny* aPtr, TInt aSize, TInt aMode = 0 ); |
|
92 |
|
93 /** |
|
94 * Gets the length of the available space in the specified |
|
95 * allocated cell. |
|
96 * @param aCell A pointer to the allocated cell. |
|
97 * @return TInt The length of the available space in the allocated cell. |
|
98 */ |
|
99 TInt AllocLen( const TAny* aCell ) const; |
|
100 |
|
101 #ifndef __KERNEL_MODE__ |
|
102 |
|
103 /** |
|
104 * Opens this heap for shared access. Opening the heap increases |
|
105 * the heap's access count by one. |
|
106 */ |
|
107 TInt Open(); |
|
108 |
|
109 /** |
|
110 * Closes this shared heap. Closing the heap decreases the heap's |
|
111 * access count by one. |
|
112 */ |
|
113 void Close(); |
|
114 |
|
115 /** |
|
116 * The function frees excess committed space from the top of the heap. |
|
117 * The size of the heap is never reduced below the minimum size |
|
118 * specified during creation of the heap. |
|
119 * @return TInt The space reclaimed. If no space can be reclaimed, |
|
120 then this value is zero. |
|
121 */ |
|
122 TInt Compress(); |
|
123 |
|
124 /** |
|
125 * Frees all allocated cells on this heap. |
|
126 */ |
|
127 void Reset(); |
|
128 |
|
129 /** |
|
130 * Gets the number of cells allocated on this heap, and |
|
131 * the total space allocated to them. |
|
132 * @param aTotalAllocSize On return, contains the total |
|
133 * space allocated to the cells. |
|
134 * @return TInt The number of cells allocated on this heap. |
|
135 */ |
|
136 TInt AllocSize( TInt& aTotalAllocSize ) const; |
|
137 |
|
138 /** |
|
139 * Gets the total free space currently available on the heap and the |
|
140 * space available in the largest free block. The space available |
|
141 * represents the total space which can be allocated. Note that |
|
142 * compressing the heap may reduce the total free space available |
|
143 * and the space available in the largest free block. |
|
144 * @param aBiggestBlock On return, contains the space available |
|
145 * in the largest free block on the heap. |
|
146 |
|
147 * @return TInt The total free space currently available on the heap. |
|
148 |
|
149 */ |
|
150 TInt Available( TInt& aBiggestBlock ) const; |
|
151 |
|
152 #endif |
|
153 |
|
154 /** |
|
155 * Invocates specified debug funtionality. |
|
156 * @param aFunc The debug function |
|
157 * @param a1 Debug function specific paramenter. |
|
158 * @param a2 Debug function specific paramenter. |
|
159 * @return TInt Returns KErrNone, if successful otherwise one |
|
160 * of the other system-wide error codes. |
|
161 */ |
|
162 //lint --e{1735} suppress "Virtual function has default parameter" |
|
163 TInt DebugFunction( TInt aFunc, TAny* a1 = NULL, TAny* a2 = NULL ); |
|
164 |
|
165 protected: |
|
166 |
|
167 /** |
|
168 * Extension function |
|
169 * @param aExtensionId The extension id |
|
170 * @param a0 Extension specific paramenter. |
|
171 * @param a1 Extension specific paramenter. |
|
172 * @return TInt Returns KErrNone, if successful otherwise one |
|
173 * of the other system-wide error codes. |
|
174 */ |
|
175 TInt Extension_( TUint aExtensionId, TAny*& a0, TAny* a1 ); |
|
176 |
|
177 public: // from RAnalyzeToolMemoryAllocator |
|
178 |
|
179 /** |
|
180 * Installs the RTraceAllocator allocator |
|
181 */ |
|
182 void Uninstall(); |
|
183 |
|
184 /** |
|
185 * Shares the heap |
|
186 */ |
|
187 void ShareHeap(); |
|
188 |
|
189 private: |
|
190 |
|
191 /** |
|
192 * Find the current thread which is using the heap |
|
193 * @param aStackStart A reference where the stack start is stored |
|
194 * @return TBool ETrue if a thread can be found, EFalse otherwise |
|
195 */ |
|
196 TBool FindCurrentThreadStack( TUint32& aStackStart ); |
|
197 |
|
198 private: |
|
199 |
|
200 /* A reference to codeblocks of the observed process */ |
|
201 RArray<TCodeblock>& iCodeblocks; |
|
202 |
|
203 /* The mutex for serializing access to the shared resources */ |
|
204 RMutex& iMutex; |
|
205 |
|
206 /* The process id */ |
|
207 TUint iProcessId; |
|
208 |
|
209 /* Array for storing the callstack */ |
|
210 TFixedArray<TUint32, KATMaxCallstackLength> iCallStack; |
|
211 |
|
212 /* Array for storing the reallocation callstack */ |
|
213 TFixedArray <TUint32, KATMaxCallstackLength> iReCallStack; |
|
214 |
|
215 /* Array for storing the reallocation callstack */ |
|
216 TFixedArray<TUint32, KATMaxFreeCallstackLength> iFreeCallStack; |
|
217 |
|
218 /* Array of threads using this heap */ |
|
219 RArray<TThreadStack> iThreadArray; |
|
220 |
|
221 RAnalyzeTool& iAnalyzeTool; |
|
222 |
|
223 /* Log option */ |
|
224 TUint32 iLogOption; |
|
225 |
|
226 /* Max items on stored call stack when memory allocated */ |
|
227 TUint32 iAllocMaxCallStack; |
|
228 |
|
229 /* Max items on stored call stack when memory freed */ |
|
230 TUint32 iFreeMaxCallStack; |
|
231 |
|
232 /* Binary log file */ |
|
233 RATFileLog& iLogFile; |
|
234 |
|
235 }; |
|
236 |
|
237 #endif // ANALYZETOOLALLOCATOR_H |
|
238 |
|
239 // End of File |