equal
deleted
inserted
replaced
10 // Accenture - Initial contribution |
10 // Accenture - Initial contribution |
11 // |
11 // |
12 |
12 |
13 #include "leak.h" |
13 #include "leak.h" |
14 #include <fshell/common.mmh> |
14 #include <fshell/common.mmh> |
|
15 #ifdef FSHELL_QR3_SUPPORT_LOGGINGALLOCATOR |
|
16 #include <fshell/loggingallocator.h> |
|
17 #endif |
15 |
18 |
16 const TInt KMinChunkSize = 4 * 1024; |
19 const TInt KMinChunkSize = 4 * 1024; |
17 const TInt KMaxChunkSize = 512 * 1024 * 1024; |
20 const TInt KMaxChunkSize = 512 * 1024 * 1024; |
18 |
21 |
19 CCommandBase* CCmdLeak::NewLC() |
22 CCommandBase* CCmdLeak::NewLC() |
24 return self; |
27 return self; |
25 } |
28 } |
26 |
29 |
27 CCmdLeak::~CCmdLeak() |
30 CCmdLeak::~CCmdLeak() |
28 { |
31 { |
|
32 #ifdef FSHELL_QR3_SUPPORT_LOGGINGALLOCATOR |
|
33 if (iLoggingAllocator) |
|
34 { |
|
35 // Hmm how do I clean up a logging allocator created with RLoggingAllocator::New()? |
|
36 } |
|
37 #endif |
29 iChunk.Close(); |
38 iChunk.Close(); |
30 if (iChunkHeap) |
39 if (iChunkHeap) |
31 { |
40 { |
32 iChunkHeap->Reset(); |
41 iChunkHeap->Reset(); |
33 iChunkHeap->Close(); |
42 iChunkHeap->Close(); |
65 { |
74 { |
66 iIncrementAmount = KMinChunkSize; |
75 iIncrementAmount = KMinChunkSize; |
67 } |
76 } |
68 } |
77 } |
69 |
78 |
|
79 if (iUseLoggingAllocator) iUseHeap = ETrue; // Using the logging allocator implies the --heap option |
|
80 |
70 if (iUseHeap) |
81 if (iUseHeap) |
71 { |
82 { |
72 iChunkHeap = UserHeap::ChunkHeap(NULL, KMinChunkSize, 256*1024*1024); |
83 iChunkHeap = UserHeap::ChunkHeap(NULL, KMinChunkSize, 256*1024*1024); |
73 if (!iChunkHeap) LeaveIfErr(KErrNoMemory, _L("Couldn't create chunk heap")); |
84 if (!iChunkHeap) LeaveIfErr(KErrNoMemory, _L("Couldn't create chunk heap")); |
|
85 iAllocatorToUse = iChunkHeap; |
|
86 |
|
87 #ifdef FSHELL_QR3_SUPPORT_LOGGINGALLOCATOR |
|
88 if (iUseLoggingAllocator) |
|
89 { |
|
90 LeaveIfErr(RLoggingAllocator::New(0, iChunkHeap, iLoggingAllocator), _L("Couldn't create logging allocator")); |
|
91 iAllocatorToUse = iLoggingAllocator; |
|
92 } |
|
93 #endif |
74 } |
94 } |
75 else |
95 else |
76 { |
96 { |
77 if (iIncrementAmount & 4095) LeaveIfErr(KErrArgument, _L("increment-amount must be a multiple of 4096")); |
97 if (iIncrementAmount & 4095) LeaveIfErr(KErrArgument, _L("increment-amount must be a multiple of 4096")); |
78 TInt err = iChunk.CreateLocal(KMinChunkSize, KMaxChunkSize); |
98 TInt err = iChunk.CreateLocal(KMinChunkSize, KMaxChunkSize); |
135 _LIT(KOptUseHeap, "heap"); |
155 _LIT(KOptUseHeap, "heap"); |
136 aOptions.AppendBoolL(iUseHeap, KOptUseHeap); |
156 aOptions.AppendBoolL(iUseHeap, KOptUseHeap); |
137 |
157 |
138 _LIT(KOptRetry, "retry"); |
158 _LIT(KOptRetry, "retry"); |
139 aOptions.AppendBoolL(iRetry, KOptRetry); |
159 aOptions.AppendBoolL(iRetry, KOptRetry); |
|
160 |
|
161 #ifdef FSHELL_QR3_SUPPORT_LOGGINGALLOCATOR |
|
162 _LIT(KOptUseLoggingAllocator, "logging-allocator"); |
|
163 aOptions.AppendBoolL(iUseLoggingAllocator, KOptUseLoggingAllocator); |
|
164 #endif |
140 } |
165 } |
141 |
166 |
142 void CCmdLeak::ArgumentsL(RCommandArgumentList& aArguments) |
167 void CCmdLeak::ArgumentsL(RCommandArgumentList& aArguments) |
143 { |
168 { |
144 _LIT(KArgAmount, "amount"); |
169 _LIT(KArgAmount, "amount"); |
151 #endif |
176 #endif |
152 |
177 |
153 TInt CCmdLeak::LeakStep(TInt aAmount) |
178 TInt CCmdLeak::LeakStep(TInt aAmount) |
154 { |
179 { |
155 TInt err = KErrNone; |
180 TInt err = KErrNone; |
156 if (iChunkHeap) |
181 if (iAllocatorToUse) |
157 { |
182 { |
158 TAny* cell = iChunkHeap->Alloc(aAmount); |
183 TAny* cell = iAllocatorToUse->Alloc(aAmount); |
159 if (!cell) err = KErrNoMemory; |
184 if (!cell) err = KErrNoMemory; |
160 } |
185 } |
161 else |
186 else |
162 { |
187 { |
163 if (aAmount < 4096) err = KErrNoMemory; // implies we're retrying - unlike the others that keep retrying down to 4 bytes, we have to stop at page granularity |
188 if (aAmount < 4096) err = KErrNoMemory; // implies we're retrying - unlike the others that keep retrying down to 4 bytes, we have to stop at page granularity |