|
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 MEMSPYINSPECTEDPROCESS_H |
|
19 #define MEMSPYINSPECTEDPROCESS_H |
|
20 |
|
21 // System includes |
|
22 #include <kern_priv.h> |
|
23 |
|
24 // Shared includes |
|
25 #include <memspy/driver/memspydriverobjectsshared.h> |
|
26 |
|
27 // User includes |
|
28 #include "MemSpyDriverUtils.h" |
|
29 #include "MemSpyDriverEventMonitor.h" |
|
30 |
|
31 // Classes referenced |
|
32 class DMemSpyInspectedProcessManager; |
|
33 class TMemSpyDriverProcessInspectionInfo; |
|
34 |
|
35 |
|
36 |
|
37 class TMemSpyTrackedChunk |
|
38 { |
|
39 public: |
|
40 enum TType |
|
41 { |
|
42 ETypeNotRelevant = -1, |
|
43 // |
|
44 ETypeChunkHeap = 0, |
|
45 ETypeChunkLocal, |
|
46 ETypeChunkGlobalData, |
|
47 ETypeChunkProcessGlobalDataAndUserStack, |
|
48 ETypeChunkShared |
|
49 }; |
|
50 |
|
51 public: |
|
52 TMemSpyTrackedChunk( DChunk* aChunk, TType aType ); |
|
53 |
|
54 public: // API |
|
55 void SetSize( TInt aSize ); |
|
56 TInt Size() const { return iSize; } |
|
57 // |
|
58 void SetUnused( TBool aUnused ); |
|
59 TBool Unused() const { return iUnused; } |
|
60 // |
|
61 TAny* Handle() const { return iChunk; } |
|
62 // |
|
63 inline TType Type() const { return iType; } |
|
64 inline void SetType( TType aType ) { iType = aType; } |
|
65 |
|
66 public: // Data members |
|
67 SDblQueLink iLink; |
|
68 DChunk* iChunk; |
|
69 TType iType; |
|
70 TInt iSize; |
|
71 TBool iUnused; |
|
72 }; |
|
73 |
|
74 |
|
75 class TMemSpyTrackedChunkChangeInfo |
|
76 { |
|
77 public: // Data members |
|
78 TMemSpyDriverProcessInspectionInfo iInfo; |
|
79 SDblQueLink iLink; |
|
80 }; |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 class DMemSpyInspectedProcess : public DBase, public MMemSpyEventMonitorObserver |
|
87 { |
|
88 public: // Construct / destruct |
|
89 DMemSpyInspectedProcess( DMemSpyDriverDevice& aDevice ); |
|
90 ~DMemSpyInspectedProcess(); |
|
91 |
|
92 public: // API |
|
93 TInt Open( DProcess* aProcess ); |
|
94 inline TUint ProcessId() const { return iProcessId; } |
|
95 |
|
96 public: // Change notification API |
|
97 TInt NotifyOnChange( DThread* aThread, TRequestStatus* aRequestStatus, TMemSpyDriverProcessInspectionInfo* aInfo ); |
|
98 TInt NotifyOnChangeCancel(); |
|
99 TBool NotifyOnChangeQueued() const; |
|
100 |
|
101 public: // Queue link |
|
102 SDblQueLink iLink; |
|
103 |
|
104 public: // From MMemSpyEventMonitorObserver |
|
105 TUint EMTypeMask() const; |
|
106 void EMHandleProcessUpdated( DProcess& aProcess ); |
|
107 void EMHandleProcessRemoved( DProcess& aProcess ); |
|
108 void EMHandleThreadAdd( DThread& aThread ); |
|
109 void EMHandleThreadRemoved( DThread& aThread ); |
|
110 void EMHandleThreadKilled( DThread& aThread ); |
|
111 void EMHandleChunkAdd( DChunk& aChunk ); |
|
112 void EMHandleChunkUpdated( DChunk& aChunk ); |
|
113 void EMHandleChunkDeleted( DChunk& aChunk ); |
|
114 |
|
115 // Internal helper |
|
116 void EMHandleThreadChanged( DThread& aThread ); |
|
117 |
|
118 private: // Tracked item management |
|
119 void ResetTrackedList(); |
|
120 void SetTrackedListUnused(); |
|
121 void SetTrackedListUnusedStatusByType( TMemSpyTrackedChunk::TType aType, TBool aUnusedStatus ); |
|
122 void DiscardUnusedTrackListItems(); |
|
123 void AddTrackedChunk( DChunk* aChunk, TMemSpyTrackedChunk::TType aType ); |
|
124 TMemSpyTrackedChunk* TrackedChunkByHandle( TAny* aHandle ); |
|
125 |
|
126 private: // Internal methods |
|
127 DMemSpyInspectedProcessManager& PManager(); |
|
128 DMemSpyEventMonitor& EventMonitor(); |
|
129 TMemSpyTrackedChunk::TType ChunkType( DObject* aObject ) const; |
|
130 TBool IsHeapChunk( DChunk& aChunk, const TName& aName ) const; |
|
131 static TUint32 TotalStatistics( const TMemSpyDriverProcessInspectionInfo& aStats, TBool aIncludeShared = ETrue ); |
|
132 static TBool IsEqual( const TMemSpyDriverProcessInspectionInfo& aLeft, const TMemSpyDriverProcessInspectionInfo& aRight ); |
|
133 void ResetStatistics( TMemSpyDriverProcessInspectionInfo& aStats ); |
|
134 TBool UpdateStatistics(); |
|
135 void CompleteClientsRequest( TInt aCompletionCode, TMemSpyDriverProcessInspectionInfo* aInfo = NULL ); |
|
136 void FindChunks( DProcess& aProcess ); |
|
137 TInt StackSize( DProcess& aProcess ); |
|
138 void ResetPendingChanges(); |
|
139 void PrintChunkInfo( DChunk& aChunk ) const; |
|
140 TBool IsChunkRelevantToOurProcess( DChunk& aChunk ) const; |
|
141 |
|
142 public: // Queue link for process manager |
|
143 SDblQueLink iPMLink; |
|
144 |
|
145 private: // Data members |
|
146 DMemSpyDriverDevice& iDevice; |
|
147 DMutex* iLock; |
|
148 TUint iProcessId; |
|
149 DProcess* iProcess; |
|
150 TBool iAmDead; |
|
151 |
|
152 // This differs from the 'inspection info' iMemoryStack field |
|
153 // because it just contains the size of all user-thread stacks |
|
154 // within the process. |
|
155 TInt iUserThreadStackSize; |
|
156 |
|
157 // Tracking chunks mapped into process |
|
158 SDblQue iTrackedChunks; |
|
159 |
|
160 // Changes that have occurred whilst the client was AWOL |
|
161 SDblQue iPendingChanges; |
|
162 |
|
163 // Tracking totals |
|
164 TMemSpyDriverProcessInspectionInfo iInfoLast; |
|
165 TMemSpyDriverProcessInspectionInfo iInfoCurrent; |
|
166 TMemSpyDriverProcessInspectionInfo iInfoPeaks; |
|
167 TMemSpyDriverProcessInspectionInfo iInfoHWMIncShared; |
|
168 TMemSpyDriverProcessInspectionInfo iInfoHWMExcShared; |
|
169 |
|
170 // For change notification |
|
171 TInt iChangeDeliveryCounter; |
|
172 DThread* iChangeObserverThread; |
|
173 TRequestStatus* iChangeObserverRS; |
|
174 TMemSpyDriverProcessInspectionInfo* iChangeObserverInfo; |
|
175 TBool iEventReceivedWhilstObserverWasAWOL; |
|
176 }; |
|
177 |
|
178 |
|
179 #endif |