|
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 |
|
19 #ifndef PERFMON_ENGINE_H |
|
20 #define PERFMON_ENGINE_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <apgcli.h> |
|
26 #include <gdi.h> |
|
27 |
|
28 #include "perfmon.hrh" |
|
29 #include "perfmon_powerlistener.h" |
|
30 |
|
31 const TUint KMaxCPUs = 4; |
|
32 |
|
33 |
|
34 // setting keys (do not change uids of existing keys to maintain compatibility to older versions!) |
|
35 const TUid KPMSettingHeartBeat = { 0x00 }; |
|
36 const TUid KPMSettingMaxSamples = { 0x01 }; |
|
37 const TUid KPMSettingPriority = { 0x02 }; |
|
38 const TUid KPMSettingCPUMode = { 0x03 }; |
|
39 const TUid KPMSettingKeepBackLightOn = { 0x04 }; |
|
40 |
|
41 const TUid KPMSettingDataPopupVisbility = { 0x05 }; |
|
42 const TUid KPMSettingDataPopupLocation = { 0x06 }; |
|
43 const TUid KPMSettingDataPopupSources = { 0x07 }; |
|
44 |
|
45 const TUid KPMSettingGraphsVerticalBarPeriod = { 0x08 }; |
|
46 const TUid KPMSettingGraphsSources = { 0x09 }; |
|
47 |
|
48 const TUid KPMSettingLoggingMode = { 0x0A }; |
|
49 const TUid KPMSettingLoggingFilePath = { 0x0B }; |
|
50 const TUid KPMSettingLoggingSources = { 0x0C }; |
|
51 |
|
52 const TUid KPMSettingPowerMonitoringEnabled = { 0x0D }; |
|
53 |
|
54 // FORWARD DECLARATIONS |
|
55 class CPerfMonValuesContainer; |
|
56 class CPerfMonGraphsContainer; |
|
57 class CPerfMonDataPopupContainer; |
|
58 class CEikonEnv; |
|
59 class CCoeControl; |
|
60 class CDictionaryFileStore; |
|
61 |
|
62 |
|
63 // CLASS DECLARATIONS |
|
64 |
|
65 class TPerfMonNOPCounter |
|
66 { |
|
67 public: |
|
68 TInt64 iCounterValue; |
|
69 TInt iCPUNumber; |
|
70 TInt iAmountOfCPUs; |
|
71 }; |
|
72 |
|
73 class TPerfMonSources |
|
74 { |
|
75 public: |
|
76 TBool iSrcEnabled[ESourcesLength]; |
|
77 |
|
78 public: |
|
79 inline void SetDefaults1() |
|
80 { |
|
81 iSrcEnabled[ESourceCPU] = ETrue; |
|
82 iSrcEnabled[ESourceRAM] = ETrue; |
|
83 iSrcEnabled[ESourceC] = ETrue; |
|
84 iSrcEnabled[ESourceD] = EFalse; |
|
85 iSrcEnabled[ESourceE] = EFalse; |
|
86 iSrcEnabled[ESourceF] = EFalse; |
|
87 iSrcEnabled[ESourceG] = EFalse; |
|
88 iSrcEnabled[ESourceH] = EFalse; |
|
89 iSrcEnabled[ESourceI] = EFalse; |
|
90 iSrcEnabled[ESourcePwr] = EFalse; |
|
91 } |
|
92 inline void SetDefaults2() |
|
93 { |
|
94 iSrcEnabled[ESourceCPU] = ETrue; |
|
95 iSrcEnabled[ESourceRAM] = ETrue; |
|
96 iSrcEnabled[ESourceC] = EFalse; |
|
97 iSrcEnabled[ESourceD] = EFalse; |
|
98 iSrcEnabled[ESourceE] = EFalse; |
|
99 iSrcEnabled[ESourceF] = EFalse; |
|
100 iSrcEnabled[ESourceG] = EFalse; |
|
101 iSrcEnabled[ESourceH] = EFalse; |
|
102 iSrcEnabled[ESourceI] = EFalse; |
|
103 iSrcEnabled[ESourcePwr] = EFalse; |
|
104 } |
|
105 TInt EnabledSourcesCount() |
|
106 { |
|
107 TInt srcCount(0); |
|
108 |
|
109 for (TInt i=0; i<ESourcesLength; i++) |
|
110 { |
|
111 if (iSrcEnabled[i]) |
|
112 srcCount++; |
|
113 } |
|
114 |
|
115 return srcCount; |
|
116 } |
|
117 }; |
|
118 |
|
119 |
|
120 class TPerfMonSettings |
|
121 { |
|
122 public: |
|
123 TInt iHeartBeat; |
|
124 TInt iMaxSamples; |
|
125 TInt iPriority; |
|
126 TInt iCPUMode; |
|
127 TBool iKeepBacklightOn; |
|
128 |
|
129 TInt iDataPopupVisibility; |
|
130 TInt iDataPopupLocation; |
|
131 TPerfMonSources iDataPopupSources; |
|
132 |
|
133 TInt iGraphsVerticalBarPeriod; |
|
134 TPerfMonSources iGraphsSources; |
|
135 |
|
136 TInt iLoggingMode; |
|
137 TFileName iLoggingFilePath; |
|
138 TPerfMonSources iLoggingSources; |
|
139 |
|
140 TBool iLoggingEnabled; |
|
141 |
|
142 TBool iPowerMonitoringEnabled; |
|
143 }; |
|
144 |
|
145 |
|
146 class TSampleData |
|
147 { |
|
148 public: |
|
149 TInt64 iFree; |
|
150 TInt64 iSize; |
|
151 TTimeIntervalMicroSeconds iTimeFromStart; |
|
152 }; |
|
153 |
|
154 typedef CArrayFixSeg<TSampleData> CSampleDataArray; |
|
155 |
|
156 |
|
157 class TSampleEntry |
|
158 { |
|
159 public: |
|
160 TBuf<16> iDescription; |
|
161 TBuf<16> iUnitTypeShort; //eg. b |
|
162 TBuf<16> iUnitTypeLong; //eg. bytes |
|
163 TInt iDriveNumber; //used only for disk drives |
|
164 TRgb iGraphColor; |
|
165 CSampleDataArray* iSampleDataArray; |
|
166 }; |
|
167 |
|
168 typedef CArrayFixSeg<TSampleEntry> CSampleEntryArray; |
|
169 |
|
170 |
|
171 |
|
172 class CPerfMonEngine : public CActive |
|
173 { |
|
174 public: |
|
175 ~CPerfMonEngine(); |
|
176 void ActivateEngineL(); |
|
177 void DeActivateEngineL(); |
|
178 void EnableLogging(TBool aEnable); |
|
179 |
|
180 private: |
|
181 void RunL(); |
|
182 void DoCancel(); |
|
183 |
|
184 void LoadSettingsL(); |
|
185 void OpenLogFile(TBool aOpen); |
|
186 void CreateSamplesDataArrayL(); |
|
187 void UpdateSamplesDataL(); |
|
188 void AppendLatestSamplesToLogsL(); |
|
189 void ActivateCPUMonitoringL(); |
|
190 TBool OpenHandleToNullThread(); |
|
191 void DeActivateCPUMonitoring(); |
|
192 TBool CPUTimeSupported(); |
|
193 TInt GetAmountOfCPUs(); |
|
194 TThreadPriority SettingItemToThreadPriority(TInt aIndex); |
|
195 void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TInt& aValue); |
|
196 void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TDes& aValue); |
|
197 void LoadDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, TPerfMonSources& aValue); |
|
198 void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TInt& aValue); |
|
199 void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TDes& aValue); |
|
200 void SaveDFSValueL(CDictionaryFileStore* aDicFS, const TUid& aUid, const TPerfMonSources& aValue); |
|
201 void ActivatePowerMonitoringL(); |
|
202 void DeActivatePowerMonitoring(); |
|
203 |
|
204 TInt SampleEntryPosToSettingPos(TInt aSampleEntryPos); |
|
205 |
|
206 protected: |
|
207 CPerfMonEngine(); |
|
208 void ConstructL(); |
|
209 void SaveSettingsL(); |
|
210 virtual void SendDrawEventToContainersL() = 0; |
|
211 virtual void HandleSettingsChangeL(); |
|
212 |
|
213 public: |
|
214 inline TPerfMonSettings& Settings() { return iSettings; } |
|
215 inline CEikonEnv* EikonEnv() { return iEnv; } |
|
216 inline RApaLsSession& LsSession() { return iLs; } |
|
217 |
|
218 inline CSampleEntryArray* SampleEntryArray() { return iSampleEntryArray; } |
|
219 inline TInt CPU0PositionInSamples() { return iCPU0PositionInSamples; } |
|
220 inline TInt RAMPositionInSamples() { return iRAMPositionInSamples; } |
|
221 inline TInt CDrivePositionInSamples() { return iCDrivePositionInSamples; } |
|
222 inline TInt PowerPositionInSamples() { return iPowerPositionInSamples; } |
|
223 inline TInt AmountOfCPUs() { return iAmountOfCPUs; } |
|
224 inline TBool PowerMonitoringSupported() { return iPowerClient->IsSupported(); } |
|
225 |
|
226 protected: |
|
227 RTimer iTimer; |
|
228 CEikonEnv* iEnv; |
|
229 TPerfMonSettings iSettings; |
|
230 RApaLsSession iLs; |
|
231 CSampleEntryArray* iSampleEntryArray; |
|
232 TTime iStartTime; |
|
233 |
|
234 TInt iCurrentCPUMode; |
|
235 |
|
236 RThread iCPULoadNOPThread[KMaxCPUs]; |
|
237 TPerfMonNOPCounter iCPULoadNOPCounter[KMaxCPUs]; |
|
238 |
|
239 RThread iNullThreads[KMaxCPUs]; |
|
240 TBool iCPULoadCalibrating; |
|
241 TInt iCPULoadCalibrationCounter; |
|
242 TInt64 iCPULoadMaxValue; |
|
243 TInt64 iCPULoadPreviousValue[KMaxCPUs]; |
|
244 TInt iAmountOfCPUs; |
|
245 TTime iPreviousTime; |
|
246 |
|
247 TInt iCPU0PositionInSamples; |
|
248 TInt iRAMPositionInSamples; |
|
249 TInt iCDrivePositionInSamples; |
|
250 TInt iPowerPositionInSamples; |
|
251 |
|
252 TBool iLogFileInitialized; |
|
253 RFile iLogFile; |
|
254 |
|
255 CPerfMonPowerListener* iPowerClient; |
|
256 }; |
|
257 |
|
258 |
|
259 #endif |