|
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 #include "MemSpyEngineHelperSysMemTrackerImp.h" |
|
19 |
|
20 // System includes |
|
21 #include <e32debug.h> |
|
22 |
|
23 // User includes |
|
24 #include <memspy/engine/memspyengine.h> |
|
25 #include <memspy/engine/memspyengineutils.h> |
|
26 #include <memspy/engine/memspyengineobjectthread.h> |
|
27 #include <memspy/engine/memspyengineobjectprocess.h> |
|
28 #include <memspy/engine/memspyengineobjectcontainer.h> |
|
29 #include <memspy/engine/memspyenginehelperheap.h> |
|
30 #include <memspy/engine/memspyenginehelperchunk.h> |
|
31 #include <memspy/engine/memspyenginehelpersysmemtrackercycle.h> |
|
32 #include <memspy/engine/memspyenginehelpersysmemtrackerobserver.h> |
|
33 #include "MemSpyEngineHelperSysMemTrackerEntryManager.h" |
|
34 |
|
35 // Constants |
|
36 const TInt KMemSpyDefaultTrackerTimerPeriod = 30; // Seconds |
|
37 |
|
38 |
|
39 CMemSpyEngineHelperSysMemTrackerImp::CMemSpyEngineHelperSysMemTrackerImp( CMemSpyEngine& aEngine ) |
|
40 : CTimer( EPriorityStandard ), iEngine( aEngine ) |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 iConfig.iTimerPeriod = TTimeIntervalMicroSeconds32( KMemSpyDefaultTrackerTimerPeriod * 1000000 ); |
|
44 } |
|
45 |
|
46 |
|
47 CMemSpyEngineHelperSysMemTrackerImp::~CMemSpyEngineHelperSysMemTrackerImp() |
|
48 { |
|
49 Cancel(); |
|
50 // |
|
51 delete iEntryManager; |
|
52 // |
|
53 iCompletedCycles.ResetAndDestroy(); |
|
54 iCompletedCycles.Close(); |
|
55 } |
|
56 |
|
57 |
|
58 void CMemSpyEngineHelperSysMemTrackerImp::ConstructL() |
|
59 { |
|
60 CTimer::ConstructL(); |
|
61 } |
|
62 |
|
63 |
|
64 CMemSpyEngineHelperSysMemTrackerImp* CMemSpyEngineHelperSysMemTrackerImp::NewL( CMemSpyEngine& aEngine ) |
|
65 { |
|
66 CMemSpyEngineHelperSysMemTrackerImp* self = new(ELeave) CMemSpyEngineHelperSysMemTrackerImp( aEngine ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop( self ); |
|
70 return self; |
|
71 } |
|
72 |
|
73 |
|
74 void CMemSpyEngineHelperSysMemTrackerImp::StartL( const TMemSpyEngineHelperSysMemTrackerConfig& aConfig ) |
|
75 { |
|
76 TRACE( RDebug::Printf("CMemSpyEngineHelperSysMemTrackerImp::StartL() - START - timer period: %d", Config().TimerPeriod().Int() ) ); |
|
77 |
|
78 // Zap any old data |
|
79 Reset(); |
|
80 |
|
81 // Cache client settings |
|
82 iConfig = aConfig; |
|
83 |
|
84 // Make new cycle |
|
85 PrepareInitialCycleL(); |
|
86 |
|
87 // Start tracking via timer - future updates will by driven by RunL(). |
|
88 After( Config().TimerPeriod() ); |
|
89 TRACE( RDebug::Printf("CMemSpyEngineHelperSysMemTrackerImp::END() - START - timer period: %d", Config().TimerPeriod().Int() ) ); |
|
90 } |
|
91 |
|
92 |
|
93 void CMemSpyEngineHelperSysMemTrackerImp::StopL() |
|
94 { |
|
95 Cancel(); |
|
96 } |
|
97 |
|
98 |
|
99 void CMemSpyEngineHelperSysMemTrackerImp::SetObserver( MMemSpyEngineHelperSysMemTrackerObserver* aObserver ) |
|
100 { |
|
101 iObserver = aObserver; |
|
102 } |
|
103 |
|
104 |
|
105 void CMemSpyEngineHelperSysMemTrackerImp::RemoveObserver( MMemSpyEngineHelperSysMemTrackerObserver* aObserver ) |
|
106 { |
|
107 if ( iObserver == aObserver ) |
|
108 { |
|
109 iObserver = NULL; |
|
110 } |
|
111 } |
|
112 |
|
113 |
|
114 const RPointerArray< CMemSpyEngineHelperSysMemTrackerCycle >& CMemSpyEngineHelperSysMemTrackerImp::CompletedCycles() const |
|
115 { |
|
116 return iCompletedCycles; |
|
117 } |
|
118 |
|
119 |
|
120 void CMemSpyEngineHelperSysMemTrackerImp::Reset() |
|
121 { |
|
122 Cancel(); |
|
123 iCompletedCycles.ResetAndDestroy(); |
|
124 // |
|
125 if ( iObserver ) |
|
126 { |
|
127 TRAP_IGNORE( iObserver->HandleCyclesResetL() ); |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 void CMemSpyEngineHelperSysMemTrackerImp::CheckForChangesNowL() |
|
133 { |
|
134 const TInt count = iCompletedCycles.Count(); |
|
135 TRACE( RDebug::Printf("CMemSpyEngineHelperSysMemTrackerImp::CheckForChangesNowL() - START - isActive: %d, cycleCount: %d", IsActive(), count ) ); |
|
136 |
|
137 if ( IsActive() ) |
|
138 { |
|
139 Cancel(); |
|
140 CheckForChangesL(); |
|
141 After( Config().TimerPeriod() ); |
|
142 } |
|
143 else |
|
144 { |
|
145 // Timer not running, so we're probably being poked by some external-to-memspy client that |
|
146 // wants to force an update. |
|
147 // |
|
148 // If we've never yet performed an initital cycle, then prep that. Otherwise, just proceed as normal |
|
149 // as if we had been called back via RunL(). |
|
150 if ( count == 0 ) |
|
151 { |
|
152 PrepareInitialCycleL(); |
|
153 } |
|
154 else |
|
155 { |
|
156 CheckForChangesL(); |
|
157 } |
|
158 } |
|
159 |
|
160 TRACE( RDebug::Printf("CMemSpyEngineHelperSysMemTrackerImp::CheckForChangesNowL() - END - isActive: %d, cycleCount: %d", IsActive(), iCompletedCycles.Count() ) ); |
|
161 } |
|
162 |
|
163 |
|
164 TInt CMemSpyEngineHelperSysMemTrackerImp::MdcaCount() const |
|
165 { |
|
166 return iCompletedCycles.Count(); |
|
167 } |
|
168 |
|
169 |
|
170 TPtrC CMemSpyEngineHelperSysMemTrackerImp::MdcaPoint( TInt aIndex ) const |
|
171 { |
|
172 const CMemSpyEngineHelperSysMemTrackerCycle* cycleInfo = iCompletedCycles[ aIndex ]; |
|
173 const TPtrC ret( cycleInfo->Caption() ); |
|
174 return ret; |
|
175 } |
|
176 |
|
177 |
|
178 void CMemSpyEngineHelperSysMemTrackerImp::NotifyObserverCycleStartedL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle ) |
|
179 { |
|
180 if ( iObserver ) |
|
181 { |
|
182 TRAP_IGNORE( iObserver->HandleCycleStartedL( aCycle ) ); |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 void CMemSpyEngineHelperSysMemTrackerImp::NotifyObserverCycleFinishedL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle ) |
|
188 { |
|
189 if ( iObserver ) |
|
190 { |
|
191 TRAP_IGNORE( iObserver->HandleCycleFinishedL( aCycle ) ); |
|
192 aCycle.DiscardChanges(); |
|
193 } |
|
194 } |
|
195 |
|
196 |
|
197 void CMemSpyEngineHelperSysMemTrackerImp::AddCycleAndPopL( CMemSpyEngineHelperSysMemTrackerCycle* aCycle ) |
|
198 { |
|
199 iCompletedCycles.AppendL( aCycle ); |
|
200 CleanupStack::Pop( aCycle ); |
|
201 aCycle->FinalizeL(); |
|
202 } |
|
203 |
|
204 |
|
205 CMemSpyEngineHelperSysMemTrackerCycle* CMemSpyEngineHelperSysMemTrackerImp::LastCycleOrNull() |
|
206 { |
|
207 CMemSpyEngineHelperSysMemTrackerCycle* ret = NULL; |
|
208 // |
|
209 const TInt count = iCompletedCycles.Count(); |
|
210 if ( count ) |
|
211 { |
|
212 ret = iCompletedCycles[ count - 1 ]; |
|
213 } |
|
214 // |
|
215 return ret; |
|
216 } |
|
217 |
|
218 |
|
219 void CMemSpyEngineHelperSysMemTrackerImp::PrepareInitialCycleL() |
|
220 { |
|
221 // Create seed items |
|
222 CMemSpyEngineHelperSysMemTrackerEntryManager* entryManager = CMemSpyEngineHelperSysMemTrackerEntryManager::NewL( *this ); |
|
223 delete iEntryManager; |
|
224 iEntryManager = entryManager; |
|
225 |
|
226 // Everything changes on the first cycle. |
|
227 CMemSpyEngineHelperSysMemTrackerCycle* baselineCycle = CMemSpyEngineHelperSysMemTrackerCycle::NewLC( iConfig ); |
|
228 NotifyObserverCycleStartedL( *baselineCycle ); |
|
229 iEntryManager->EverythingHasChangedL( *baselineCycle ); |
|
230 AddCycleAndPopL( baselineCycle ); |
|
231 NotifyObserverCycleFinishedL( *baselineCycle ); |
|
232 } |
|
233 |
|
234 |
|
235 void CMemSpyEngineHelperSysMemTrackerImp::CheckForChangesL() |
|
236 { |
|
237 // Create info structure |
|
238 CMemSpyEngineHelperSysMemTrackerCycle* cycle = CMemSpyEngineHelperSysMemTrackerCycle::NewLC( iConfig, LastCycleOrNull() ); |
|
239 |
|
240 // Notify |
|
241 NotifyObserverCycleStartedL( *cycle ); |
|
242 |
|
243 // Find changes |
|
244 iEntryManager->IdentifyChangesL( *cycle ); |
|
245 |
|
246 // Finalise the cycle and save it |
|
247 AddCycleAndPopL( cycle ); |
|
248 |
|
249 // Notify |
|
250 NotifyObserverCycleFinishedL( *cycle ); |
|
251 } |
|
252 |
|
253 |
|
254 void CMemSpyEngineHelperSysMemTrackerImp::RunL() |
|
255 { |
|
256 CheckForChangesL(); |
|
257 After( Config().TimerPeriod() ); |
|
258 } |
|
259 |
|
260 |
|
261 TInt CMemSpyEngineHelperSysMemTrackerImp::RunError( TInt aError ) |
|
262 { |
|
263 RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerImp::RunError() - aError: %d", aError ); |
|
264 (void) aError; |
|
265 // |
|
266 Cancel(); |
|
267 After( Config().TimerPeriod() ); |
|
268 // |
|
269 return KErrNone; |
|
270 } |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |