48
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@internalTechnology
|
|
19 |
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <flogger.h>
|
|
24 |
#include <hal.h>
|
|
25 |
#include "suplmemlogger.h"
|
|
26 |
|
|
27 |
|
|
28 |
/** Time interval between the first and second updates. */
|
|
29 |
const TInt KTimerInitialDelay = 1000000;
|
|
30 |
|
|
31 |
/** Time interval between the second and third and all the other updates. */
|
|
32 |
const TInt KTimerInitialInterval = 2000000;
|
|
33 |
|
|
34 |
const TInt KSuplDevLogMaxBufSize = 256;
|
|
35 |
|
|
36 |
_LIT(KSuplDevLogFolder, "lbs");
|
|
37 |
_LIT(KHeader, "TIME\tUID\tSTACK SIZE\tHEAP TOTAL\tHEAP AVAIL\tCHUNK TOTAL\tCHUNK AVAIL\tCELLS TOTAL\tCELLS AVAIL\tH/S TOTAL\tRAM TOTAL\tRAM AVAIL");
|
|
38 |
_LIT(KLogFormat, "%d\t%x\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d");
|
|
39 |
|
|
40 |
EXPORT_C CSuplMemoryUsageLogger* CSuplMemoryUsageLogger::NewLC()
|
|
41 |
{
|
|
42 |
CSuplMemoryUsageLogger* self = new (ELeave) CSuplMemoryUsageLogger();
|
|
43 |
CleanupStack::PushL(self);
|
|
44 |
self->ConstructL();
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
CSuplMemoryUsageLogger::CSuplMemoryUsageLogger() :
|
|
49 |
iHeap(User::Heap())
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
CSuplMemoryUsageLogger::~CSuplMemoryUsageLogger()
|
|
54 |
{
|
|
55 |
// Cancel and delete periodic timer
|
|
56 |
iPeriodic->Cancel();
|
|
57 |
delete iPeriodic;
|
|
58 |
|
|
59 |
// Close iLogger handle
|
|
60 |
iLogger.Write(KNullDesC8);
|
|
61 |
iLogger.Close();
|
|
62 |
|
|
63 |
// Write the max params to a separate file
|
|
64 |
WriteMaxHeapToLog();
|
|
65 |
|
|
66 |
// Close RProcess handle
|
|
67 |
iProcess.Close();
|
|
68 |
}
|
|
69 |
|
|
70 |
void CSuplMemoryUsageLogger::ConstructL()
|
|
71 |
{
|
|
72 |
//create periodic timer object
|
|
73 |
iPeriodic = CPeriodic::NewL(CActive::EPriorityHigh);
|
|
74 |
|
|
75 |
//get process name
|
|
76 |
TFileName processFilename(iProcess.FileName());
|
|
77 |
|
|
78 |
//create log file name out of process name
|
|
79 |
TInt pos = processFilename.LocateReverse(TChar('\\'));
|
|
80 |
iFileName = processFilename.Mid(pos + 1);
|
|
81 |
iFileName = iFileName.Mid(0, iFileName.Length() - 3);
|
|
82 |
iFileName.Append(_L("txt"));
|
|
83 |
|
|
84 |
//connect to file iLogger
|
|
85 |
User::LeaveIfError(iLogger.Connect());
|
|
86 |
|
|
87 |
//get total stack size
|
|
88 |
RThread currentThread;
|
|
89 |
TThreadStackInfo stackInfo;
|
|
90 |
currentThread.StackInfo(stackInfo);
|
|
91 |
iStackSize = stackInfo.iBase - stackInfo.iLimit;
|
|
92 |
|
|
93 |
//create log file
|
|
94 |
iLogger.CreateLog(KSuplDevLogFolder, iFileName, EFileLoggingModeAppend);
|
|
95 |
|
|
96 |
//write header to log file
|
|
97 |
iLogger.SetDateAndTime(ETrue, ETrue);
|
|
98 |
iLogger.Write(KNullDesC8);
|
|
99 |
iLogger.SetDateAndTime(EFalse, EFalse);
|
|
100 |
iLogger.WriteFormat(KHeader);
|
|
101 |
|
|
102 |
//setup time stamp for calculating time passed
|
|
103 |
iStartTime.UniversalTime();
|
|
104 |
|
|
105 |
//first write to log file
|
|
106 |
WriteToLog();
|
|
107 |
|
|
108 |
//start periodic timer
|
|
109 |
iPeriodic->Start(KTimerInitialDelay, KTimerInitialInterval, TCallBack(PeriodicCallback, this));
|
|
110 |
}
|
|
111 |
|
|
112 |
EXPORT_C void CSuplMemoryUsageLogger::Cancel()
|
|
113 |
{
|
|
114 |
iPeriodic->Cancel();
|
|
115 |
}
|
|
116 |
|
|
117 |
TInt CSuplMemoryUsageLogger::PeriodicCallback(TAny* aSelf)
|
|
118 |
{
|
|
119 |
CSuplMemoryUsageLogger* self = static_cast<CSuplMemoryUsageLogger*>(aSelf);
|
|
120 |
self->WriteToLog();
|
|
121 |
return KErrNone;
|
|
122 |
}
|
|
123 |
|
|
124 |
void CSuplMemoryUsageLogger::WriteToLog()
|
|
125 |
{
|
|
126 |
//seconds passed since start of application
|
|
127 |
TTime currentTime;
|
|
128 |
TTimeIntervalSeconds seconds;
|
|
129 |
currentTime.UniversalTime();
|
|
130 |
currentTime.SecondsFrom(iStartTime, seconds);
|
|
131 |
|
|
132 |
if (seconds.Int() <= 60)
|
|
133 |
{
|
|
134 |
TInt heapTotal = 0;
|
|
135 |
TInt heapAvail = 0;
|
|
136 |
TInt chunkTotal = 0;
|
|
137 |
TInt chunkAvail = 0;
|
|
138 |
TInt cellsTotal = 0;
|
|
139 |
TInt cellsAvail = 0;
|
|
140 |
TInt heapStackTotal = 0;
|
|
141 |
TInt ramTotal = 0;
|
|
142 |
TInt ramAvail = 0;
|
|
143 |
|
|
144 |
//get system memory info from hardware abstraction layer
|
|
145 |
HAL::Get(HAL::EMemoryRAM, ramTotal);
|
|
146 |
HAL::Get(HAL::EMemoryRAMFree, ramAvail);
|
|
147 |
|
|
148 |
//get process UID
|
|
149 |
TSecureId processUid(iProcess.SecureId());
|
|
150 |
|
|
151 |
//get various heap and chunk memory sizes
|
|
152 |
iHeap.AllocSize(heapTotal);
|
|
153 |
if (heapTotal > iMaxHeapTotal)
|
|
154 |
{
|
|
155 |
iMaxHeapTotal = heapTotal;
|
|
156 |
}
|
|
157 |
iHeap.Available(heapAvail);
|
|
158 |
chunkTotal = iHeap.Size();
|
|
159 |
chunkAvail = chunkTotal - heapTotal;
|
|
160 |
if (chunkTotal > iMaxChunkTotal)
|
|
161 |
{
|
|
162 |
iMaxChunkTotal = chunkTotal;
|
|
163 |
}
|
|
164 |
|
|
165 |
//get cells info
|
|
166 |
cellsTotal = iHeap.Count(cellsAvail);
|
|
167 |
|
|
168 |
//sum up the total heap and stack sizes
|
|
169 |
heapStackTotal = heapTotal + iStackSize;
|
|
170 |
|
|
171 |
//create log text and write to log file
|
|
172 |
TBuf16<KSuplDevLogMaxBufSize> logData;
|
|
173 |
logData.Format(KLogFormat, seconds.Int(), processUid.iId, iStackSize, heapTotal, heapAvail, chunkTotal, chunkAvail, cellsTotal, cellsAvail, heapStackTotal, ramTotal, ramAvail);
|
|
174 |
iLogger.Write(logData);
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
void CSuplMemoryUsageLogger::WriteMaxHeapToLog()
|
|
179 |
{
|
|
180 |
_LIT(KLogMaxHeapFormat, "%d, %d");
|
|
181 |
|
|
182 |
//connect to file iLogger
|
|
183 |
TInt err = iLogger.Connect();
|
|
184 |
if (KErrNone == err)
|
|
185 |
{
|
|
186 |
//create new log file name out of existing
|
|
187 |
TInt pos = iFileName.LocateReverse(TChar('.'));
|
|
188 |
if (KErrNotFound != pos)
|
|
189 |
{
|
|
190 |
iFileName.Insert(pos, _L("_max_ram"));
|
|
191 |
|
|
192 |
//create log file
|
|
193 |
iLogger.CreateLog(KSuplDevLogFolder, iFileName, EFileLoggingModeOverwrite);
|
|
194 |
|
|
195 |
//write header to log file
|
|
196 |
// iLogger.SetDateAndTime(ETrue, ETrue);
|
|
197 |
// iLogger.Write(KNullDesC8);
|
|
198 |
iLogger.SetDateAndTime(EFalse, EFalse);
|
|
199 |
|
|
200 |
//create log text and write to log file
|
|
201 |
TBuf16<KSuplDevLogMaxBufSize> logData;
|
|
202 |
logData.Format(KLogMaxHeapFormat, iMaxHeapTotal, iMaxChunkTotal);
|
|
203 |
iLogger.Write(logData);
|
|
204 |
iLogger.Write(KNullDesC8);
|
|
205 |
}
|
|
206 |
iLogger.Close();
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|